@@ -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+ machinesUpToDateResults map [string ]UpToDateResult
5655
5756 // reconciliationTime is the time of the current reconciliation, and should be used for all "now" calculations
5857 reconciliationTime metav1.Time
@@ -84,6 +83,11 @@ type ControlPlane struct {
8483 DeletingMessage string
8584}
8685
86+ type UpToDateResult struct {
87+ LogMessages []string
88+ ConditionMessages []string
89+ }
90+
8791// PreflightCheckResults contains description about pre flight check results blocking machines creation or deletion.
8892type PreflightCheckResults struct {
8993 // HasDeletingMachine reports true if preflight check detected a deleting machine.
@@ -98,7 +102,7 @@ type PreflightCheckResults struct {
98102
99103// NewControlPlane returns an instantiated ControlPlane.
100104func 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 )
105+ infraMachines , err := getInfraMachines (ctx , client , ownedMachines )
102106 if err != nil {
103107 return nil , err
104108 }
@@ -118,32 +122,29 @@ func NewControlPlane(ctx context.Context, managementCluster ManagementCluster, c
118122 // Select machines that should be rolled out because of an outdated configuration or because rolloutAfter/Before expired.
119123 reconciliationTime := metav1 .Now ()
120124 machinesNotUptoDate := make (collections.Machines , len (ownedMachines ))
121- machinesNotUptoDateLogMessages := map [string ][]string {}
122- machinesNotUptoDateConditionMessages := map [string ][]string {}
125+ machinesUpToDateResults := map [string ]UpToDateResult {}
123126 for _ , m := range ownedMachines {
124- upToDate , logMessages , conditionMessages , err := UpToDate (m , kcp , & reconciliationTime , infraObjects , kubeadmConfigs )
127+ upToDate , upToDateResult , err := UpToDate (m , kcp , & reconciliationTime , infraMachines , kubeadmConfigs )
125128 if err != nil {
126129 return nil , err
127130 }
128131 if ! upToDate {
129132 machinesNotUptoDate .Insert (m )
130- machinesNotUptoDateLogMessages [m .Name ] = logMessages
131- machinesNotUptoDateConditionMessages [m .Name ] = conditionMessages
133+ machinesUpToDateResults [m .Name ] = * upToDateResult
132134 }
133135 }
134136
135137 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 ,
138+ KCP : kcp ,
139+ Cluster : cluster ,
140+ Machines : ownedMachines ,
141+ machinesPatchHelpers : patchHelpers ,
142+ machinesNotUptoDate : machinesNotUptoDate ,
143+ machinesUpToDateResults : machinesUpToDateResults ,
144+ KubeadmConfigs : kubeadmConfigs ,
145+ InfraResources : infraMachines ,
146+ reconciliationTime : reconciliationTime ,
147+ managementCluster : managementCluster ,
147148 }, nil
148149}
149150
@@ -256,15 +257,15 @@ func (c *ControlPlane) GetKubeadmConfig(machineName string) (*bootstrapv1.Kubead
256257}
257258
258259// MachinesNeedingRollout return a list of machines that need to be rolled out.
259- func (c * ControlPlane ) MachinesNeedingRollout () (collections.Machines , map [string ][] string ) {
260+ func (c * ControlPlane ) MachinesNeedingRollout () (collections.Machines , map [string ]UpToDateResult ) {
260261 // 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
262+ return c .machinesNotUptoDate .Filter (collections .Not (collections .HasDeletionTimestamp )), c .machinesUpToDateResults
262263}
263264
264265// NotUpToDateMachines return a list of machines that are not up to date with the control
265266// plane's configuration.
266- func (c * ControlPlane ) NotUpToDateMachines () (collections.Machines , map [string ][] string ) {
267- return c .machinesNotUptoDate , c .machinesNotUptoDateConditionMessages
267+ func (c * ControlPlane ) NotUpToDateMachines () (collections.Machines , map [string ]UpToDateResult ) {
268+ return c .machinesNotUptoDate , c .machinesUpToDateResults
268269}
269270
270271// UpToDateMachines returns the machines that are up to date with the control
@@ -273,18 +274,18 @@ func (c *ControlPlane) UpToDateMachines() collections.Machines {
273274 return c .Machines .Difference (c .machinesNotUptoDate )
274275}
275276
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 ) {
277+ // getInfraMachines fetches the InfraMachine for each machine in the collection and returns a map of machine.Name -> InfraMachine .
278+ func getInfraMachines (ctx context.Context , cl client.Client , machines collections.Machines ) (map [string ]* unstructured.Unstructured , error ) {
278279 result := map [string ]* unstructured.Unstructured {}
279280 for _ , m := range machines {
280- infraObj , err := external .GetObjectFromContractVersionedRef (ctx , cl , m .Spec .InfrastructureRef , m .Namespace )
281+ infraMachine , err := external .GetObjectFromContractVersionedRef (ctx , cl , m .Spec .InfrastructureRef , m .Namespace )
281282 if err != nil {
282283 if apierrors .IsNotFound (errors .Cause (err )) {
283284 continue
284285 }
285- return nil , errors .Wrapf (err , "failed to retrieve infra obj for machine %q " , m .Name )
286+ return nil , errors .Wrapf (err , "failed to retrieve InfraMachine for Machine %s " , m .Name )
286287 }
287- result [m .Name ] = infraObj
288+ result [m .Name ] = infraMachine
288289 }
289290 return result , nil
290291}
@@ -297,14 +298,14 @@ func getKubeadmConfigs(ctx context.Context, cl client.Client, machines collectio
297298 if ! bootstrapRef .IsDefined () {
298299 continue
299300 }
300- machineConfig := & bootstrapv1.KubeadmConfig {}
301- if err := cl .Get (ctx , client.ObjectKey {Name : bootstrapRef .Name , Namespace : m .Namespace }, machineConfig ); err != nil {
301+ kubeadmConfig := & bootstrapv1.KubeadmConfig {}
302+ if err := cl .Get (ctx , client.ObjectKey {Name : bootstrapRef .Name , Namespace : m .Namespace }, kubeadmConfig ); err != nil {
302303 if apierrors .IsNotFound (errors .Cause (err )) {
303304 continue
304305 }
305- return nil , errors .Wrapf (err , "failed to retrieve bootstrap config for machine %q " , m .Name )
306+ return nil , errors .Wrapf (err , "failed to retrieve KubeadmConfig for Machine %s " , m .Name )
306307 }
307- result [m .Name ] = machineConfig
308+ result [m .Name ] = kubeadmConfig
308309 }
309310 return result , nil
310311}
0 commit comments