From 15b011800902faf9966a7d7c4dd35a77aa66050e Mon Sep 17 00:00:00 2001 From: Itohan Date: Fri, 16 Aug 2019 17:53:58 -0700 Subject: [PATCH] Fixed Bug in controller Modified controller to properly create hosts.ini file for KUD Issue-ID: ICN-8 Signed-off-by: Itohan Ukponmwan Change-Id: I86541e475aecf9641d20a862c385df0012637b06 --- .../provisioning/provisioning_controller.go | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/cmd/bpa-operator/pkg/controller/provisioning/provisioning_controller.go b/cmd/bpa-operator/pkg/controller/provisioning/provisioning_controller.go index e7e7c34..8031cd3 100644 --- a/cmd/bpa-operator/pkg/controller/provisioning/provisioning_controller.go +++ b/cmd/bpa-operator/pkg/controller/provisioning/provisioning_controller.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "path/filepath" "os/user" + "os/exec" bpav1alpha1 "github.com/bpa-operator/pkg/apis/bpa/v1alpha1" @@ -31,7 +32,9 @@ import ( ) var log = logf.Log.WithName("controller_provisioning") +//Todo: Should be an input from the user var dhcpLeaseFile = "/var/lib/dhcp/dhcpd.leases" +var kudInstallerScript = "/root/icn/deploy/kud/multicloud-k8s/kud/hosting_providers/vagrant" /** * USER ACTION REQUIRED: This is a scaffold file intended for the user to modify with their own Controller @@ -130,7 +133,7 @@ func (r *ReconcileProvisioning) Reconcile(request reconcile.Request) (reconcile. - allString += masterLabel + " ansible_host=" + hostIPaddress + " ip=" + hostIPaddress + "\n" + allString += masterLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + "\n" masterString += masterLabel + "\n" fmt.Printf("%s : %s \n", hostIPaddress, master.MACaddress) @@ -161,7 +164,7 @@ func (r *ReconcileProvisioning) Reconcile(request reconcile.Request) (reconcile. } fmt.Printf("%s : %s \n", hostIPaddress, worker.MACaddress) - allString += workerLabel + " ansible_host=" + hostIPaddress + " ip=" + hostIPaddress + "\n" + allString += workerLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + "\n" workerString += workerLabel + "\n" }else { @@ -214,6 +217,12 @@ func (r *ReconcileProvisioning) Reconcile(request reconcile.Request) (reconcile. hostFile.SaveTo(iniHostFilePath) + + //TODO: Test KUD installer part + //Copy host.ini file to the right path and install KUD + dstIniPath := kudInstallerScript + "/inventory/hosts.ini" + kudInstaller(iniHostFilePath, dstIniPath, kudInstallerScript) + return reconcile.Result{}, nil } @@ -321,3 +330,24 @@ func getHostIPaddress(macAddress string, dhcpLeaseFilePath string ) (string, err } return "", nil } + +func kudInstaller(srcIniPath, dstIniPath, kudInstallerPath string) { + + err := os.Chdir(kudInstallerPath) + if err != nil { + fmt.Printf("Could not change directory %v", err) + return + } + + commands := "cp " + srcIniPath + " " + dstIniPath + "; ./installer.sh| tee kud_installer.log" + + cmd := exec.Command("/bin/bash", "-c", commands) + err = cmd.Run() + + if err != nil { + fmt.Printf("Error Occured while running KUD install scripts %v", err) + return + } + + return +} -- 2.16.6