- return reconcile.Result{}, err
-
- //worker node is different from any master node and it has not been added to the worker list
- } else if workerLabel != masterLabel && !containsWorkerLabel {
-
- // Error occurs if MAC address not provided for worker node not matching master
- if workerMAC == "" {
- err = fmt.Errorf("MAC address for worker %s not provided", workerLabel)
- return reconcile.Result{}, err
- }
-
- // Check if worker MAC address has already been used
- usedMAC, err = r.macAddressUsed(provisioningInstance.Namespace, workerMAC, clusterName)
-
- if err != nil {
-
- fmt.Printf("Error occured while checking if mac Address has already been used\n %v", err)
- return reconcile.Result{}, err
- }
-
- if usedMAC {
-
- err = fmt.Errorf("MAC address %s has already been used, check and update provisioning CR", workerMAC)
- return reconcile.Result{}, err
-
- }
-
- containsMac, bmhCR := checkMACaddress(bareMetalHostList, workerMAC)
-
- if clusterType == "virtlet-vm" {
- //Get VM IP address of master
- hostIPaddress, err = getVMIPaddress(virtletVMList, workerMAC)
- if err != nil || hostIPaddress == "" {
- err = fmt.Errorf("IP address not found for VM with MAC address %s \n", workerMAC)
- return reconcile.Result{}, err
- }
- containsMac = true
- }
-
- if containsMac{
-
- if clusterType != "virtlet-vm" {
- fmt.Printf("Host %s matches that macAddress\n", bmhCR)
-
- //Get IP address of worker
- hostIPaddress, err = getHostIPaddress(workerMAC, dhcpLeaseFile )
- if err != nil {
- fmt.Errorf("IP address not found for host with MAC address %s \n", workerMAC)
- return reconcile.Result{}, err
- }
- }
- fmt.Printf("%s : %s \n", hostIPaddress, workerMAC)
-
- allString += workerLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + "\n"
- if clusterType == "virtlet-vm" {
- allString = masterLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + " ansible_ssh_user=root" + " ansible_ssh_pass=root" + "\n"
- }
- workerString += workerLabel + "\n"
- clusterData[workerTag + workerLabel] = hostIPaddress
- clusterMACData[strings.ReplaceAll(workerMAC, ":", "-")] = workerTag + workerLabel
-
- //No host found that matches the worker MAC
- } else {
-
- err = fmt.Errorf("Host with MAC Address %s not found\n", workerMAC)
- return reconcile.Result{}, err
- }
- }
- }
- }
- //No worker node specified, add master as worker node
- } else if len(workersList) == 0 && !strings.Contains(workerString, masterLabel) {
- workerString += masterLabel + "\n"
-
- //Add host to ip address config map with worker tag
- hostIPaddress = clusterData[masterTag + masterLabel]
- clusterData[workerTag + masterLabel] = hostIPaddress
- }
-
- //No host matching master MAC found
- } else {
- err = fmt.Errorf("Host with MAC Address %s not found\n", masterMAC)
- return reconcile.Result{}, err
- }
- }
- }
-
- //Create host.ini file
- iniHostFilePath := clusterDir + "/hosts.ini"
- newFile, err := os.Create(iniHostFilePath)
- defer newFile.Close()
-
-
- if err != nil {
- fmt.Printf("Error occured while creating file \n %v", err)
- return reconcile.Result{}, err
- }
-
- hostFile, err := ini.Load(iniHostFilePath)
- if err != nil {
- fmt.Printf("Error occured while Loading file \n %v", err)
- return reconcile.Result{}, err
- }
-
- _, err = hostFile.NewRawSection("all", allString)
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
- _, err = hostFile.NewRawSection("kube-master", masterString)
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
-
- _, err = hostFile.NewRawSection("kube-node", workerString)
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
-
- _, err = hostFile.NewRawSection("etcd", masterString)
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
-
- _, err = hostFile.NewRawSection("ovn-central", masterString)
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
-
- _, err = hostFile.NewRawSection("ovn-controller", workerString)
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
-
- _, err = hostFile.NewRawSection("virtlet", workerString)
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
-
- _, err = hostFile.NewRawSection("k8s-cluster:children", "kube-node\n" + "kube-master")
- if err != nil {
- fmt.Printf("Error occured while creating section \n %v", err)
- return reconcile.Result{}, err
- }
-
-
- //Create host.ini file for KUD
- hostFile.SaveTo(iniHostFilePath)
-
- // Create configmap to store MAC address info for the cluster
- cmName := provisioningInstance.Labels["cluster"] + "-mac-addresses"
- foundConfig := &corev1.ConfigMap{}
- err = r.client.Get(context.TODO(), types.NamespacedName{Name: cmName, Namespace: provisioningInstance.Namespace}, foundConfig)
-
- // Configmap was found but the provisioning CR was updated so update configMap
- if err == nil && foundConfig.Labels["provisioning-version"] != provisioningVersion {
-
- foundConfig.Data = clusterMACData
- foundConfig.Labels = provisioningInstance.Labels
- foundConfig.Labels["configmap-type"] = "mac-address"
- foundConfig.Labels["provisioning-version"] = provisioningVersion
- err = r.client.Update(context.TODO(), foundConfig)
- if err != nil {
- fmt.Printf("Error occured while updating mac address configmap for provisioningCR %s\n ERROR: %v\n", provisioningInstance.Name,
- err)
- return reconcile.Result{}, err
- }
-
- } else if err != nil && errors.IsNotFound(err) {
- labels := provisioningInstance.Labels
- labels["configmap-type"] = "mac-address"
- labels["provisioning-version"] = provisioningVersion
- err = r.createConfigMap(provisioningInstance, clusterMACData, labels, cmName)
- if err != nil {
- fmt.Printf("Error occured while creating MAC address configmap for cluster %v\n ERROR: %v", clusterName, err)
- return reconcile.Result{}, err
- }
-
- } else if err != nil {
- fmt.Printf("ERROR occured in Create MAC address Config map section: %v\n", err)
- return reconcile.Result{}, err
- }
-
- //Install KUD
- err = r.createKUDinstallerJob(provisioningInstance)
- if err != nil {
- fmt.Printf("Error occured while creating KUD Installer job for cluster %v\n ERROR: %v", clusterName, err)
- return reconcile.Result{}, err
- }
-
- //Start separate thread to keep checking job status, Create an IP address configmap
- //for cluster if KUD is successfully installed
- go r.checkJob(provisioningInstance, clusterData)
-
- return reconcile.Result{}, nil
-
- }
-
-
-
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //////////////// Software CR was created so install software /////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////
- softwareClusterName, masterSoftwareList, workerSoftwareList := getSoftwareList(softwareInstance)
- defaultSSHPrivateKey := "/root/.ssh/id_rsa"
-
- //Get IP address configmap for the cluster
- configmapName := softwareInstance.Labels["cluster"] + "-configmap"
- clusterConfigMapData, err := r.getConfigMapData(softwareInstance.Namespace, configmapName)
- if err != nil {
- fmt.Printf("Error occured while retrieving IP address Data for cluster %s, ERROR: %v\n", softwareClusterName, err)
- return reconcile.Result{}, err
- }
-
- for hostLabel, ipAddress := range clusterConfigMapData {
-
- if strings.Contains(hostLabel, masterTag) {
- // Its a master node, install master software
- err = softwareInstaller(ipAddress, defaultSSHPrivateKey, masterSoftwareList)
- if err != nil {
- fmt.Printf("Error occured while installing master software in host %s, ERROR: %v\n", hostLabel, err)
- }
- } else if strings.Contains(hostLabel, workerTag) {
- // Its a worker node, install worker software
- err = softwareInstaller(ipAddress, defaultSSHPrivateKey, workerSoftwareList)
- if err != nil {
- fmt.Printf("Error occured while installing worker software in host %s, ERROR: %v\n", hostLabel, err)
- }
-
- }
-
- }
-
- return reconcile.Result{}, nil
+ return reconcile.Result{}, err
+
+ //worker node is different from any master node and it has not been added to the worker list
+ } else if workerLabel != masterLabel && !containsWorkerLabel {
+
+ // Error occurs if MAC address not provided for worker node not matching master
+ if workerMAC == "" {
+ err = fmt.Errorf("MAC address for worker %s not provided", workerLabel)
+ return reconcile.Result{}, err
+ }
+
+ containsMac, bmhCR := checkMACaddress(bareMetalHostList, workerMAC)
+
+ if clusterType == "virtlet-vm" {
+ //Get VM IP address of master
+ hostIPaddress, err = getVMIPaddress(virtletVMList, workerMAC)
+ if err != nil || hostIPaddress == "" {
+ err = fmt.Errorf("IP address not found for VM with MAC address %s \n", workerMAC)
+ return reconcile.Result{}, err
+ }
+ containsMac = true
+ }
+
+ if containsMac {
+
+ if clusterType != "virtlet-vm" {
+ fmt.Printf("Host %s matches that macAddress\n", bmhCR)
+
+ //Get IP address of worker
+ hostIPaddress, err = getHostIPaddress(workerMAC, dhcpLeaseFile)
+ if err != nil {
+ fmt.Errorf("IP address not found for host with MAC address %s \n", workerMAC)
+ return reconcile.Result{}, err
+ }
+ allString += workerLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + "\n"
+ }
+ fmt.Printf("%s : %s \n", hostIPaddress, workerMAC)
+
+ if clusterType == "virtlet-vm" {
+ allString += masterLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + " ansible_ssh_user=root" + " ansible_ssh_pass=root" + "\n"
+ }
+ workerString += workerLabel + "\n"
+ clusterData[workerTag+workerLabel] = hostIPaddress
+
+ //No host found that matches the worker MAC
+ } else {
+
+ err = fmt.Errorf("Host with MAC Address %s not found\n", workerMAC)
+ return reconcile.Result{}, err
+ }
+ }
+ }
+ }
+ //No worker node specified, add master as worker node
+ } else if len(workersList) == 0 && !strings.Contains(workerString, masterLabel) {
+ workerString += masterLabel + "\n"
+
+ //Add host to ip address config map with worker tag
+ hostIPaddress = clusterData[masterTag+masterLabel]
+ clusterData[workerTag+masterLabel] = hostIPaddress
+ }
+
+ //No host matching master MAC found
+ } else {
+ err = fmt.Errorf("Host with MAC Address %s not found\n", masterMAC)
+ return reconcile.Result{}, err
+ }
+ }
+ }
+
+ //Create host.ini file
+ //iniHostFilePath := kudInstallerScript + "/inventory/hosts.ini"
+ iniHostFilePath := clusterDir + "/hosts.ini"
+ newFile, err := os.Create(iniHostFilePath)
+ defer newFile.Close()
+
+ if err != nil {
+ fmt.Printf("Error occured while creating file \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ hostFile, err := ini.Load(iniHostFilePath)
+ if err != nil {
+ fmt.Printf("Error occured while Loading file \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ _, err = hostFile.NewRawSection("all", allString)
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+ _, err = hostFile.NewRawSection("kube-master", masterString)
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ _, err = hostFile.NewRawSection("kube-node", workerString)
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ _, err = hostFile.NewRawSection("etcd", masterString)
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ if clusterType != "virtlet-vm" {
+ _, err = hostFile.NewRawSection("ovn-central", masterString)
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ _, err = hostFile.NewRawSection("ovn-controller", workerString)
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ _, err = hostFile.NewRawSection("virtlet", workerString)
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+ }
+ _, err = hostFile.NewRawSection("k8s-cluster:children", "kube-node\n"+"kube-master")
+ if err != nil {
+ fmt.Printf("Error occured while creating section \n %v", err)
+ return reconcile.Result{}, err
+ }
+
+ //Create host.ini file for KUD
+ hostFile.SaveTo(iniHostFilePath)
+
+ //Install KUD
+ err = createKUDinstallerJob(clusterName, request.Namespace, clusterLabel, podSubnet, kudPlugins, r.clientset)
+ if err != nil {
+ fmt.Printf("Error occured while creating KUD Installer job for cluster %v\n ERROR: %v", clusterName, err)
+ return reconcile.Result{}, err
+ }
+
+ //Start separate thread to keep checking job status, Create an IP address configmap
+ //for cluster if KUD is successfully installed
+ go checkJob(clusterName, request.Namespace, clusterData, clusterLabel, r.clientset)
+
+ return reconcile.Result{}, nil
+
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ //////////////// Software CR was created so install software /////////////////
+ //////////////////////////////////////////////////////////////////////////////////////////////
+ softwareClusterName, masterSoftwareList, workerSoftwareList := getSoftwareList(softwareInstance)
+ defaultSSHPrivateKey := "/root/.ssh/id_rsa"
+
+ //Get IP address configmap for the cluster
+ clusterConfigMapData, err := getConfigMapData(request.Namespace, softwareClusterName, r.clientset)
+ if err != nil {
+ fmt.Printf("Error occured while retrieving IP address Data for cluster %s, ERROR: %v\n", softwareClusterName, err)
+ return reconcile.Result{}, err
+ }
+
+ for hostLabel, ipAddress := range clusterConfigMapData {
+
+ if strings.Contains(hostLabel, masterTag) {
+ // Its a master node, install master software
+ err = softwareInstaller(ipAddress, defaultSSHPrivateKey, masterSoftwareList)
+ if err != nil {
+ fmt.Printf("Error occured while installing master software in host %s, ERROR: %v\n", hostLabel, err)
+ }
+ } else if strings.Contains(hostLabel, workerTag) {
+ // Its a worker node, install worker software
+ err = softwareInstaller(ipAddress, defaultSSHPrivateKey, workerSoftwareList)
+ if err != nil {
+ fmt.Printf("Error occured while installing worker software in host %s, ERROR: %v\n", hostLabel, err)
+ }
+
+ }
+
+ }
+
+ return reconcile.Result{}, nil