in pkg/controller/apmserver/controller.go [211:280]
func (r *ReconcileApmServer) doReconcile(ctx context.Context, as *apmv1.ApmServer) (*reconciler.Results, State) {
state := NewState(as)
results := reconciler.NewResult(ctx)
areAssocsConfigured, err := association.AreConfiguredIfSet(ctx, as.GetAssociations(), r.recorder)
if err != nil {
return results.WithError(tracing.CaptureError(ctx, err)), state
}
if !areAssocsConfigured {
return results, state
}
// Run validation in case the webhook is disabled
if err := r.validate(ctx, as); err != nil {
return results.WithError(err), state
}
svc, err := common.ReconcileService(ctx, r.Client, NewService(*as), as)
if err != nil {
return results.WithError(err), state
}
_, results = certificates.Reconciler{
K8sClient: r.K8sClient(),
DynamicWatches: r.DynamicWatches(),
Owner: as,
TLSOptions: as.Spec.HTTP.TLS,
Namer: Namer,
Labels: as.GetIdentityLabels(),
Services: []corev1.Service{*svc},
GlobalCA: r.GlobalCA,
CACertRotation: r.CACertRotation,
CertRotation: r.CertRotation,
GarbageCollectSecrets: true,
}.ReconcileCAAndHTTPCerts(ctx)
if results.HasError() {
_, err := results.Aggregate()
k8s.MaybeEmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Certificate reconciliation error: %v", err)
return results, state
}
asVersion, err := version.Parse(as.Spec.Version)
if err != nil {
return results.WithError(err), state
}
logger := log.WithValues("namespace", as.Namespace, "as_name", as.Name)
assocAllowed, err := association.AllowVersion(asVersion, as, logger, r.recorder)
if err != nil {
return results.WithError(tracing.CaptureError(ctx, err)), state
}
if !assocAllowed {
return results, state // will eventually retry
}
state, err = r.reconcileApmServerDeployment(ctx, state, as, asVersion)
if err != nil {
if apierrors.IsConflict(err) {
log.V(1).Info("Conflict while updating status")
return results.WithResult(reconcile.Result{Requeue: true}), state
}
k8s.MaybeEmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Deployment reconciliation error: %v", err)
return results.WithError(tracing.CaptureError(ctx, err)), state
}
state.UpdateApmServerExternalService(*svc)
_, err = results.WithError(err).Aggregate()
k8s.MaybeEmitErrorEvent(r.recorder, err, as, events.EventReconciliationError, "Reconciliation error: %v", err)
return results, state
}