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

Add event when different upgrade policy is picked #776

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 6 additions & 9 deletions pkg/controllers/vdb/offlineupgrade_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (o *OfflineUpgradeReconciler) Reconcile(ctx context.Context, _ *ctrl.Reques
funcs := []func(context.Context) (ctrl.Result, error){
// Initiate an upgrade by setting condition and event recording
o.Manager.startUpgrade,
o.logEventIfOnlineUpgradeRequested,
o.logEventIfThisUpgradeWasNotChosen,
// Do a clean shutdown of the cluster
o.postStoppingClusterMsg,
o.stopCluster,
Expand Down Expand Up @@ -139,14 +139,11 @@ func (o *OfflineUpgradeReconciler) Reconcile(ctx context.Context, _ *ctrl.Reques
return ctrl.Result{}, o.Manager.logUpgradeSucceeded(sandbox)
}

// logEventIfOnlineUpgradeRequested will log an event if the vdb has
// OnlineUpgrade requested. We can fall into this codepath if we are running a
// version of Vertica that doesn't support online upgrade.
func (o *OfflineUpgradeReconciler) logEventIfOnlineUpgradeRequested(_ context.Context) (ctrl.Result, error) {
if !o.Manager.ContinuingUpgrade && o.Vdb.Spec.UpgradePolicy == vapi.OnlineUpgrade {
o.VRec.Eventf(o.Vdb, corev1.EventTypeNormal, events.IncompatibleOnlineUpgrade,
"Online upgrade was requested but it is incompatible with the Vertica server. Falling back to offline upgrade.")
}
// logEventIfThisUpgradeWasNotChosen will log an event if the vdb had requested
// a method other than offline or auto. We can fall into this codepath if we
// are running a version of Vertica that doesn't support online upgrade.
func (o *OfflineUpgradeReconciler) logEventIfThisUpgradeWasNotChosen(_ context.Context) (ctrl.Result, error) {
o.Manager.logEventIfRequestedUpgradeIsDifferent(vapi.OfflineUpgrade)
return ctrl.Result{}, nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/controllers/vdb/onlineupgrade_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (o *OnlineUpgradeReconciler) Reconcile(ctx context.Context, _ *ctrl.Request
funcs := []func(context.Context) (ctrl.Result, error){
// Initiate an upgrade by setting condition and event recording
o.Manager.startUpgrade,
o.logEventIfThisUpgradeWasNotChosen,
// Load up state that is used for the subsequent steps
o.loadSubclusterState,
// Figure out all of the status messages that we will report
Expand Down Expand Up @@ -130,6 +131,13 @@ func (o *OnlineUpgradeReconciler) Reconcile(ctx context.Context, _ *ctrl.Request
return ctrl.Result{}, o.Manager.logUpgradeSucceeded(sandbox)
}

// logEventIfThisUpgradeWasNotChosen will write an event log if we are doing this
// upgrade method as a fall back from a requested policy.
func (o *OnlineUpgradeReconciler) logEventIfThisUpgradeWasNotChosen(ctx context.Context) (ctrl.Result, error) {
o.Manager.logEventIfRequestedUpgradeIsDifferent(vapi.OnlineUpgrade)
return ctrl.Result{}, nil
}

// loadSubclusterState will load state into the OnlineUpgradeReconciler that
// is used in subsequent steps.
func (o *OnlineUpgradeReconciler) loadSubclusterState(ctx context.Context) (ctrl.Result, error) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/controllers/vdb/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"strconv"
"strings"

"github.com/go-logr/logr"
vapi "github.com/vertica/vertica-kubernetes/api/v1"
Expand Down Expand Up @@ -631,3 +632,14 @@ func (i *UpgradeManager) routeClientTraffic(ctx context.Context, pfacts *PodFact
i.Log.Info("Updating svc", "selector", svc.Spec.Selector)
return objRec.reconcileExtSvc(ctx, svc, sc)
}

// logEventIfRequestedUpgradeIsDifferent will log an event if the requested
// upgrade, as per the upgrade policy, is different than the actual upgrade
// chosen.
func (i *UpgradeManager) logEventIfRequestedUpgradeIsDifferent(actualUpgrade vapi.UpgradePolicyType) {
if !i.ContinuingUpgrade && i.Vdb.Spec.UpgradePolicy != actualUpgrade && i.Vdb.Spec.UpgradePolicy != vapi.AutoUpgrade {
actualUpgradeAsText := strings.ToLower(string(actualUpgrade))
i.VRec.Eventf(i.Vdb, corev1.EventTypeNormal, events.IncompatibleUpgradeRequested,
"Requested upgrade is incompatible with the Vertica deployment. Falling back to %s upgrade.", actualUpgradeAsText)
}
}
2 changes: 1 addition & 1 deletion pkg/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
AuthParmsCopyFailed = "AuthParmsCopyFailed"
UpgradeStart = "UpgradeStart"
UpgradeSucceeded = "UpgradeSucceeded"
IncompatibleOnlineUpgrade = "IncompatibleOnlineUpgrade"
IncompatibleUpgradeRequested = "IncompatibleUpgradeRequested"
ClusterShutdownStarted = "ClusterShutdownStarted"
ClusterShutdownFailed = "ClusterShutdownFailed"
ClusterShutdownSucceeded = "ClusterShutdownSucceeded"
Expand Down
Loading