@@ -50,9 +50,8 @@ type ControlPlane struct {
5050 Machines collections.Machines
5151 machinesPatchHelpers map [string ]* patch.Helper
5252
53- machinesNotUptoDate collections.Machines
54- machinesNotUptoDateLogMessages map [string ][]string
55- machinesNotUptoDateConditionMessages map [string ][]string
53+ machinesNotUptoDate collections.Machines
54+ machinesNotUpToDateResults map [string ]NotUpToDateResult
5655
5756 // reconciliationTime is the time of the current reconciliation, and should be used for all "now" calculations
5857 reconciliationTime metav1.Time
@@ -98,7 +97,7 @@ type PreflightCheckResults struct {
9897
9998// NewControlPlane returns an instantiated ControlPlane.
10099func NewControlPlane (ctx context.Context , managementCluster ManagementCluster , client client.Client , cluster * clusterv1.Cluster , kcp * controlplanev1.KubeadmControlPlane , ownedMachines collections.Machines ) (* ControlPlane , error ) {
101- infraObjects , err := getInfraResources (ctx , client , ownedMachines )
100+ infraMachines , err := getInfraMachines (ctx , client , ownedMachines )
102101 if err != nil {
103102 return nil , err
104103 }
@@ -118,32 +117,29 @@ func NewControlPlane(ctx context.Context, managementCluster ManagementCluster, c
118117 // Select machines that should be rolled out because of an outdated configuration or because rolloutAfter/Before expired.
119118 reconciliationTime := metav1 .Now ()
120119 machinesNotUptoDate := make (collections.Machines , len (ownedMachines ))
121- machinesNotUptoDateLogMessages := map [string ][]string {}
122- machinesNotUptoDateConditionMessages := map [string ][]string {}
120+ machinesNotUpToDateResults := map [string ]NotUpToDateResult {}
123121 for _ , m := range ownedMachines {
124- upToDate , logMessages , conditionMessages , err := UpToDate (m , kcp , & reconciliationTime , infraObjects , kubeadmConfigs )
122+ upToDate , notUpToDateResult , err := UpToDate (m , kcp , & reconciliationTime , infraMachines , kubeadmConfigs )
125123 if err != nil {
126124 return nil , err
127125 }
128126 if ! upToDate {
129127 machinesNotUptoDate .Insert (m )
130- machinesNotUptoDateLogMessages [m .Name ] = logMessages
131- machinesNotUptoDateConditionMessages [m .Name ] = conditionMessages
128+ machinesNotUpToDateResults [m .Name ] = * notUpToDateResult
132129 }
133130 }
134131
135132 return & ControlPlane {
136- KCP : kcp ,
137- Cluster : cluster ,
138- Machines : ownedMachines ,
139- machinesPatchHelpers : patchHelpers ,
140- machinesNotUptoDate : machinesNotUptoDate ,
141- machinesNotUptoDateLogMessages : machinesNotUptoDateLogMessages ,
142- machinesNotUptoDateConditionMessages : machinesNotUptoDateConditionMessages ,
143- KubeadmConfigs : kubeadmConfigs ,
144- InfraResources : infraObjects ,
145- reconciliationTime : reconciliationTime ,
146- managementCluster : managementCluster ,
133+ KCP : kcp ,
134+ Cluster : cluster ,
135+ Machines : ownedMachines ,
136+ machinesPatchHelpers : patchHelpers ,
137+ machinesNotUptoDate : machinesNotUptoDate ,
138+ machinesNotUpToDateResults : machinesNotUpToDateResults ,
139+ KubeadmConfigs : kubeadmConfigs ,
140+ InfraResources : infraMachines ,
141+ reconciliationTime : reconciliationTime ,
142+ managementCluster : managementCluster ,
147143 }, nil
148144}
149145
@@ -256,15 +252,15 @@ func (c *ControlPlane) GetKubeadmConfig(machineName string) (*bootstrapv1.Kubead
256252}
257253
258254// MachinesNeedingRollout return a list of machines that need to be rolled out.
259- func (c * ControlPlane ) MachinesNeedingRollout () (collections.Machines , map [string ][] string ) {
255+ func (c * ControlPlane ) MachinesNeedingRollout () (collections.Machines , map [string ]NotUpToDateResult ) {
260256 // Note: Machines already deleted are dropped because they will be replaced by new machines after deletion completes.
261- return c .machinesNotUptoDate .Filter (collections .Not (collections .HasDeletionTimestamp )), c .machinesNotUptoDateLogMessages
257+ return c .machinesNotUptoDate .Filter (collections .Not (collections .HasDeletionTimestamp )), c .machinesNotUpToDateResults
262258}
263259
264260// NotUpToDateMachines return a list of machines that are not up to date with the control
265261// plane's configuration.
266- func (c * ControlPlane ) NotUpToDateMachines () (collections.Machines , map [string ][] string ) {
267- return c .machinesNotUptoDate , c .machinesNotUptoDateConditionMessages
262+ func (c * ControlPlane ) NotUpToDateMachines () (collections.Machines , map [string ]NotUpToDateResult ) {
263+ return c .machinesNotUptoDate , c .machinesNotUpToDateResults
268264}
269265
270266// UpToDateMachines returns the machines that are up to date with the control
@@ -273,18 +269,18 @@ func (c *ControlPlane) UpToDateMachines() collections.Machines {
273269 return c .Machines .Difference (c .machinesNotUptoDate )
274270}
275271
276- // getInfraResources fetches the external infrastructure resource for each machine in the collection and returns a map of machine.Name -> infraResource .
277- func getInfraResources (ctx context.Context , cl client.Client , machines collections.Machines ) (map [string ]* unstructured.Unstructured , error ) {
272+ // getInfraMachines fetches the InfraMachine for each machine in the collection and returns a map of machine.Name -> InfraMachine .
273+ func getInfraMachines (ctx context.Context , cl client.Client , machines collections.Machines ) (map [string ]* unstructured.Unstructured , error ) {
278274 result := map [string ]* unstructured.Unstructured {}
279275 for _ , m := range machines {
280- infraObj , err := external .GetObjectFromContractVersionedRef (ctx , cl , m .Spec .InfrastructureRef , m .Namespace )
276+ infraMachine , err := external .GetObjectFromContractVersionedRef (ctx , cl , m .Spec .InfrastructureRef , m .Namespace )
281277 if err != nil {
282278 if apierrors .IsNotFound (errors .Cause (err )) {
283279 continue
284280 }
285- return nil , errors .Wrapf (err , "failed to retrieve infra obj for machine %q " , m .Name )
281+ return nil , errors .Wrapf (err , "failed to retrieve InfraMachine for Machine %s " , m .Name )
286282 }
287- result [m .Name ] = infraObj
283+ result [m .Name ] = infraMachine
288284 }
289285 return result , nil
290286}
@@ -297,14 +293,14 @@ func getKubeadmConfigs(ctx context.Context, cl client.Client, machines collectio
297293 if ! bootstrapRef .IsDefined () {
298294 continue
299295 }
300- machineConfig := & bootstrapv1.KubeadmConfig {}
301- if err := cl .Get (ctx , client.ObjectKey {Name : bootstrapRef .Name , Namespace : m .Namespace }, machineConfig ); err != nil {
296+ kubeadmConfig := & bootstrapv1.KubeadmConfig {}
297+ if err := cl .Get (ctx , client.ObjectKey {Name : bootstrapRef .Name , Namespace : m .Namespace }, kubeadmConfig ); err != nil {
302298 if apierrors .IsNotFound (errors .Cause (err )) {
303299 continue
304300 }
305- return nil , errors .Wrapf (err , "failed to retrieve bootstrap config for machine %q " , m .Name )
301+ return nil , errors .Wrapf (err , "failed to retrieve KubeadmConfig for Machine %s " , m .Name )
306302 }
307- result [m .Name ] = machineConfig
303+ result [m .Name ] = kubeadmConfig
308304 }
309305 return result , nil
310306}
0 commit comments