@@ -198,19 +198,6 @@ type ClusterStatus struct {
198198 HasRKE2ServingSecret bool
199199}
200200
201- func (w * Workload ) getControlPlaneNodes (ctx context.Context ) (* corev1.NodeList , error ) {
202- nodes := & corev1.NodeList {}
203- labels := map [string ]string {
204- labelNodeRoleControlPlane : "true" ,
205- }
206-
207- if err := w .List (ctx , nodes , ctrlclient .MatchingLabels (labels )); err != nil {
208- return nil , err
209- }
210-
211- return nodes , nil
212- }
213-
214201// PatchNodes patches the nodes in the workload cluster.
215202func (w * Workload ) PatchNodes (ctx context.Context , cp * ControlPlane ) error {
216203 errList := []error {}
@@ -399,6 +386,60 @@ func (w *Workload) UpdateAgentConditions(controlPlane *ControlPlane) {
399386 })
400387}
401388
389+ // UpdateNodeMetadata is responsible for populating node metadata after
390+ // it is referenced from machine object.
391+ func (w * Workload ) UpdateNodeMetadata (ctx context.Context , controlPlane * ControlPlane ) error {
392+ for nodeName , machine := range controlPlane .Machines {
393+ if machine .Spec .Bootstrap .ConfigRef == nil {
394+ continue
395+ }
396+
397+ if machine .Status .NodeRef != nil {
398+ nodeName = machine .Status .NodeRef .Name
399+ }
400+
401+ conditions .MarkTrue (machine , controlplanev1 .NodeMetadataUpToDate )
402+
403+ node , nodeFound := w .Nodes [nodeName ]
404+ if ! nodeFound {
405+ conditions .MarkUnknown (
406+ machine ,
407+ controlplanev1 .NodeMetadataUpToDate ,
408+ controlplanev1 .NodePatchFailedReason , "associated node not found" )
409+
410+ continue
411+ } else if name , ok := node .Annotations [clusterv1 .MachineAnnotation ]; ! ok || name != machine .Name {
412+ conditions .MarkUnknown (
413+ machine ,
414+ controlplanev1 .NodeMetadataUpToDate ,
415+ controlplanev1 .NodePatchFailedReason , fmt .Sprintf ("node object is missing %s annotation" , clusterv1 .MachineAnnotation ))
416+
417+ continue
418+ }
419+
420+ rkeConfig , found := controlPlane .Rke2Configs [machine .Name ]
421+ if ! found {
422+ conditions .MarkUnknown (
423+ machine ,
424+ controlplanev1 .NodeMetadataUpToDate ,
425+ controlplanev1 .NodePatchFailedReason , "associated RKE2 config not found" )
426+
427+ continue
428+ }
429+
430+ annotations .AddAnnotations (node , rkeConfig .Spec .AgentConfig .NodeAnnotations )
431+ }
432+
433+ return w .PatchNodes (ctx , controlPlane )
434+ }
435+
436+ // UpdateEtcdConditions is responsible for updating machine conditions reflecting the status of all the etcd members.
437+ // This operation is best effort, in the sense that in case of problems in retrieving member status, it sets
438+ // the condition to Unknown state without returning any error.
439+ func (w * Workload ) UpdateEtcdConditions (controlPlane * ControlPlane ) {
440+ w .updateManagedEtcdConditions (controlPlane )
441+ }
442+
402443type aggregateFromMachinesToRCPInput struct {
403444 controlPlane * ControlPlane
404445 machineConditions []clusterv1.ConditionType
@@ -409,6 +450,19 @@ type aggregateFromMachinesToRCPInput struct {
409450 note string
410451}
411452
453+ func (w * Workload ) getControlPlaneNodes (ctx context.Context ) (* corev1.NodeList , error ) {
454+ nodes := & corev1.NodeList {}
455+ labels := map [string ]string {
456+ labelNodeRoleControlPlane : "true" ,
457+ }
458+
459+ if err := w .List (ctx , nodes , ctrlclient .MatchingLabels (labels )); err != nil {
460+ return nil , err
461+ }
462+
463+ return nodes , nil
464+ }
465+
412466// aggregateFromMachinesToRCP aggregates a group of conditions from machines to RCP.
413467// NOTE: this func follows the same aggregation rules used by conditions.Merge thus giving priority to
414468// errors, then warning, info down to unknown.
@@ -510,13 +564,6 @@ func aggregateFromMachinesToRCP(input aggregateFromMachinesToRCPInput) {
510564 }
511565}
512566
513- // UpdateEtcdConditions is responsible for updating machine conditions reflecting the status of all the etcd members.
514- // This operation is best effort, in the sense that in case of problems in retrieving member status, it sets
515- // the condition to Unknown state without returning any error.
516- func (w * Workload ) UpdateEtcdConditions (controlPlane * ControlPlane ) {
517- w .updateManagedEtcdConditions (controlPlane )
518- }
519-
520567func (w * Workload ) updateManagedEtcdConditions (controlPlane * ControlPlane ) {
521568 // NOTE: This methods uses control plane nodes only to get in contact with etcd but then it relies on etcd
522569 // as ultimate source of truth for the list of members and for their health.
@@ -552,50 +599,3 @@ func (w *Workload) updateManagedEtcdConditions(controlPlane *ControlPlane) {
552599 conditions .MarkTrue (machine , controlplanev1 .MachineEtcdMemberHealthyCondition )
553600 }
554601}
555-
556- // UpdateNodeMetadata is responsible for populating node metadata after
557- // it is referenced from machine object.
558- func (w * Workload ) UpdateNodeMetadata (ctx context.Context , controlPlane * ControlPlane ) error {
559- for nodeName , machine := range controlPlane .Machines {
560- if machine .Spec .Bootstrap .ConfigRef == nil {
561- continue
562- }
563-
564- if machine .Status .NodeRef != nil {
565- nodeName = machine .Status .NodeRef .Name
566- }
567-
568- conditions .MarkTrue (machine , controlplanev1 .NodeMetadataUpToDate )
569-
570- node , nodeFound := w .Nodes [nodeName ]
571- if ! nodeFound {
572- conditions .MarkUnknown (
573- machine ,
574- controlplanev1 .NodeMetadataUpToDate ,
575- controlplanev1 .NodePatchFailedReason , "associated node not found" )
576-
577- continue
578- } else if name , ok := node .Annotations [clusterv1 .MachineAnnotation ]; ! ok || name != machine .Name {
579- conditions .MarkUnknown (
580- machine ,
581- controlplanev1 .NodeMetadataUpToDate ,
582- controlplanev1 .NodePatchFailedReason , fmt .Sprintf ("node object is missing %s annotation" , clusterv1 .MachineAnnotation ))
583-
584- continue
585- }
586-
587- rkeConfig , found := controlPlane .Rke2Configs [machine .Name ]
588- if ! found {
589- conditions .MarkUnknown (
590- machine ,
591- controlplanev1 .NodeMetadataUpToDate ,
592- controlplanev1 .NodePatchFailedReason , "associated RKE2 config not found" )
593-
594- continue
595- }
596-
597- annotations .AddAnnotations (node , rkeConfig .Spec .AgentConfig .NodeAnnotations )
598- }
599-
600- return w .PatchNodes (ctx , controlPlane )
601- }
0 commit comments