diff --git a/rollout/controller.go b/rollout/controller.go index b5d8122ac3..c7e51611c2 100644 --- a/rollout/controller.go +++ b/rollout/controller.go @@ -228,7 +228,20 @@ func NewController(cfg ControllerConfig) *Controller { log.Info("Setting up event handlers") // Set up an event handler for when rollout resources change cfg.RolloutsInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.enqueueRollout, + AddFunc: func(obj interface{}) { + controller.enqueueRollout(obj) + ro := unstructuredutil.ObjectToRollout(obj) + if ro != nil { + if cfg.Recorder != nil { + cfg.Recorder.Eventf(ro, record.EventOptions{ + EventType: corev1.EventTypeNormal, + EventReason: conditions.RolloutAddedToInformerReason, + }, "Rollout resource added to informer: %s/%s", ro.Namespace, ro.Name) + } else { + log.Warnf("Recorder is not configured") + } + } + }, UpdateFunc: func(old, new interface{}) { oldRollout := unstructuredutil.ObjectToRollout(old) newRollout := unstructuredutil.ObjectToRollout(new) diff --git a/test/e2e/functional_test.go b/test/e2e/functional_test.go index 71907414e8..d4b27d3e3f 100644 --- a/test/e2e/functional_test.go +++ b/test/e2e/functional_test.go @@ -90,11 +90,12 @@ spec: ExpectRevisionPodCount("1", 0). ExpectRevisionPodCount("2", 1). ExpectRolloutEvents([]string{ - "RolloutNotCompleted", // Rollout not completed, started update to revision 0 (7fd9b5545c) - "RolloutUpdated", // Rollout updated to revision 1 - "NewReplicaSetCreated", // Created ReplicaSet abort-retry-promote-698fbfb9dc (revision 1) - "ScalingReplicaSet", // Scaled up ReplicaSet abort-retry-promote-698fbfb9dc (revision 1) from 0 to 1 - "RolloutCompleted", // Rollout completed update to revision 1 (698fbfb9dc): Initial deploy + "RolloutAddedToInformer", // Rollout added to informer cache + "RolloutNotCompleted", // Rollout not completed, started update to revision 0 (7fd9b5545c) + "RolloutUpdated", // Rollout updated to revision 1 + "NewReplicaSetCreated", // Created ReplicaSet abort-retry-promote-698fbfb9dc (revision 1) + "ScalingReplicaSet", // Scaled up ReplicaSet abort-retry-promote-698fbfb9dc (revision 1) from 0 to 1 + "RolloutCompleted", // Rollout completed update to revision 1 (698fbfb9dc): Initial deploy "RolloutNotCompleted", "RolloutUpdated", // Rollout updated to revision 2 "NewReplicaSetCreated", // Created ReplicaSet abort-retry-promote-75dcb5ddd6 (revision 2) @@ -701,17 +702,18 @@ func (s *FunctionalSuite) TestBlueGreenUpdate() { Then(). ExpectReplicaCounts(3, 6, 3, 3, 3). ExpectRolloutEvents([]string{ - "RolloutUpdated", // Rollout updated to revision 1 - "NewReplicaSetCreated", // Created ReplicaSet bluegreen-7dcd8f8869 (revision 1) - "ScalingReplicaSet", // Scaled up ReplicaSet bluegreen-7dcd8f8869 (revision 1) from 0 to 3 - "RolloutCompleted", // Rollout completed update to revision 1 (7dcd8f8869): Initial deploy - "SwitchService", // Switched selector for service 'bluegreen' from '' to '7dcd8f8869' - "RolloutUpdated", // Rollout updated to revision 2 - "NewReplicaSetCreated", // Created ReplicaSet bluegreen-5498785cd6 (revision 2) - "RolloutNotCompleted", // Rollout went to not completed state started update to revision 2 (85c6899) - "ScalingReplicaSet", // Scaled up ReplicaSet bluegreen-5498785cd6 (revision 2) from 0 to 3 - "SwitchService", // Switched selector for service 'bluegreen' from '7dcd8f8869' to '6c779b88b6' - "RolloutCompleted", // Rollout completed update to revision 2 (6c779b88b6): Completed blue-green update + "RolloutAddedToInformer", // Rollout added to informer cache + "RolloutUpdated", // Rollout updated to revision 1 + "NewReplicaSetCreated", // Created ReplicaSet bluegreen-7dcd8f8869 (revision 1) + "ScalingReplicaSet", // Scaled up ReplicaSet bluegreen-7dcd8f8869 (revision 1) from 0 to 3 + "RolloutCompleted", // Rollout completed update to revision 1 (7dcd8f8869): Initial deploy + "SwitchService", // Switched selector for service 'bluegreen' from '' to '7dcd8f8869' + "RolloutUpdated", // Rollout updated to revision 2 + "NewReplicaSetCreated", // Created ReplicaSet bluegreen-5498785cd6 (revision 2) + "RolloutNotCompleted", // Rollout went to not completed state started update to revision 2 (85c6899) + "ScalingReplicaSet", // Scaled up ReplicaSet bluegreen-5498785cd6 (revision 2) from 0 to 3 + "SwitchService", // Switched selector for service 'bluegreen' from '7dcd8f8869' to '6c779b88b6' + "RolloutCompleted", // Rollout completed update to revision 2 (6c779b88b6): Completed blue-green update }) } diff --git a/utils/conditions/conditions.go b/utils/conditions/conditions.go index c2aaece787..77cd401c63 100644 --- a/utils/conditions/conditions.go +++ b/utils/conditions/conditions.go @@ -174,6 +174,8 @@ const ( // LoadBalancerNotFoundReason is emitted when load balancer can not be found LoadBalancerNotFoundReason = "LoadBalancerNotFound" LoadBalancerNotFoundMessage = "Failed to find load balancer: %s" + + RolloutAddedToInformerReason = "RolloutAddedToInformer" ) // NewRolloutCondition creates a new rollout condition.