Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: After deleting a pod and scaling up the statefulset with different valid envs in the same container simultaneously, then the output events of executing the command is below: What you expected to happen: update successfully. How to reproduce it (as minimally and precisely as possible): a statefulset. apply this statefulset's yaml: After a while, execute , and the pod is running a new stateful's yaml, which a new env key and more replicas. the pod and apply a new stateful's yaml the statefulset Environment: Kubernetes version (use ): Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"", GitTreeState:"clean", BuildDate:"2019-02-28T13:37:52Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"", GitTreeState:"clean", BuildDate:"2019-02-28T13:30:26Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
/sig apps
Meet same problem while using kube-addon-manager. vs and patchStrategy
+1
In some cases, add in the env which using can solve the problem.
/assign
I think the root cause of this is the strategic patch. As mentioned, we have to use the to fix the problem which tells the strategic patch to remove the field so the spec could pass the validation process of statefulsets. It would lead to API broken if we change the behaviour of strategic merge patch, I'll dig around in the apps validation process and try to find out the solution to this.
Thank you for your reply. According to your advice, I tried to add in my second statefulset's yaml, but I still could not update statefulset correctly. How to fix my yamls to get around the problem?
/unassign Sorry, I do not have enough time for this, anyone interested could take it from here.
I don't think the problem comes from your YAML, the problem comes from the controller that doesn't update the fields properly.
/assign

Discussion:
if err != nil { return nil, err } <del> err = json.Unmarshal(patched, clone) </del> <ins> restoredSet := &apps.StatefulSet{} err = json.Unmarshal(patched, restoredSet) </ins> if err != nil { return nil, err } <del> return clone, nil </del> <ins> return restoredSet, nil </ins> } // nextRevision finds the next valid revision number based on revisions. If the length of revisions

} } <ins> func TestRollingUpdateApplyRevision(t *testing.T) { set := newStatefulSet(1) set.Status.CollisionCount = new(int32) currentSet := set.DeepCopy() currentRevision, err := newRevision(set, 1, set.Status.CollisionCount) if err != nil { t.Fatal(err) } set.Spec.Template.Spec.Containers[0].Env = []v1.EnvVar{{Name: "foo", Value: "bar"}} updateSet := set.DeepCopy() updateRevision, err := newRevision(set, 2, set.Status.CollisionCount) if err != nil { t.Fatal(err) } restoredCurrentSet, err := ApplyRevision(set, currentRevision) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(currentSet.Spec.Template, restoredCurrentSet.Spec.Template) { t.Errorf("want %v got %v", currentSet.Spec.Template, restoredCurrentSet.Spec.Template) } restoredUpdateSet, err := ApplyRevision(set, updateRevision) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(updateSet.Spec.Template, restoredUpdateSet.Spec.Template) { t.Errorf("want %v got %v", updateSet.Spec.Template, restoredUpdateSet.Spec.Template) } } </ins> func TestGetPersistentVolumeClaims(t *testing.T) { // nil inherits statefulset labels