+ if clusterType != "virtlet-vm" {
+ fmt.Printf("BareMetalHost CR %s has NIC with MAC Address %s\n", bmhCR, masterMAC)
+
+ //Get IP address of master
+ hostIPaddress, err = getHostIPaddress(masterMAC, dhcpLeaseFile )
+ if err != nil || hostIPaddress == ""{
+ err = fmt.Errorf("IP address not found for host with MAC address %s \n", masterMAC)
+ return reconcile.Result{}, err
+ }
+ }
+
+ allString += masterLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + "\n"
+ masterString += masterLabel + "\n"
+ clusterData[masterTag + masterLabel] = hostIPaddress
+
+ fmt.Printf("%s : %s \n", hostIPaddress, masterMAC)
+
+ if len(workersList) != 0 {
+
+ //Iterate through workersList and get all the mac addresses
+ for _, workerMap := range workersList {
+
+ //Get worker labels from the workermap
+ for workerLabel, worker := range workerMap {
+
+ //Check if workerString already contains worker label
+ containsWorkerLabel := strings.Contains(workerString, workerLabel)
+ workerMAC := worker.MACaddress
+ hostIPaddress = ""
+
+ //Error occurs if the same label is given to different hosts (assumption,
+ //each MAC address represents a unique host
+ if workerLabel == masterLabel && workerMAC != masterMAC && workerMAC != "" {
+ if containsWorkerLabel {
+ strings.ReplaceAll(workerString, workerLabel, "")
+ }
+ err = fmt.Errorf(`A node with label %s already exists, modify resource and assign a
+ different label to node with MACAddress %s`, workerLabel, workerMAC)
+ return reconcile.Result{}, err
+
+ //same node performs worker and master roles
+ } else if workerLabel == masterLabel && !containsWorkerLabel {
+ workerString += workerLabel + "\n"
+
+ //Add host to ip address config map with worker tag
+ hostIPaddress = clusterData[masterTag + masterLabel]
+ clusterData[workerTag + masterLabel] = hostIPaddress
+
+ //Error occurs if the same node is given different labels
+ } else if workerLabel != masterLabel && workerMAC == masterMAC {
+ if containsWorkerLabel {
+ strings.ReplaceAll(workerString, workerLabel, "")
+ }
+ err = fmt.Errorf(`A node with label %s already exists, modify resource and assign a
+ different label to node with MACAddress %s`, workerLabel, workerMAC)
+ 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
+ }
+ }
+ fmt.Printf("%s : %s \n", hostIPaddress, workerMAC)
+
+
+ allString += workerLabel + " ansible_ssh_host=" + hostIPaddress + " ansible_ssh_port=22" + "\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