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

Log information about StatefulSets as they are created, updated and deleted #182

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions development/test-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -36,3 +37,5 @@ spec:
containers:
- name: app
image: nginx:latest
updateStrategy:
type: OnDelete
56 changes: 50 additions & 6 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down