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

Make sure rollout restarts are performed for stateful sets #281

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"reflect"
"sort"
"sync"
"time"

"github.com/m3db/m3db-operator/pkg/apis/m3dboperator"
myspec "github.com/m3db/m3db-operator/pkg/apis/m3dboperator/v1alpha1"
Expand Down Expand Up @@ -69,6 +70,7 @@ const (
controllerName = "m3db-controller"
clusterWorkQueueName = "m3dbcluster-work-queue"
podWorkQueueName = "pods-work-queue"
rolloutTimeFormat = "2006-01-02T150405"
)

var (
Expand Down Expand Up @@ -1071,6 +1073,7 @@ func updatedStatefulSet(
// 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 {
updateSpecTemplate(actual)
delete(actual.Annotations, annotations.Update)
return actual, true, nil
}
Expand All @@ -1083,9 +1086,18 @@ func updatedStatefulSet(
expected.Status = actual.DeepCopy().Status

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

// updates spec template so that rollout update is always performed.
func updateSpecTemplate(sts *appsv1.StatefulSet) {
if sts.Spec.Template.Annotations == nil {
sts.Spec.Template.Annotations = map[string]string{}
}
sts.Spec.Template.Annotations[annotations.Rollout] = time.Now().Format(rolloutTimeFormat)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you use the k8s-native time helpers? That should handle formatting for you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. I assume k8s annotation values don't have similar restrictions as label values?

}

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
Expand Down
2 changes: 2 additions & 0 deletions pkg/k8sops/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
// Update is the annotation used by the operator to determine if a StatefulSet is
// allowed to be updated.
Update = "operator.m3db.io/update"
// Rollout is the annotation used by the operator to force rollout update of a StatefulSet.
Rollout = "operator.m3db.io/rollout"

// EnabledVal is the value that indicates an annotation is enabled.
EnabledVal = "enabled"
Expand Down