kube-state-metrics: kube-state-metrics with autosharding stops updating shards when the labels of the statefulset are updated

What happened:

When I updated the labels of the ksm statefulset when kube-state-metrics are deployed with autosharding updates, and thus the recalculation of shards, stop getting to pods that don’t get restarted

What you expected to happen:

I would expect shards update to happen even when statefulset labels are updated, as in k8s this is allowed and it doesn’t cause the pods to get restarted

How to reproduce it (as minimally and precisely as possible):

  1. clone kube-state-metrics repo git clone https://github.com/kubernetes/kube-state-metrics && cd kube-state-metrics
  2. with the editor of your choice add a label to the metadata of the sts prone to change in examples/autosharding/statefulset.yaml e.g. app.revision: '1' and set replicas to 2
  3. deploy ksm with autosharding kubectl apply -k ./examples/autosharding
  4. change the label kubectl patch sts kube-state-metrics -n kube-system --patch '{"metadata": {"labels": {"app.revision": "2"}}}'
  5. scale the statefulset to 3 replicas kubectl scale statefulsets kube-state-metrics --replicas=3 -n kube-system
  6. checks the logs of pod/kube-state-metrics-0 and pod/kube-state-metrics-1 they didn’t update their shards calculation. This is recovered only after all pods are restarted and labels are not changed again.

Anything else we need to know?:

Environment:

  • kube-state-metrics version: 2.11.0
  • Kubernetes version (use kubectl version):
    Client Version: v1.29.3
    Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
    Server Version: v1.27.7-gke.1121002
    
  • Cloud provider or hardware configuration: Google Kubernetes Engine (GKE)
  • Other info: N/A

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (20 by maintainers)

Most upvoted comments

I can have a look. Will try reproducing this issue to understand what happened.