Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send informer add k8s event #2834

Merged
merged 14 commits into from
Jul 17, 2023
15 changes: 14 additions & 1 deletion rollout/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 18 additions & 16 deletions test/e2e/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
}

Expand Down
2 changes: 2 additions & 0 deletions utils/conditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down