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

Wait for elasticsearch cluster to be up #242

Merged
merged 3 commits into from
Feb 28, 2019
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
39 changes: 37 additions & 2 deletions pkg/controller/jaeger/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package jaeger

import (
"context"
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Copy link
Contributor

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.

"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"
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/logrus/log

"namespace": es.Namespace,
"name": es.Name,
"desiredNodes": expectedSize,
"availableNodes": available,
}).Debug("Waiting for Elasticsearch to be available")
return available == expectedSize, nil
})
return nil
}
9 changes: 5 additions & 4 deletions pkg/controller/jaeger/jaeger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func defaultStrategyChooser(instance *v1alpha1.Jaeger) strategy.S {
}

func (r *ReconcileJaeger) apply(jaeger v1alpha1.Jaeger, str strategy.S) error {
// secrets have to be created before ES - they are mounted to the ES pod
if err := r.applySecrets(jaeger, str.Secrets()); err != nil {
return err
}

elasticsearches := str.Elasticsearches()
if strings.EqualFold(viper.GetString("es-provision"), v1alpha1.FlagProvisionElasticsearchTrue) {
if err := r.applyElasticsearches(jaeger, elasticsearches); err != nil {
Expand Down Expand Up @@ -164,10 +169,6 @@ func (r *ReconcileJaeger) apply(jaeger v1alpha1.Jaeger, str strategy.S) error {
return err
}

if err := r.applySecrets(jaeger, str.Secrets()); err != nil {
return err
}

if err := r.applyCronJobs(jaeger, str.CronJobs()); err != nil {
return err
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/storage/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ func (ed *ElasticsearchDeployment) Elasticsearch() *esv1alpha1.Elasticsearch {
Namespace: ed.Jaeger.Namespace,
Name: esSecret.name,
Labels: map[string]string{
"app": "jaeger",
"app.kubernetes.io/name": esSecret.name,
"app.kubernetes.io/instance": ed.Jaeger.Name,
"app.kubernetes.io/component": "elasticsearch",
"app.kubernetes.io/part-of": "jaeger",
"app.kubernetes.io/managed-by": "jaeger-operator",
"app": "jaeger",
"app.kubernetes.io/name": esSecret.name,
"app.kubernetes.io/instance": ed.Jaeger.Name,
"app.kubernetes.io/component": "elasticsearch",
"app.kubernetes.io/part-of": "jaeger",
// We cannot use jaeger-operator label because our controllers would try
// to manipulate with objects created by ES operator.
//"app.kubernetes.io/managed-by": "jaeger-operator",
},
OwnerReferences: []metav1.OwnerReference{asOwner(ed.Jaeger)},
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/cert_generation.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/bash

# The script it taken from https://github.com/openshift/cluster-logging-operator
# The script is taken from https://github.com/openshift/cluster-logging-operator

WORKING_DIR=${WORKING_DIR:-/tmp/_working_dir}
NAMESPACE=${NAMESPACE:-openshift-logging}
Expand Down