oc-deploy/src/tool/kubectl.go

44 lines
851 B
Go
Raw Normal View History

2024-09-02 13:44:44 +02:00
package tool
import (
"fmt"
"os"
"path/filepath"
log "oc-deploy/log_wrapper"
"oc-deploy/utils"
"oc-deploy/kubectl"
)
2024-09-10 19:01:54 +02:00
type KubectlInstall struct {
2024-09-03 13:46:45 +02:00
obj ToolData
2024-09-02 13:44:44 +02:00
}
2024-09-10 19:01:54 +02:00
func (this KubectlInstall) Get() (ToolData) {
2024-09-03 13:46:45 +02:00
return this.obj
2024-09-02 13:44:44 +02:00
}
2024-09-10 19:01:54 +02:00
func (this KubectlInstall) Download() (error) {
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
bin_dir := this.obj.Bin
bin := filepath.Join(bin_dir, this.obj.Name)
url := fmt.Sprintf(this.obj.Url, this.obj.Version)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
log.Log().Debug().Msg(fmt.Sprintf("Téléchargement : %s, %s", bin, url))
os.MkdirAll(bin_dir, os.ModePerm)
2024-09-02 13:44:44 +02:00
2024-09-03 13:46:45 +02:00
err := utils.DownloadFromUrl(bin, url, 0777)
if err != nil {return err}
2024-09-02 13:44:44 +02:00
os.Chmod(bin, 0755)
2024-09-03 13:46:45 +02:00
return nil
2024-09-02 13:44:44 +02:00
}
///////////////
2024-09-10 19:01:54 +02:00
func (this KubectlInstall) Version(path string) (string, error) {
2024-09-09 16:17:02 +02:00
cmd := kubectl.KubectlCommand{Bin: path}
cmd.New()
return cmd.GetVersion()
2024-09-02 13:44:44 +02:00
}