func()

in pkg/controller/enterprisesearch/enterprisesearch_controller.go [181:262]


func (r *ReconcileEnterpriseSearch) doReconcile(ctx context.Context, ent entv1.EnterpriseSearch) (*reconciler.Results, entv1.EnterpriseSearchStatus) {
	results := reconciler.NewResult(ctx)
	status := newStatus(ent)

	isEsAssocConfigured, err := association.IsConfiguredIfSet(ctx, &ent, 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, &ent); err != nil {
		return results.WithError(err), status
	}

	svc, err := common.ReconcileService(ctx, r.Client, NewService(ent), &ent)
	if err != nil {
		return results.WithError(err), status
	}

	_, results = certificates.Reconciler{
		K8sClient:             r.K8sClient(),
		DynamicWatches:        r.DynamicWatches(),
		Owner:                 &ent,
		TLSOptions:            ent.Spec.HTTP.TLS,
		Namer:                 entv1.Namer,
		Labels:                ent.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, &ent, events.EventReconciliationError, "Certificate reconciliation error: %v", err)
		return results, status
	}

	entVersion, err := version.Parse(ent.Spec.Version)
	if err != nil {
		return results.WithError(err), status
	}
	assocAllowed, err := association.AllowVersion(entVersion, ent.Associated(), ulog.FromContext(ctx), r.recorder)
	if err != nil {
		return results.WithError(err), status
	}
	if !assocAllowed {
		return results, status // will eventually retry once updated
	}

	configSecret, err := ReconcileConfig(ctx, r, ent, r.IPFamily)
	if err != nil {
		return results.WithError(err), status
	}

	// toggle read-only mode for Enterprise Search version upgrades
	upgrade := VersionUpgrade{k8sClient: r.K8sClient(), recorder: r.Recorder(), ent: ent, dialer: r.Dialer}
	if err := upgrade.Handle(ctx); err != nil {
		return results.WithError(fmt.Errorf("version upgrade: %w", err)), status
	}

	// build a hash of various inputs to rotate Pods on any change
	configHash, err := buildConfigHash(r.K8sClient(), ent, configSecret)
	if err != nil {
		return results.WithError(fmt.Errorf("build config hash: %w", err)), status
	}

	deploy, err := r.reconcileDeployment(ctx, ent, configHash)
	if err != nil {
		return results.WithError(fmt.Errorf("reconcile deployment: %w", err)), status
	}

	status, err = r.generateStatus(ctx, ent, deploy, svc.Name)
	if err != nil {
		return results.WithError(fmt.Errorf("updating status: %w", err)), status
	}

	return results, status
}