@@ -50,9 +50,8 @@ type ControlPlane struct {
50
50
Machines collections.Machines
51
51
machinesPatchHelpers map [string ]* patch.Helper
52
52
53
- machinesNotUptoDate collections.Machines
54
- machinesNotUptoDateLogMessages map [string ][]string
55
- machinesNotUptoDateConditionMessages map [string ][]string
53
+ machinesNotUptoDate collections.Machines
54
+ machinesNotUpToDateResults map [string ]NotUpToDateResult
56
55
57
56
// reconciliationTime is the time of the current reconciliation, and should be used for all "now" calculations
58
57
reconciliationTime metav1.Time
@@ -98,7 +97,7 @@ type PreflightCheckResults struct {
98
97
99
98
// NewControlPlane returns an instantiated ControlPlane.
100
99
func 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 )
102
101
if err != nil {
103
102
return nil , err
104
103
}
@@ -118,32 +117,29 @@ func NewControlPlane(ctx context.Context, managementCluster ManagementCluster, c
118
117
// Select machines that should be rolled out because of an outdated configuration or because rolloutAfter/Before expired.
119
118
reconciliationTime := metav1 .Now ()
120
119
machinesNotUptoDate := make (collections.Machines , len (ownedMachines ))
121
- machinesNotUptoDateLogMessages := map [string ][]string {}
122
- machinesNotUptoDateConditionMessages := map [string ][]string {}
120
+ machinesNotUpToDateResults := map [string ]NotUpToDateResult {}
123
121
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 )
125
123
if err != nil {
126
124
return nil , err
127
125
}
128
126
if ! upToDate {
129
127
machinesNotUptoDate .Insert (m )
130
- machinesNotUptoDateLogMessages [m .Name ] = logMessages
131
- machinesNotUptoDateConditionMessages [m .Name ] = conditionMessages
128
+ machinesNotUpToDateResults [m .Name ] = * notUpToDateResult
132
129
}
133
130
}
134
131
135
132
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 ,
147
143
}, nil
148
144
}
149
145
@@ -256,15 +252,15 @@ func (c *ControlPlane) GetKubeadmConfig(machineName string) (*bootstrapv1.Kubead
256
252
}
257
253
258
254
// 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 ) {
260
256
// 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
262
258
}
263
259
264
260
// NotUpToDateMachines return a list of machines that are not up to date with the control
265
261
// 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
268
264
}
269
265
270
266
// UpToDateMachines returns the machines that are up to date with the control
@@ -273,18 +269,18 @@ func (c *ControlPlane) UpToDateMachines() collections.Machines {
273
269
return c .Machines .Difference (c .machinesNotUptoDate )
274
270
}
275
271
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 ) {
278
274
result := map [string ]* unstructured.Unstructured {}
279
275
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 )
281
277
if err != nil {
282
278
if apierrors .IsNotFound (errors .Cause (err )) {
283
279
continue
284
280
}
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 )
286
282
}
287
- result [m .Name ] = infraObj
283
+ result [m .Name ] = infraMachine
288
284
}
289
285
return result , nil
290
286
}
@@ -297,14 +293,14 @@ func getKubeadmConfigs(ctx context.Context, cl client.Client, machines collectio
297
293
if ! bootstrapRef .IsDefined () {
298
294
continue
299
295
}
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 {
302
298
if apierrors .IsNotFound (errors .Cause (err )) {
303
299
continue
304
300
}
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 )
306
302
}
307
- result [m .Name ] = machineConfig
303
+ result [m .Name ] = kubeadmConfig
308
304
}
309
305
return result , nil
310
306
}
0 commit comments