in internal/controllers/composition/controller.go [38:105]
func (c *compositionController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := logr.FromContextOrDiscard(ctx)
comp := &apiv1.Composition{}
err := c.client.Get(ctx, req.NamespacedName, comp)
if err != nil {
logger.Error(err, "failed to get composition resource")
return ctrl.Result{}, client.IgnoreNotFound(err)
}
logger = logger.WithValues("compositionName", comp.Name, "compositionNamespace", comp.Namespace, "compositionGeneration", comp.Generation, "synthesisUUID", comp.Status.GetCurrentSynthesisUUID())
if comp.DeletionTimestamp != nil {
return c.reconcileDeletedComposition(ctx, comp)
}
if controllerutil.AddFinalizer(comp, "eno.azure.io/cleanup") {
err = c.client.Update(ctx, comp)
if err != nil {
logger.Error(err, "failed to update composition")
return ctrl.Result{}, err
}
logger.V(1).Info("added cleanup finalizer to composition")
return ctrl.Result{}, nil
}
synth := &apiv1.Synthesizer{}
synth.Name = comp.Spec.Synthesizer.Name
err = c.client.Get(ctx, client.ObjectKeyFromObject(synth), synth)
if errors.IsNotFound(err) {
synth = nil
err = nil
}
if err != nil {
logger.Error(err, "failed to get synthesizer")
return ctrl.Result{}, err
}
if synth != nil {
logger = logger.WithValues("synthesizerName", synth.Name, "synthesizerGeneration", synth.Generation)
}
ctx = logr.NewContext(ctx, logger)
// Write the simplified status
modified, err := c.reconcileSimplifiedStatus(ctx, synth, comp)
if err != nil {
logger.Error(err, "failed to reconcile simplified status")
return ctrl.Result{}, err
}
if modified || synth == nil {
return ctrl.Result{}, nil
}
// Enforce the synthesis timeout period
if syn := comp.Status.InFlightSynthesis; syn != nil && syn.Canceled == nil && syn.Initialized != nil && synth.Spec.PodTimeout != nil {
delta := time.Until(syn.Initialized.Time.Add(synth.Spec.PodTimeout.Duration))
if delta > 0 {
return ctrl.Result{RequeueAfter: delta}, nil
}
syn.Canceled = ptr.To(metav1.Now())
if err := c.client.Status().Update(ctx, comp); err != nil {
logger.Error(err, "failed to update composition status to reflect synthesis timeout")
return ctrl.Result{}, err
}
logger.V(0).Info("synthesis timed out")
return ctrl.Result{}, nil
}
return ctrl.Result{}, nil
}