Skip to content

Commit

Permalink
Do not reconcile APM Server if association is not fully configured (e…
Browse files Browse the repository at this point in the history
…lastic#2224)

* Do not reconcile APM Server if association is not ready
  • Loading branch information
barkbay authored and mjmbischoff committed Jan 13, 2020
1 parent 1d2a429 commit 39b7ab7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/apmserver/apmserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ func (r *ReconcileApmServer) Reconcile(request reconcile.Request) (reconcile.Res
return reconcile.Result{}, err
}

if !association.IsConfiguredIfSet(&as, r.recorder) {
return reconcile.Result{}, nil
}

return r.doReconcile(request, &as)
}

Expand Down
23 changes: 20 additions & 3 deletions pkg/controller/common/association/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
package association

import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/events"
"github.com/elastic/cloud-on-k8s/pkg/utils/k8s"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
)

// ElasticsearchAuthSettings returns the user and the password to be used by an associated object to authenticate
Expand All @@ -30,3 +31,19 @@ func ElasticsearchAuthSettings(
}
return assocConf.AuthSecretKey, string(secret.Data[assocConf.AuthSecretKey]), nil
}

// IsConfiguredIfSet checks if an association is set in the spec and if it has been configured by an association controller.
// This is used to prevent the deployment of an associated resource while the association is not yet fully configured.
func IsConfiguredIfSet(associated commonv1.Associated, r record.EventRecorder) bool {
esRef := associated.ElasticsearchRef()
if (&esRef).IsDefined() && !associated.AssociationConf().IsConfigured() {
r.Event(associated, v1.EventTypeWarning, events.EventAssociationError, "Elasticsearch backend is not configured")
log.Info("Elasticsearch association not established: skipping associated resource deployment reconciliation",
"kind", associated.GetObjectKind().GroupVersionKind().Kind,
"namespace", associated.GetNamespace(),
"name", associated.GetName(),
)
return false
}
return true
}
6 changes: 2 additions & 4 deletions pkg/controller/kibana/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

kbv1 "github.com/elastic/cloud-on-k8s/pkg/apis/kibana/v1"
"github.com/elastic/cloud-on-k8s/pkg/controller/common"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/association"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/certificates/http"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/deployment"
driver2 "github.com/elastic/cloud-on-k8s/pkg/controller/common/driver"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/events"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/keystore"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/operator"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler"
Expand Down Expand Up @@ -233,9 +233,7 @@ func (d *driver) Reconcile(
params operator.Parameters,
) *reconciler.Results {
results := reconciler.Results{}
if kb.RequiresAssociation() && !kb.AssociationConf().IsConfigured() {
d.recorder.Event(kb, corev1.EventTypeWarning, events.EventAssociationError, "Elasticsearch backend is not configured")
log.Info("Elasticsearch association not established: skipping Kibana deployment reconciliation", "namespace", kb.Namespace, "kibana_name", kb.Name)
if !association.IsConfiguredIfSet(kb, d.recorder) {
return &results
}

Expand Down

0 comments on commit 39b7ab7

Please sign in to comment.