diff --git a/CHANGELOG.md b/CHANGELOG.md index 6645bcb4d..0d8f77d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## main / unreleased +* [ENHANCEMENT] Log debug information about StatefulSets as they are created, updated and deleted. #182 + ## v0.20.1 * [BUGFIX] Improved handling of URL ports in `createPrepareDownscaleEndpoints` function. The function now correctly preserves the port when replacing the host in the URL. #176 diff --git a/development/test-app.yaml b/development/test-app.yaml index c0664a468..eeb011e13 100644 --- a/development/test-app.yaml +++ b/development/test-app.yaml @@ -19,6 +19,7 @@ metadata: name: test-app labels: grafana.com/prepare-downscale: "true" + rollout-group: test-app annotations: grafana.com/prepare-downscale-http-path: "/" grafana.com/prepare-downscale-http-port: "80" @@ -36,3 +37,5 @@ spec: containers: - name: app image: nginx:latest + updateStrategy: + type: OnDelete diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index aa633697a..3d8cf5a35 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -136,12 +136,9 @@ func (c *RolloutController) Init() error { // We enqueue a reconcile request each time any of the observed StatefulSets are updated. The UpdateFunc // is also called every sync period even if no changes occurred. _, err := c.statefulSetsInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { - c.enqueueReconcile() - }, - UpdateFunc: func(old, new interface{}) { - c.enqueueReconcile() - }, + AddFunc: c.onAdded, + UpdateFunc: c.onUpdated, + DeleteFunc: c.onDeleted, }) if err != nil { return err @@ -172,6 +169,53 @@ func (c *RolloutController) Init() error { return nil } +func (c *RolloutController) onAdded(obj interface{}) { + sts, isStatefulSet := obj.(*v1.StatefulSet) + if isStatefulSet { + level.Debug(c.logger).Log( + "msg", "observed StatefulSet added", + "name", sts.Name, + "namespace", sts.Namespace, + "replicas", sts.Spec.Replicas, + "generation", sts.Generation, + "creation_timestamp", sts.CreationTimestamp, + ) + } + + c.enqueueReconcile() +} + +func (c *RolloutController) onUpdated(old, new interface{}) { + oldSts, oldIsStatefulSet := old.(*v1.StatefulSet) + newSts, newIsStatefulSet := new.(*v1.StatefulSet) + if oldIsStatefulSet && newIsStatefulSet && oldSts.Generation != newSts.Generation { + level.Debug(c.logger).Log( + "msg", "observed StatefulSet updated", + "name", oldSts.Name, + "namespace", oldSts.Namespace, + "old_replicas", oldSts.Spec.Replicas, + "new_replicas", newSts.Spec.Replicas, + "old_generation", oldSts.Generation, + "new_generation", newSts.Generation, + ) + } + + c.enqueueReconcile() +} + +func (c *RolloutController) onDeleted(obj interface{}) { + sts, isStatefulSet := obj.(*v1.StatefulSet) + if isStatefulSet { + level.Debug(c.logger).Log( + "msg", "observed StatefulSet deleted", + "name", sts.Name, + "namespace", sts.Namespace, + "replicas", sts.Spec.Replicas, + "generation", sts.Generation, + ) + } +} + // Run runs the controller and blocks until Stop() is called. func (c *RolloutController) Run() { ctx := context.Background()