Commit 8f5f061c authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #50263 from liyinan926/branch1

Automatic merge from submit-queue (batch tested with PRs 50173, 50324, 50288, 50263, 50333) Copy annotations from StatefulSet to owned ControllerRevisions **What this PR does / why we need it**: This PR starts copying annotations from a `StatefulSet`'s metadata to the `ControllerRevision`s it owns. `DaemonSet` controller copies the annotations from a `DaemonSet`s metadata to the `ControllerRevision`s it owns. One of the annotation copied is `kubernetes.io/change-cause`, which is used in `DaemonSetHistoryViewer` to fill in the `CHANGE-CAUSE` column of revision history of a `DaemonSet`. For consistency, the `StatefulSet` controller should do the same, i.e., copy annotations in a `StatefulSet`'s metadata to the `ControllerRevision`s it owns for consistency. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #50158. **Special notes for your reviewer**: /assign @kow3ns **Release note**: ```release-note Copy annotations from a StatefulSet's metadata to the ControllerRevisions it owns ```
parents 788664b7 2c1ada38
...@@ -311,11 +311,21 @@ func newRevision(set *apps.StatefulSet, revision int64) (*apps.ControllerRevisio ...@@ -311,11 +311,21 @@ func newRevision(set *apps.StatefulSet, revision int64) (*apps.ControllerRevisio
if err != nil { if err != nil {
return nil, err return nil, err
} }
return history.NewControllerRevision(set, cr, err := history.NewControllerRevision(set,
controllerKind, controllerKind,
selector, selector,
runtime.RawExtension{Raw: patch}, runtime.RawExtension{Raw: patch},
revision) revision)
if err != nil {
return nil, err
}
if cr.ObjectMeta.Annotations == nil {
cr.ObjectMeta.Annotations = make(map[string]string)
}
for key, value := range set.Annotations {
cr.ObjectMeta.Annotations[key] = value
}
return cr, nil
} }
// applyRevision returns a new StatefulSet constructed by restoring the state in revision to set. If the returned error // applyRevision returns a new StatefulSet constructed by restoring the state in revision to set. If the returned error
......
...@@ -280,6 +280,12 @@ func TestCreateApplyRevision(t *testing.T) { ...@@ -280,6 +280,12 @@ func TestCreateApplyRevision(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
set.Spec.Template.Spec.Containers[0].Name = "foo" set.Spec.Template.Spec.Containers[0].Name = "foo"
if set.Annotations == nil {
set.Annotations = make(map[string]string)
}
key := "foo"
expectedValue := "bar"
set.Annotations[key] = expectedValue
restoredSet, err := applyRevision(set, revision) restoredSet, err := applyRevision(set, revision)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -291,6 +297,13 @@ func TestCreateApplyRevision(t *testing.T) { ...@@ -291,6 +297,13 @@ func TestCreateApplyRevision(t *testing.T) {
if !history.EqualRevision(revision, restoredRevision) { if !history.EqualRevision(revision, restoredRevision) {
t.Errorf("wanted %v got %v", string(revision.Data.Raw), string(restoredRevision.Data.Raw)) t.Errorf("wanted %v got %v", string(revision.Data.Raw), string(restoredRevision.Data.Raw))
} }
value, ok := restoredRevision.Annotations[key]
if !ok {
t.Errorf("missing annotation %s", key)
}
if value != expectedValue {
t.Errorf("for annotation %s wanted %s got %s", key, expectedValue, value)
}
} }
func newPVC(name string) v1.PersistentVolumeClaim { func newPVC(name string) v1.PersistentVolumeClaim {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment