mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Copy annotations from StatefulSet to ControllerRevisions it owns
This commit is contained in:
parent
fddc7f3e50
commit
89fd3b0ebd
@ -311,11 +311,21 @@ func newRevision(set *apps.StatefulSet, revision int64) (*apps.ControllerRevisio
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return history.NewControllerRevision(set,
|
||||
cr, err := history.NewControllerRevision(set,
|
||||
controllerKind,
|
||||
selector,
|
||||
runtime.RawExtension{Raw: patch},
|
||||
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
|
||||
|
@ -280,6 +280,12 @@ func TestCreateApplyRevision(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -291,6 +297,13 @@ func TestCreateApplyRevision(t *testing.T) {
|
||||
if !history.EqualRevision(revision, restoredRevision) {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user