44 lines
851 B
Go
44 lines
851 B
Go
package tool
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
log "oc-deploy/log_wrapper"
|
|
"oc-deploy/utils"
|
|
"oc-deploy/kubectl"
|
|
)
|
|
|
|
type KubectlInstall struct {
|
|
obj ToolData
|
|
}
|
|
|
|
func (this KubectlInstall) Get() (ToolData) {
|
|
return this.obj
|
|
}
|
|
|
|
func (this KubectlInstall) Download() (error) {
|
|
|
|
bin_dir := this.obj.Bin
|
|
bin := filepath.Join(bin_dir, this.obj.Name)
|
|
url := fmt.Sprintf(this.obj.Url, this.obj.Version)
|
|
|
|
log.Log().Debug().Msg(fmt.Sprintf("Téléchargement : %s, %s", bin, url))
|
|
os.MkdirAll(bin_dir, os.ModePerm)
|
|
|
|
err := utils.DownloadFromUrl(bin, url, 0777)
|
|
if err != nil {return err}
|
|
|
|
os.Chmod(bin, 0755)
|
|
|
|
return nil
|
|
}
|
|
|
|
///////////////
|
|
func (this KubectlInstall) Version(path string) (string, error) {
|
|
cmd := kubectl.KubectlCommand{Bin: path}
|
|
cmd.New()
|
|
return cmd.GetVersion()
|
|
}
|