Skip to content

Commit

Permalink
#86 | BUG | Addon | fix addon bug
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Müller <[email protected]>
  • Loading branch information
MuellerMH committed Dec 10, 2018
1 parent b8e4219 commit 766f0bf
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions internal/addon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func (a *Addon) Destroy(addonNameOrGitPath string) (error, string) {
_, addonName := a.Get(addonNameOrGitPath)
fmt.Println("Destroying", strings.Replace(addonName, "tk8-addon-", "", 1))
executeMainSh(addonName)
deleteMainYml(addonName, "yml")
deleteMainYml(addonName, "yaml")
deleteMainYml(addonName)
fmt.Println(strings.Replace(addonName, "tk8-addon-", "", 1), "destroy complete")

return nil, addonName
Expand All @@ -46,49 +45,56 @@ func (a *Addon) Get(addonNameOrGitPath string) (error, string) {
fmt.Println("check if provided a url")
if strings.Contains(addonNameOrGitPath, "http://") || strings.Contains(addonNameOrGitPath, "https://") {
fmt.Println("Load Addon from external path", addonNameOrGitPath)
common.CloneGit("./addons", addonNameOrGitPath, addonName)
return nil, addonName
err := common.CloneGit("./addons", addonNameOrGitPath, addonName)
return err, extractAddonName(addonName)
}

fmt.Println("Search addon on kubernauts space.")
common.CloneGit("./addons", "https://github.com/kubernauts/tk8-addon-"+addonName, addonName)
return nil, "tk8-addon-" + addonName
err := common.CloneGit("./addons", "https://github.com/kubernauts/tk8-addon-"+addonName, addonName)
return err, addonName

}
return nil, "tk8-addon-" + addonName
return nil, addonName

}

func (a *Addon) Install(addonNameOrGitPath string) {
_, addonName := a.Get(addonNameOrGitPath)
fmt.Println("Install", strings.Replace(addonName, "tk8-addon-", "", 1), addonName)

fmt.Println("Install", addonName)
executeMainSh(addonName)
applyMainYml(addonName, "yml")
applyMainYml(addonName, "yaml")
fmt.Println(addonName, "installation complete")
err := applyMainYml(addonName)
if err == nil {
fmt.Println(addonName, "installation complete")
} else {
fmt.Println(err)
}

}

// KubeConfig provide the path to the local kube config
var KubeConfig string

func applyMainYml(addonName string, fileType string) {
func applyMainYml(addonName string) error {

var cEx *exec.Cmd
_, err := os.Stat("./addons/" + addonName + "/main." + fileType)
fileName := "main.yml"
if _, err := os.Stat("./addons/" + addonName + "/" + fileName); err != nil {
fileName = "main.yaml"
}
_, err := os.Stat("./addons/" + addonName + "/" + fileName)
if err == nil {
fmt.Println("apply main." + fileType)
fmt.Println("apply " + addonName + "/" + fileName)
if len(KubeConfig) > 1 {
cEx = exec.Command("kubectl", "--kubeconfig", KubeConfig, "apply", "-f", "main."+fileType)
cEx = exec.Command("kubectl", "--kubeconfig", KubeConfig, "apply", "-f", fileName)
} else {
cEx = exec.Command("kubectl", "apply", "-f", "main."+fileType)
cEx = exec.Command("kubectl", "apply", "-f", fileName)
}
cEx.Dir = "./addons/" + addonName
printTerminalLog(cEx)
cEx.Wait()
return
return nil
}
return err
}

func executeMainSh(addonName string) {
Expand Down Expand Up @@ -137,15 +143,19 @@ func cloneExample(addonName string) {
common.CloneGit("./addons", "https://github.com/kubernauts/tk8-addon-develop", addonName)
}

func deleteMainYml(addonName string, fileType string) {
func deleteMainYml(addonName string) {

var cEx *exec.Cmd
if _, err := os.Stat("./addons/" + addonName + "/main." + fileType); err == nil {
fileName := addonName + ".yml"
if _, err := os.Stat("./addons/" + addonName + "/" + fileName); err != nil {
fileName = addonName + ".yaml"
}
if _, err := os.Stat("./addons/" + addonName + "/" + fileName); err == nil {
fmt.Println("delete", strings.Replace(addonName, "tk8-addon-", "", 1), "from cluster")
if len(KubeConfig) > 1 {
cEx = exec.Command("kubectl", "--kubeconfig="+KubeConfig, "delete", "-f", "main."+fileType)
cEx = exec.Command("kubectl", "--kubeconfig="+KubeConfig, "delete", "-f", fileName)
} else {
cEx = exec.Command("kubectl", "delete", "-f", "main."+fileType)
cEx = exec.Command("kubectl", "delete", "-f", fileName)
}
cEx.Dir = "./addons/" + addonName
printTerminalLog(cEx)
Expand Down

0 comments on commit 766f0bf

Please sign in to comment.