@@ -409,6 +409,16 @@ func (ctrl *Controller) addNode(obj interface{}) {
409
409
}
410
410
}
411
411
412
+ func (ctrl * Controller ) logPool (pool * mcfgv1.MachineConfigPool , format string , args ... interface {}) {
413
+ msg := fmt .Sprintf (format , args ... )
414
+ glog .Infof ("Pool %s: %s" , pool .Name , msg )
415
+ }
416
+
417
+ func (ctrl * Controller ) logPoolNode (pool * mcfgv1.MachineConfigPool , node * corev1.Node , format string , args ... interface {}) {
418
+ msg := fmt .Sprintf (format , args ... )
419
+ glog .Infof ("Pool %s: node %s: %s" , pool .Name , node .Name , msg )
420
+ }
421
+
412
422
func (ctrl * Controller ) updateNode (old , cur interface {}) {
413
423
oldNode := old .(* corev1.Node )
414
424
curNode := cur .(* corev1.Node )
@@ -441,16 +451,16 @@ func (ctrl *Controller) updateNode(old, cur interface{}) {
441
451
if oldReady != newReady {
442
452
changed = true
443
453
if newReadyErr != nil {
444
- glog . Infof ( "Pool %s: node %s is now reporting unready: %v", pool . Name , curNode . Name , newReadyErr )
454
+ ctrl . logPoolNode ( pool , curNode , "Reporting unready: %v" , newReadyErr )
445
455
} else {
446
- glog . Infof ( "Pool %s: node %s is now reporting ready", pool . Name , curNode . Name )
456
+ ctrl . logPoolNode ( pool , curNode , "Reporting ready" )
447
457
}
448
458
}
449
459
450
460
// Specifically log when a node has completed an update so the MCC logs are a useful central aggregate of state changes
451
461
if oldNode .Annotations [daemonconsts .CurrentMachineConfigAnnotationKey ] != oldNode .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ] &&
452
462
isNodeDone (curNode ) {
453
- glog . Infof ( "Pool %s: node %s has completed update to %s", pool . Name , curNode . Name , curNode .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ])
463
+ ctrl . logPoolNode ( pool , curNode , "Completed update to %s" , curNode .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ])
454
464
changed = true
455
465
} else {
456
466
annos := []string {
@@ -459,13 +469,18 @@ func (ctrl *Controller) updateNode(old, cur interface{}) {
459
469
daemonconsts .MachineConfigDaemonStateAnnotationKey ,
460
470
}
461
471
for _ , anno := range annos {
462
- if oldNode .Annotations [anno ] != curNode .Annotations [anno ] {
463
- glog .Infof ("Pool %s: node %s changed %s = %s" , pool .Name , curNode .Name , anno , curNode .Annotations [anno ])
472
+ newValue := curNode .Annotations [anno ]
473
+ if oldNode .Annotations [anno ] != newValue {
474
+ ctrl .logPoolNode (pool , curNode , "changed annotation %s = %s" , anno , newValue )
464
475
changed = true
476
+ // For the control plane, emit events for these since they're important
477
+ if pool .Name == masterPoolName {
478
+ ctrl .eventRecorder .Eventf (pool , corev1 .EventTypeNormal , "AnnotationChange" , "Node %s now has %s=%s" , curNode .Name , anno , newValue )
479
+ }
465
480
}
466
481
}
467
482
if ! reflect .DeepEqual (oldNode .Labels , curNode .Labels ) {
468
- glog . Infof ( "Pool %s: node %s changed labels", pool . Name , curNode . Name )
483
+ ctrl . logPoolNode ( pool , curNode , " changed labels" )
469
484
changed = true
470
485
}
471
486
}
@@ -742,7 +757,7 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error {
742
757
743
758
candidates , capacity := getAllCandidateMachines (pool , nodes , maxunavail )
744
759
if len (candidates ) > 0 {
745
- glog . Infof ( "Pool %s: % d candidate nodes for update, capacity: %d", pool . Name , len (candidates ), capacity )
760
+ ctrl . logPool ( pool , "% d candidate nodes for update, capacity: %d" , len (candidates ), capacity )
746
761
if err := ctrl .updateCandidateMachines (pool , candidates , capacity ); err != nil {
747
762
if syncErr := ctrl .syncStatusOnly (pool ); syncErr != nil {
748
763
return goerrs .Wrapf (err , "error setting desired machine config annotation for pool %q, sync error: %v" , pool .Name , syncErr )
@@ -783,7 +798,6 @@ func (ctrl *Controller) getNodesForPool(pool *mcfgv1.MachineConfigPool) ([]*core
783
798
}
784
799
785
800
func (ctrl * Controller ) setDesiredMachineConfigAnnotation (nodeName , currentConfig string ) error {
786
- glog .Infof ("Setting node %s to desired config %s" , nodeName , currentConfig )
787
801
return clientretry .RetryOnConflict (nodeUpdateBackoff , func () error {
788
802
oldNode , err := ctrl .kubeClient .CoreV1 ().Nodes ().Get (context .TODO (), nodeName , metav1.GetOptions {})
789
803
if err != nil {
@@ -869,7 +883,7 @@ func (ctrl *Controller) getCurrentEtcdLeader(candidates []*corev1.Node) (*corev1
869
883
// filterControlPlaneCandidateNodes adjusts the candidates and capacity specifically
870
884
// for the control plane, e.g. based on which node is the etcd leader at the time.
871
885
// nolint:unparam
872
- func (ctrl * Controller ) filterControlPlaneCandidateNodes (candidates []* corev1.Node , capacity uint ) ([]* corev1.Node , uint , error ) {
886
+ func (ctrl * Controller ) filterControlPlaneCandidateNodes (pool * mcfgv1. MachineConfigPool , candidates []* corev1.Node , capacity uint ) ([]* corev1.Node , uint , error ) {
873
887
if len (candidates ) <= 1 {
874
888
return candidates , capacity , nil
875
889
}
@@ -880,6 +894,8 @@ func (ctrl *Controller) filterControlPlaneCandidateNodes(candidates []*corev1.No
880
894
var newCandidates []* corev1.Node
881
895
for _ , node := range candidates {
882
896
if node == etcdLeader {
897
+ // For now make this an event so we know it's working, even though it's more of a non-event
898
+ ctrl .eventRecorder .Eventf (pool , corev1 .EventTypeNormal , "DeferringEtcdLeaderUpdate" , "Deferring update of etcd leader %s" , node .Name )
883
899
glog .Infof ("Deferring update of etcd leader: %s" , node .Name )
884
900
continue
885
901
}
@@ -892,23 +908,31 @@ func (ctrl *Controller) filterControlPlaneCandidateNodes(candidates []*corev1.No
892
908
func (ctrl * Controller ) updateCandidateMachines (pool * mcfgv1.MachineConfigPool , candidates []* corev1.Node , capacity uint ) error {
893
909
if pool .Name == masterPoolName {
894
910
var err error
895
- candidates , capacity , err = ctrl .filterControlPlaneCandidateNodes (candidates , capacity )
911
+ candidates , capacity , err = ctrl .filterControlPlaneCandidateNodes (pool , candidates , capacity )
896
912
if err != nil {
897
913
return err
898
914
}
899
915
// In practice right now these counts will be 1 but let's stay general to support 5 etcd nodes in the future
900
- glog . Infof ( "Pool %s: filtered to %d candidate nodes for update, capacity: %d", pool . Name , len (candidates ), capacity )
916
+ ctrl . logPool ( pool , " filtered to %d candidate nodes for update, capacity: %d" , len (candidates ), capacity )
901
917
}
902
918
if capacity < uint (len (candidates )) {
903
919
// Arbitrarily pick the first N candidates; no attempt at sorting.
904
920
// Perhaps later we allow admins to weight somehow, or do something more intelligent.
905
921
candidates = candidates [:capacity ]
906
922
}
923
+ targetConfig := pool .Spec .Configuration .Name
907
924
for _ , node := range candidates {
908
- if err := ctrl .setDesiredMachineConfigAnnotation (node .Name , pool .Spec .Configuration .Name ); err != nil {
925
+ ctrl .logPool (pool , "Setting node %s target to %s" , node .Name , targetConfig )
926
+ if err := ctrl .setDesiredMachineConfigAnnotation (node .Name , targetConfig ); err != nil {
909
927
return goerrs .Wrapf (err , "setting desired config for node %s" , node .Name )
910
928
}
911
929
}
930
+ if len (candidates ) == 1 {
931
+ candidate := candidates [0 ]
932
+ ctrl .eventRecorder .Eventf (pool , corev1 .EventTypeNormal , "SetDesiredConfig" , "Targeted node %s to config %s" , candidate .Name , targetConfig )
933
+ } else {
934
+ ctrl .eventRecorder .Eventf (pool , corev1 .EventTypeNormal , "SetDesiredConfig" , "Set target for %d nodes to config %s" , targetConfig )
935
+ }
912
936
return nil
913
937
}
914
938
0 commit comments