Skip to content

Commit

Permalink
[controller] Always remove update annotation after processing Statefu…
Browse files Browse the repository at this point in the history
…lSet
  • Loading branch information
jeromefroe committed Sep 30, 2020
1 parent fd5c37d commit 7ed9d21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,20 @@ func updatedStatefulSet(
update = true
}

// If we don't need to perform an update to the StatefulSet's spec, but the StatefulSet
// has the update annotation, we'll still update the StatefulSet to remove the update
// annotation. This ensures that users can always set the update annotation and then
// wait for it to be removed to know if the operator has processed a StatefulSet.
if !update {
return nil, false, nil
delete(actual.Annotations, annotations.Update)
return actual, true, nil
}

copyAnnotations(expected, actual)
return expected, true, nil
}

func copyAnnotations(expected, actual *appsv1.StatefulSet) {
// It's okay for users to add annotations to a StatefulSet after it has been created so
// we'll want to copy over any that exist on the actual StatefulSet but not the expected
// one. The only exception is we don't want to copy over the update annotation so users
Expand All @@ -1006,6 +1016,4 @@ func updatedStatefulSet(
expected.Annotations[k] = v
}
}

return expected, true, nil
}
16 changes: 16 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,22 @@ func TestHandleUpdateClusterUpdatesStatefulSets(t *testing.T) {
newImage: "m3db:v2.0.0",
expUpdateStatefulSets: []string{"cluster1-rep2"},
},
{
name: "removes update annotation even if stateful set doesn't change",
cluster: newMeta("cluster1", map[string]string{
"foo": "bar",
"operator.m3db.io/app": "m3db",
"operator.m3db.io/cluster": "cluster1",
}, nil),
sets: []*metav1.ObjectMeta{
newMeta("cluster1-rep0", nil, nil),
newMeta("cluster1-rep1", nil, map[string]string{
annotations.Update: "enabled",
}),
newMeta("cluster1-rep2", nil, nil),
},
expUpdateStatefulSets: []string{"cluster1-rep1"},
},
{
name: "doesn't call update for replica changes",
cluster: newMeta("cluster1", map[string]string{
Expand Down

0 comments on commit 7ed9d21

Please sign in to comment.