in pkg/controller/maps/controller.go [185:276]
func (r *ReconcileMapsServer) doReconcile(ctx context.Context, ems emsv1alpha1.ElasticMapsServer) (*reconciler.Results, emsv1alpha1.MapsStatus) {
log := ulog.FromContext(ctx)
results := reconciler.NewResult(ctx)
status := newStatus(ems)
enabled, err := r.licenseChecker.EnterpriseFeaturesEnabled(ctx)
if err != nil {
return results.WithError(err), status
}
if !enabled {
msg := "Elastic Maps Server is an enterprise feature. Enterprise features are disabled"
log.Info(msg, "namespace", ems.Namespace, "maps_name", ems.Name)
r.recorder.Eventf(&ems, corev1.EventTypeWarning, events.EventReconciliationError, msg)
// we don't have a good way of watching for the license level to change so just requeue with a reasonably long delay
return results.WithResult(reconcile.Result{Requeue: true, RequeueAfter: 5 * time.Minute}), status
}
isEsAssocConfigured, err := association.IsConfiguredIfSet(ctx, &ems, r.recorder)
if err != nil {
return results.WithError(err), status
}
if !isEsAssocConfigured {
return results, status
}
// Run validation in case the webhook is disabled
if err := r.validate(ctx, ems); err != nil {
return results.WithError(err), status
}
svc, err := common.ReconcileService(ctx, r.Client, NewService(ems), &ems)
if err != nil {
return results.WithError(err), status
}
_, results = certificates.Reconciler{
K8sClient: r.K8sClient(),
DynamicWatches: r.DynamicWatches(),
Owner: &ems,
TLSOptions: ems.Spec.HTTP.TLS,
Namer: EMSNamer,
Labels: ems.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, &ems, events.EventReconciliationError, "Certificate reconciliation error: %v", err)
return results, status
}
emsVersion, err := version.Parse(ems.Spec.Version)
if err != nil {
return results.WithError(err), status
}
assocAllowed, err := association.AllowVersion(emsVersion, ems.Associated(), log, r.recorder)
if err != nil {
return results.WithError(err), status
}
if !assocAllowed {
// will eventually retry once updated, along with the results
// from the certificate reconciliation having a retry after a time period
return results, status
}
configSecret, err := reconcileConfig(ctx, r, ems, r.IPFamily)
if err != nil {
return results.WithError(err), status
}
// build a hash of various inputs to rotate Pods on any change
configHash, err := buildConfigHash(r.K8sClient(), ems, configSecret)
if err != nil {
return results.WithError(fmt.Errorf("build config hash: %w", err)), status
}
deploy, err := r.reconcileDeployment(ctx, ems, configHash)
if err != nil {
return results.WithError(fmt.Errorf("reconcile deployment: %w", err)), status
}
status, err = r.getStatus(ctx, ems, deploy)
if err != nil {
return results.WithError(fmt.Errorf("calculating status: %w", err)), status
}
return results, status
}