Skip to content

Commit

Permalink
feat: Send informer add k8s event (#2834)
Browse files Browse the repository at this point in the history
* add event for reconcilation

Signed-off-by: zachaller <[email protected]>

* add sprig

Signed-off-by: zachaller <[email protected]>

* fmt

Signed-off-by: zachaller <[email protected]>

* fix tests

Signed-off-by: zachaller <[email protected]>

* move event to add informer event

Signed-off-by: zachaller <[email protected]>

* remove bad code

Signed-off-by: zachaller <[email protected]>

* handel bad ro objects

Signed-off-by: zachaller <[email protected]>

* add new event

Signed-off-by: zachaller <[email protected]>

* typo

Signed-off-by: zachaller <[email protected]>

* switch to built in eventf

Signed-off-by: zachaller <[email protected]>

* remove sprig

Signed-off-by: zachaller <[email protected]>

* refactor

Signed-off-by: zachaller <[email protected]>

---------

Signed-off-by: zachaller <[email protected]>
  • Loading branch information
zachaller authored Jul 17, 2023
1 parent 8144fb8 commit 8db151f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
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

0 comments on commit 8db151f

Please sign in to comment.