WIP: Added entry point for deletion. Not workign yet.
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								bin/manager
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								bin/manager
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -1,2 +1,2 @@ | |||||||
| SCHEDULED=$1 | SCHEDULED=$1 | ||||||
| kubectl get baremetalhosts --all-namespaces -l sip.airshipit.org/sip-scheduled=$SCHEDULED --show-labels|awk '{print $1,$2,$5,$6}' | kubectl get baremetalhosts --all-namespaces -l sip.airshipit.org/sip-scheduled=$SCHEDULED --show-labels|grep -v NAME|awk '{print "____________\n",$2,"\n\t",$5,$6}'|sed -e's/,/\n\t/g' | ||||||
|   | |||||||
| @@ -56,23 +56,35 @@ func (r *SIPClusterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) | |||||||
| 		// on deleted requests. | 		// on deleted requests. | ||||||
| 		return ctrl.Result{}, nil | 		return ctrl.Result{}, nil | ||||||
| 	} | 	} | ||||||
| 	// machines |  | ||||||
| 	err, machines := r.gatherVBMH(sip) |  | ||||||
| 	if err != nil { |  | ||||||
| 		log.Error(err, "unable to gather vBMHs") |  | ||||||
| 		return ctrl.Result{}, err |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	err = r.deployInfra(sip, machines) | 	// Check for Deletion | ||||||
| 	if err != nil { | 	if sip.ObjectMeta.DeletionTimestamp.IsZero() { | ||||||
| 		log.Error(err, "unable to deploy infrastructure services") | 		// machines | ||||||
| 		return ctrl.Result{}, err | 		err, machines := r.gatherVBMH(sip) | ||||||
| 	} | 		if err != nil { | ||||||
|  | 			//log.Error(err, "unable to gather vBMHs") | ||||||
|  | 			return ctrl.Result{}, err | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		err = r.deployInfra(sip, machines) | ||||||
|  | 		if err != nil { | ||||||
|  | 			log.Error(err, "unable to deploy infrastructure services") | ||||||
|  | 			return ctrl.Result{}, err | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		err = r.finish(sip, machines) | ||||||
|  | 		if err != nil { | ||||||
|  | 			log.Error(err, "unable to finish creation/update ..") | ||||||
|  | 			return ctrl.Result{}, err | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  | 		// Deleting the SIP , what do we do now | ||||||
|  | 		err := r.finalize(sip) | ||||||
|  | 		if err != nil { | ||||||
|  | 			log.Error(err, "unable to finalize") | ||||||
|  | 			return ctrl.Result{}, err | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 	err = r.finish(sip, machines) |  | ||||||
| 	if err != nil { |  | ||||||
| 		log.Error(err, "unable to finalize ..") |  | ||||||
| 		return ctrl.Result{}, err |  | ||||||
| 	} | 	} | ||||||
| 	return ctrl.Result{}, nil | 	return ctrl.Result{}, nil | ||||||
| } | } | ||||||
| @@ -169,3 +181,28 @@ func (r *SIPClusterReconciler) finish(sip airshipv1.SIPCluster, machines *airshi | |||||||
| 	return nil | 	return nil | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  | ||||||
|  | Deal with Deletion andd Finalizers if any is needed | ||||||
|  | Such as i'e what are we doing with the lables on teh vBMH's | ||||||
|  | **/ | ||||||
|  | func (r *SIPClusterReconciler) finalize(sip airshipv1.SIPCluster) error { | ||||||
|  | 	// 1- Let me retrieve all vBMH mapped for this SIP Cluster | ||||||
|  | 	// 2- Let me now select the one's that meet teh scheduling criteria | ||||||
|  | 	// If I schedule successfully then | ||||||
|  | 	// If Not complete schedule , then throw an error. | ||||||
|  | 	machines := &airshipvms.MachineList{} | ||||||
|  | 	fmt.Printf("finalize sip:%v machines:%s\n", sip, machines.String()) | ||||||
|  | 	// Update the list of  Machines. | ||||||
|  | 	err := machines.GetCluster(sip, r.Client) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	// Placeholder unsuree whether this is what we want | ||||||
|  | 	err = machines.RemoveLabels(sip, r.Client) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|   | |||||||
| @@ -297,7 +297,7 @@ func (ml *MachineList) scheduleIt(nodeRole airshipv1.VmRoles, nodeCfg airshipv1. | |||||||
| 		if validBmh && !ml.hasMachine(bmh) { | 		if validBmh && !ml.hasMachine(bmh) { | ||||||
| 			// Lets add it to the list as a schedulable thing | 			// Lets add it to the list as a schedulable thing | ||||||
| 			ml.bmhs[bmh.ObjectMeta.Name] = NewMachine(bmh, nodeRole) | 			ml.bmhs[bmh.ObjectMeta.Name] = NewMachine(bmh, nodeRole) | ||||||
| 			fmt.Printf("---------------\nSchedule.scheduleIt ADDED machine:%s ml.bmhs %s \n", ml.bmhs[bmh.ObjectMeta.Name].String()) | 			fmt.Printf("---------------\nSchedule.scheduleIt ADDED machine:%s \n", ml.bmhs[bmh.ObjectMeta.Name].String()) | ||||||
| 			// TODO Probable should remove the bmh from the list so if there are other node targets they dont even take it into account | 			// TODO Probable should remove the bmh from the list so if there are other node targets they dont even take it into account | ||||||
| 			nodeTarget = nodeTarget - 1 | 			nodeTarget = nodeTarget - 1 | ||||||
| 			if nodeTarget == 0 { | 			if nodeTarget == 0 { | ||||||
| @@ -603,3 +603,60 @@ func (ml *MachineList) ApplyLabels(sip airshipv1.SIPCluster, c client.Client) er | |||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  | RemoveLabels | ||||||
|  | */ | ||||||
|  | func (ml *MachineList) RemoveLabels(sip airshipv1.SIPCluster, c client.Client) error { | ||||||
|  |  | ||||||
|  | 	fmt.Printf("ApplyLabels  %s size:%d\n", ml.String(), len(ml.bmhs)) | ||||||
|  | 	for _, machine := range ml.bmhs { | ||||||
|  |  | ||||||
|  | 		bmh := &machine.Bmh | ||||||
|  | 		fmt.Printf("ApplyLabels bmh.ObjectMeta.Name:%s\n", bmh.ObjectMeta.Name) | ||||||
|  | 		bmh.Labels[SipClusterLabel] = "-" // REMOVE IT | ||||||
|  | 		bmh.Labels[SipScheduleLabel] = "false" | ||||||
|  | 		bmh.Labels[SipNodeTypeLabel] = "-" // REMOVE IT | ||||||
|  |  | ||||||
|  | 		// This is bombing when it find 1 error | ||||||
|  | 		// Might be better to acculumalte the errors, and | ||||||
|  | 		// Allow it  to continue. | ||||||
|  | 		err := c.Update(context.Background(), bmh) | ||||||
|  | 		if err != nil { | ||||||
|  | 			fmt.Printf("ApplyLabel bmh:%s err:%v\n", bmh.ObjectMeta.Name, err) | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (ml *MachineList) addLabels(bmh metal3.BareMetalHost, m *Machine) { | ||||||
|  |  | ||||||
|  | } | ||||||
|  | func (ml *MachineList) GetCluster(sip airshipv1.SIPCluster, c client.Client) error { | ||||||
|  |  | ||||||
|  | 	bmhList := &metal3.BareMetalHostList{} | ||||||
|  | 	scheduleLabels := map[string]string{ | ||||||
|  | 		SipScheduleLabel: "true", | ||||||
|  | 		SipClusterLabel:  sip.Spec.Config.ClusterName, | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	err := c.List(context.Background(), bmhList, client.MatchingLabels(scheduleLabels)) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	for _, bmh := range bmhList.Items { | ||||||
|  | 		ml.bmhs[bmh.ObjectMeta.Name] = &Machine{ | ||||||
|  | 			Bmh:            bmh, | ||||||
|  | 			ScheduleStatus: Scheduled, | ||||||
|  | 			VmRole:         airshipv1.VmRoles(bmh.Labels[SipNodeTypeLabel]), | ||||||
|  | 			Data: &MachineData{ | ||||||
|  | 				IpOnInterface: make(map[string]string), | ||||||
|  | 			}, | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	fmt.Printf("GetCluster %s \n", ml.String()) | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Rodolfo Pacheco
					Rodolfo Pacheco