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

Allow users to disable version validation to downgrade clusters #5272

Merged
merged 7 commits into from
Jan 25, 2022
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
7 changes: 7 additions & 0 deletions docs/operating-eck/troubleshooting/common-problems.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,10 @@ elastic-cloud-eck.v1.4.0 Elasticsearch (ECK) Operator 1.4.0 elasti
If you are using one of the affected versions of OLM and upgrading OLM to a newer version is not possible then ECK
can still be upgraded by uninstalling and reinstalling it. This can be done by removing the `Subscription` and both `ClusterServiceVersion` resources and adding them again.
On OpenShift the same workaround can be performed in the UI by clicking on "Uninstall Operator" and then reinstalling it through OperatorHub.

[id="{p}-{page_id}-version-downgrade"]
== If you upgraded Elasticsearch to the wrong version
If you accidentally upgrade one of your Elasticsearch clusters to a version that does not exist or a version to which a direct upgrade is not possible from your currently deployed version, a validation will prevent you from going back to the previous version.
The reason for this validation is that ECK will not allow downgrades as this is not supported by Elasticsearch and once the data directory of Elasticsearch has been upgraded there is no way back to the old version without a link:https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-upgrade.html[snapshot restore].

The two scenarios described above however are exceptions because Elasticsearch never started up successfully. If you annotate the Elasticsearch resource with `k8s.eck.elastic.co/disable-downgrade-validation=true` ECK will allow you to go back to the old version at your own risk. Please remove the annotation afterwards to prevent accidental downgrades and reduced availability.
8 changes: 8 additions & 0 deletions pkg/apis/elasticsearch/v1/elasticsearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
// SuspendAnnotation allows users to annotate the Elasticsearch resource with the names of Pods they want to suspend
// for debugging purposes.
SuspendAnnotation = "eck.k8s.elastic.co/suspend"
// DisableDowngradeValidationAnnotation allows circumventing downgrade/upgrade checks.
DisableDowngradeValidationAnnotation = "eck.k8s.elastic.co/disable-downgrade-validation"
// Kind is inferred from the struct name using reflection in SchemeBuilder.Register()
// we duplicate it as a constant here for practical purposes.
Kind = "Elasticsearch"
Expand Down Expand Up @@ -481,6 +483,12 @@ func (es Elasticsearch) IsMarkedForDeletion() bool {
return !es.DeletionTimestamp.IsZero()
}

// IsConfiguredToAllowDowngrades returns true if the DisableDowngradeValidation annotation is set to the value of true.
func (es Elasticsearch) IsConfiguredToAllowDowngrades() bool {
val, exists := es.Annotations[DisableDowngradeValidationAnnotation]
return exists && val == "true"
}

func (es *Elasticsearch) ServiceAccountName() string {
return es.Spec.ServiceAccountName
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/elasticsearch/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@ func (d *defaultDriver) Reconcile(ctx context.Context) *reconciler.Results {
// always update the elasticsearch state bits
d.ReconcileState.UpdateElasticsearchState(*resourcesState, observedState())

allowDownscales := d.ES.IsConfiguredToAllowDowngrades()
if err := d.verifySupportsExistingPods(resourcesState.CurrentPods); err != nil {
return results.WithError(err)
if !allowDownscales {
return results.WithError(err)
}
log.Info("Allowing downgrade on user request", "warning", err.Error())
}

// TODO: support user-supplied certificate (non-ca)
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/elasticsearch/validation/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ func checkNodeSetNameUniqueness(es esv1.Elasticsearch) field.ErrorList {

func noDowngrades(current, proposed esv1.Elasticsearch) field.ErrorList {
var errs field.ErrorList

// allow disabling version validation
if proposed.IsConfiguredToAllowDowngrades() {
return errs
}

currentVer, err := version.Parse(current.Spec.Version)
if err != nil {
// this should not happen, since this is the already persisted version
Expand Down