-
Notifications
You must be signed in to change notification settings - Fork 344
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
Wait for elasticsearch cluster to be up #242
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -2,7 +2,12 @@ package jaeger | |
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"k8s.io/api/apps/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1" | ||
|
@@ -12,8 +17,8 @@ import ( | |
|
||
func (r *ReconcileJaeger) applyElasticsearches(jaeger v1alpha1.Jaeger, desired []esv1alpha1.Elasticsearch) error { | ||
opts := client.MatchingLabels(map[string]string{ | ||
"app.kubernetes.io/instance": jaeger.Name, | ||
"app.kubernetes.io/managed-by": "jaeger-operator", | ||
"app.kubernetes.io/instance": jaeger.Name, | ||
"app.kubernetes.io/part-of": "jaeger", | ||
}) | ||
list := &esv1alpha1.ElasticsearchList{} | ||
if err := r.client.List(context.Background(), opts, list); err != nil { | ||
|
@@ -26,6 +31,9 @@ func (r *ReconcileJaeger) applyElasticsearches(jaeger v1alpha1.Jaeger, desired [ | |
if err := r.client.Create(context.Background(), &d); err != nil { | ||
return err | ||
} | ||
if err := waitForAvailableElastic(r.client, d); err != nil { | ||
return errors.Wrap(err, "elasticsearch cluster didn't get to ready state") | ||
} | ||
} | ||
|
||
for _, d := range inv.Update { | ||
|
@@ -44,3 +52,30 @@ func (r *ReconcileJaeger) applyElasticsearches(jaeger v1alpha1.Jaeger, desired [ | |
|
||
return nil | ||
} | ||
|
||
func waitForAvailableElastic(c client.Client, es esv1alpha1.Elasticsearch) error { | ||
var expectedSize int32 | ||
for _, n := range es.Spec.Nodes { | ||
expectedSize += n.NodeCount | ||
} | ||
return wait.PollImmediate(time.Second, 2*time.Minute, func() (done bool, err error) { | ||
depList := v1.DeploymentList{} | ||
if err = c.List(context.Background(), client.MatchingLabels(es.Labels).InNamespace(es.Namespace), &depList); err != nil { | ||
return false, err | ||
} | ||
available := int32(0) | ||
for _, d := range depList.Items { | ||
if d.Status.Replicas == d.Status.AvailableReplicas { | ||
available++ | ||
} | ||
} | ||
logrus.WithFields(logrus.Fields{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"namespace": es.Namespace, | ||
"name": es.Name, | ||
"desiredNodes": expectedSize, | ||
"availableNodes": available, | ||
}).Debug("Waiting for Elasticsearch to be available") | ||
return available == expectedSize, nil | ||
}) | ||
return nil | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Across the code base, we are now using
log
as alias to this package.