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

Cleaner LastRollingRestart status #124

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Changes from all commits
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
21 changes: 6 additions & 15 deletions operator/pkg/reconciliation/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import (
"k8s.io/client-go/tools/record"
runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"github.com/datastax/cass-operator/operator/pkg/dynamicwatch"

"github.com/datastax/cass-operator/operator/pkg/httphelper"
"github.com/datastax/cass-operator/operator/pkg/events"

api "github.com/datastax/cass-operator/operator/pkg/apis/cassandra/v1beta1"
"github.com/datastax/cass-operator/operator/pkg/dynamicwatch"
"github.com/datastax/cass-operator/operator/pkg/events"
"github.com/datastax/cass-operator/operator/pkg/httphelper"
)

// ReconciliationContext contains all of the input necessary to calculate a list of ReconciliationActions
Expand All @@ -32,7 +31,7 @@ type ReconciliationContext struct {
Recorder record.EventRecorder
ReqLogger logr.Logger

SecretWatches dynamicwatch.DynamicWatches
SecretWatches dynamicwatch.DynamicWatches

// According to golang recommendations the context should not be stored in a struct but given that
// this is passed around as a parameter we feel that its a fair compromise. For further discussion
Expand All @@ -54,12 +53,11 @@ func CreateReconciliationContext(
rec record.EventRecorder,
secretWatches dynamicwatch.DynamicWatches,
reqLogger logr.Logger) (*ReconciliationContext, error) {

rc := &ReconciliationContext{}
rc.Request = req
rc.Client = cli
rc.Scheme = scheme
rc.Recorder = &events.LoggingEventRecorder{EventRecorder: rec, ReqLogger: reqLogger,}
rc.Recorder = &events.LoggingEventRecorder{EventRecorder: rec, ReqLogger: reqLogger}
rc.SecretWatches = secretWatches
rc.ReqLogger = reqLogger
rc.Ctx = context.Background()
Expand All @@ -84,15 +82,8 @@ func CreateReconciliationContext(
if rc.Datacenter.Status.LastServerNodeStarted.IsZero() {
rc.Datacenter.Status.LastServerNodeStarted = metav1.Unix(1, 0)
}

if rc.Datacenter.Status.LastRollingRestart.IsZero() {
dcPatch := runtimeClient.MergeFrom(dc.DeepCopy())
dc.Status.LastRollingRestart = metav1.Now()
err := rc.Client.Status().Patch(rc.Ctx, dc, dcPatch)
if err != nil {
rc.ReqLogger.Error(err, "error patching datacenter status for rolling restart")
return nil, err
}
rc.Datacenter.Status.LastRollingRestart = metav1.Unix(1, 0)
}

httpClient, err := httphelper.BuildManagementApiHttpClient(dc, cli, rc.Ctx)
Expand Down