-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To better match zen1 and zen2 requirements (especially zen 1), we should only create one master node at a time. This is achieved here by: * slowly incrementing master StatefulSets replicas, as long as the upscaleState allows us to do so * inspecting the current nodes at upscaleState initialization. If the cluster is not bootstrapped yet, any number of masters can be created. Else, we allow master node creation only if there's not a master in the process of being created already. * because the above point can hardly tolerate an out-of-date cache, we check pods vs. StatefulSet spec expectations beforehand. * zen1 & zen2 configuration in elasticsearch.yml now needs to be patched after adjusting the number of replicas Some side-effects of this features: * cluster bootstrap/UUID annotation is moved to its own file since not only related to zen2 * downscale expectations checks can be removed, since checked at a higher level
- Loading branch information
Showing
19 changed files
with
582 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package driver | ||
|
||
import ( | ||
"github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1alpha1" | ||
"github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/observer" | ||
"github.com/elastic/cloud-on-k8s/pkg/utils/k8s" | ||
) | ||
|
||
const ( | ||
// ClusterUUIDAnnotationName used to store the cluster UUID as an annotation when cluster has been bootstrapped. | ||
ClusterUUIDAnnotationName = "elasticsearch.k8s.elastic.co/cluster-uuid" | ||
) | ||
|
||
// AnnotatedForBootstrap returns true if the cluster has been annotated with the UUID already. | ||
func AnnotatedForBootstrap(cluster v1alpha1.Elasticsearch) bool { | ||
_, bootstrapped := cluster.Annotations[ClusterUUIDAnnotationName] | ||
return bootstrapped | ||
} | ||
|
||
func ReconcileClusterUUID(c k8s.Client, cluster *v1alpha1.Elasticsearch, observedState observer.State) error { | ||
if AnnotatedForBootstrap(*cluster) { | ||
// already annotated, nothing to do. | ||
return nil | ||
} | ||
if clusterIsBootstrapped(observedState) { | ||
// cluster bootstrapped but not annotated yet | ||
return annotateWithUUID(cluster, observedState, c) | ||
} | ||
// cluster not bootstrapped yet | ||
return nil | ||
} | ||
|
||
// clusterIsBootstrapped returns true if the cluster has formed and has a UUID. | ||
func clusterIsBootstrapped(observedState observer.State) bool { | ||
return observedState.ClusterState != nil && len(observedState.ClusterState.ClusterUUID) > 0 | ||
} | ||
|
||
// annotateWithUUID annotates the cluster with its UUID, to mark it as "bootstrapped". | ||
func annotateWithUUID(cluster *v1alpha1.Elasticsearch, observedState observer.State, c k8s.Client) error { | ||
log.Info("Annotating bootstrapped cluster with its UUID", "namespace", cluster.Namespace, "es_name", cluster.Name) | ||
if cluster.Annotations == nil { | ||
cluster.Annotations = make(map[string]string) | ||
} | ||
cluster.Annotations[ClusterUUIDAnnotationName] = observedState.ClusterState.ClusterUUID | ||
return c.Update(cluster) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.