-
Notifications
You must be signed in to change notification settings - Fork 775
Upgrade masters last when upgrading ES clusters #8871
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Michael Montgomery <[email protected]>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
|
buildkite test this -f p=kind,t=TestNonMasterFirstUpgradeComplexTopology -m s=9.1.2 |
Signed-off-by: Michael Montgomery <[email protected]>
updated. Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
…/cloud-on-k8s into fix-sts-upgrade-issue-recreation
Signed-off-by: Michael Montgomery <[email protected]>
|
buildkite test this -f p=kind,t=TestHandleUpscaleAndSpecChanges_VersionUpgradeDataFirstFlow -m s=9.1.2 |
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a non-master-first upgrade strategy for Elasticsearch clusters. The key change ensures that during version upgrades, non-master nodes (data, ingest, coordinating nodes) are upgraded before master nodes, which helps maintain cluster stability during upgrades.
- Adds logic to separate master and non-master StatefulSets during version upgrades
- Implements upgrade order validation to ensure non-master nodes complete their upgrades first
- Adds comprehensive unit and e2e tests to verify the upgrade flow
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/controller/elasticsearch/driver/upgrade.go | Adds check to identify new clusters vs upgrades by checking if status version is empty |
| pkg/controller/elasticsearch/driver/upscale.go | Implements non-master-first upgrade logic with resource separation and upgrade status checking |
| pkg/controller/elasticsearch/driver/upscale_test.go | Adds comprehensive unit test for version upgrade flow and minor formatting fixes |
| test/e2e/es/non_master_first_upgrade_test.go | Adds e2e test that validates non-master-first upgrade behavior with a watcher |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
|
I will take another look at it today. Edit: was not able to make it today, will do tomorrow first thing |
| // The only adjustment we want to make to master statefulSets before ensuring that all non-master | ||
| // statefulSets have been reconciled is to potentially scale up the replicas | ||
| // which should happen 1 at a time as we adjust the replicas early. | ||
| if err = maybeUpscaleMasterResources(ctx, masterResources); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that calling this when len(nonMasterResources) == 0 (or more generally, when all non-master nodesets have already been upgraded?) can be slightly suboptimal.
Assuming that the initial state is:
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: elasticsearch-sample
spec:
version: 9.1.0
nodeSets:
- name: default
config:
node.roles: ["master", "data", "ingest", "ml"]
node.store.allow_mmap: false
count: 3If we update and upgrade to:
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: elasticsearch-sample
spec:
version: 9.1.2
nodeSets:
- name: default
config:
node.roles: ["master", "data", "ingest", "ml"]
node.store.allow_mmap: false
count: 4Then we are going to scale up the 9.1.0 statefulset, leading to the creation of elasticsearch-sample-es-default-3, but immediately in the next reconciliation we are going to delete elasticsearch-sample-es-default-3 to upgrade it to 9.1.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My previous comment made me wonder if !isVersionUpgrade is actually the only reason we might want to reconcile everything at once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
buildkite test this -f p=kind,t=TestNonMasterFirstUpgradeComplexTopology -m s=8.15.2 |
| func(k *test.K8sClient, t *testing.T) { | ||
| statefulSets, err := essset.RetrieveActualStatefulSets(k.Client, k8s.ExtractNamespacedName(&es)) | ||
| if err != nil { | ||
| t.Logf("failed to get StatefulSets: %s", err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this test fail if we consistently get an error here? (my feeling is that it's not going to be the case because violations is always empty in that case, but maybe I'm missing something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not. I wonder what would be the limit we set on errors in the watcher where it would fail? There are 4 instances I can find where we don't fail in these watchers in the e2e tests currently:
| t.Logf("got error: %v", err) |
| t.Logf("got error: %v", err) |
| t.Logf("failed to list pods: %v", err) |
| t.Logf("got error listing pods: %v", err) |
barkbay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost LGTM, I think we need to adjust the way we scale the master nodes, also the e2e test seems broken (we create the data integrity index with no replicas, which should fail during a rolling upgrade), and may not be accurate in case of errors.
Update upscaleResults with results of upscale. Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
Signed-off-by: Michael Montgomery <[email protected]>
|
buildkite test this -f p=kind,t=TestNonMasterFirstUpgradeComplexTopology -m s=8.15.2 |
Fixes #8429
What is changing?
This ensure that the master StatefulSets are always upgraded last when doing a version upgrade of Elasticsearch.
Validation