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

Upgrade StatefulSet, key missing in env #122121

Closed
chymy opened this issue Nov 30, 2023 · 9 comments
Closed

Upgrade StatefulSet, key missing in env #122121

chymy opened this issue Nov 30, 2023 · 9 comments
Labels
area/controller-manager area/kubectl kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@chymy
Copy link
Contributor

chymy commented Nov 30, 2023

What happened?

There are two versions of StatefulSet resources as follows:
sts-1.yaml has duplicate keys, e.g.: key-1

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: busybox
  labels:
    app: busybox
spec:
  replicas: 1
  revisionHistoryLimit: 10
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
  selector:
    matchLabels:
      app: busybox
  serviceName: ""
  template:
    metadata:
      labels:
        app: busybox
    spec:
      terminationGracePeriodSeconds: 0
      containers:
      - name: busybox
        image: busybox
        command:
        - sleep
        - "36000"
        env:
        - name: key-1
          value: "1"
        - name: key-1
          value: "1"
        imagePullPolicy: IfNotPresent

sts-2.yaml has no duplicate keys:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: busybox
  labels:
    app: busybox
spec:
  replicas: 1
  revisionHistoryLimit: 10
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
  selector:
    matchLabels:
      app: busybox
  serviceName: ""
  template:
    metadata:
      labels:
        app: busybox
    spec:
      terminationGracePeriodSeconds: 0
      containers:
      - name: busybox
        image: busybox
        command:
        - sleep
        - "36000"
        env:
        - name: key-1
          value: "1"
        imagePullPolicy: IfNotPresent

Do the following:
1、kubectl create -f sts-2.yaml
kubectl get sts busybox -oyaml :

apiVersion: apps/v1
kind: StatefulSet
metadata:
  creationTimestamp: "2023-11-30T08:34:21Z"
  generation: 1
  labels:
    app: busybox
  name: busybox
  namespace: default
  resourceVersion: "1308"
  uid: df902802-4faf-458b-abde-806a7e8f5a3b
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: busybox
  serviceName: ""
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: busybox
    spec:
      containers:
      - command:
        - sleep
        - "36000"
        env:
        - name: key-1
          value: "1"
        image: busybox
        imagePullPolicy: IfNotPresent
        name: busybox
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 0
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
status:
  availableReplicas: 1
  collisionCount: 0
  currentReplicas: 1
  currentRevision: busybox-6448b6b4c4
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updateRevision: busybox-6448b6b4c4
  updatedReplicas: 1

The sts env are as follows:

env:
 - name: key-1
    value: "1"

2、kubectl apply -f sts-1.yaml
kubectl get sts busybox -oyaml :

apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"StatefulSet","metadata":{"annotations":{},"labels":{"app":"busybox"},"name":"busybox","namespace":"default"},"spec":{"replicas":1,"revisionHistoryLimit":10,"selector":{"matchLabels":{"app":"busybox"}},"serviceName":"","template":{"metadata":{"labels":{"app":"busybox"}},"spec":{"containers":[{"command":["sleep","36000"],"env":[{"name":"key-1","value":"1"},{"name":"key-1","value":"1"}],"image":"kubernetes-release-docker.artsz.zte.com.cn/k8s/admin/op-containers-kube-proxy:v1.22.3.b77ebe34","imagePullPolicy":"IfNotPresent","name":"busybox"}],"terminationGracePeriodSeconds":0}},"updateStrategy":{"rollingUpdate":{"partition":0},"type":"RollingUpdate"}}}
  creationTimestamp: "2023-11-30T08:34:21Z"
  generation: 1
  labels:
    app: busybox
  name: busybox
  namespace: default
  resourceVersion: "1351"
  uid: df902802-4faf-458b-abde-806a7e8f5a3b
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: busybox
  serviceName: ""
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: busybox
    spec:
      containers:
      - command:
        - sleep
        - "36000"
        env:
        - name: key-1
          value: "1"
        image: busybox
        imagePullPolicy: IfNotPresent
        name: busybox
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 0
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
status:
  availableReplicas: 1
  collisionCount: 0
  currentReplicas: 1
  currentRevision: busybox-6448b6b4c4
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updateRevision: busybox-6448b6b4c4
  updatedReplicas: 1

The sts env are as follows:

env:
 - name: key-1
    value: "1"

3、kubectl apply -f sts-2.yaml
kubectl get sts busybox -oyaml :

apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"StatefulSet","metadata":{"annotations":{},"labels":{"app":"busybox"},"name":"busybox","namespace":"default"},"spec":{"replicas":1,"revisionHistoryLimit":10,"selector":{"matchLabels":{"app":"busybox"}},"serviceName":"","template":{"metadata":{"labels":{"app":"busybox"}},"spec":{"containers":[{"command":["sleep","36000"],"env":[{"name":"key-1","value":"1"}],"image":"kubernetes-release-docker.artsz.zte.com.cn/k8s/admin/op-containers-kube-proxy:v1.22.3.b77ebe34","imagePullPolicy":"IfNotPresent","name":"busybox"}],"terminationGracePeriodSeconds":0}},"updateStrategy":{"rollingUpdate":{"partition":0},"type":"RollingUpdate"}}}
  creationTimestamp: "2023-11-30T08:34:21Z"
  generation: 2
  labels:
    app: busybox
  name: busybox
  namespace: default
  resourceVersion: "1376"
  uid: df902802-4faf-458b-abde-806a7e8f5a3b
spec:
  podManagementPolicy: OrderedReady
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: busybox
  serviceName: ""
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: busybox
    spec:
      containers:
      - command:
        - sleep
        - "36000"
        image: busybox
        imagePullPolicy: IfNotPresent
        name: busybox
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 0
  updateStrategy:
    rollingUpdate:
      partition: 0
    type: RollingUpdate
status:
  collisionCount: 0
  currentRevision: busybox-6448b6b4c4
  observedGeneration: 2
  replicas: 1
  updateRevision: busybox-544d65dd87
  updatedReplicas: 1

The env key-1 disappeared this time, but there is a missing env in the annotation kubectl.kubernetes.io/last-applied-configuration

What did you expect to happen?

There should be env key-1 in the third step.

How can we reproduce it (as minimally and precisely as possible)?

Refer to What happened? step description

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
1.28.3

Cloud provider

no

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

@chymy chymy added the kind/bug Categorizes issue or PR as related to a bug. label Nov 30, 2023
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Nov 30, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 30, 2023
@chymy
Copy link
Contributor Author

chymy commented Nov 30, 2023

/area kubectl
/area controller-manager

@chymy
Copy link
Contributor Author

chymy commented Nov 30, 2023

@kubernetes/sig-cli-kubectl-maintainers

@chymy
Copy link
Contributor Author

chymy commented Nov 30, 2023

@liggitt Could you please take a look?
thank you.

@neolit123
Copy link
Member

/sig apps

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 30, 2023
@DrAuYueng
Copy link
Contributor

Duplicate of #121541.

@DrAuYueng
Copy link
Contributor

/sig cli

@liggitt
Copy link
Member

liggitt commented Nov 30, 2023

This is a duplicate of #58477

Use of env var entries with duplicate names is not recommended, and breaks the name-keyed list when using apply (duplicates are removed). The recommended solution is to stop adding env var entries with duplicate names. Use of duplicate envvar entries has emitted warnings since 1.22.

@liggitt liggitt closed this as completed Nov 30, 2023
@liggitt liggitt closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2023
@liggitt
Copy link
Member

liggitt commented Nov 30, 2023

Note that server-side apply handles this case better, by removing duplicates but not removing all entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/controller-manager area/kubectl kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
Archived in project
Archived in project
Development

No branches or pull requests

5 participants