func()

in internal/controllers/watch/pruning.go [16:50]


func (c *pruningController) 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")
		return ctrl.Result{}, client.IgnoreNotFound(err)
	}

	synth := &apiv1.Synthesizer{}
	synth.Name = comp.Spec.Synthesizer.Name
	err = c.client.Get(ctx, client.ObjectKeyFromObject(synth), synth)
	if client.IgnoreNotFound(err) != nil {
		logger.Error(err, "failed to get synthesizer")
		return ctrl.Result{}, err
	}

	for i, ir := range comp.Status.InputRevisions {
		if hasBindingKey(comp, synth, ir.Key) {
			continue
		}
		comp.Status.InputRevisions = append(comp.Status.InputRevisions[:i], comp.Status.InputRevisions[i+1:]...)
		err = c.client.Status().Update(ctx, comp)
		if err != nil {
			logger.Error(err, "failed to update composition status")
			return ctrl.Result{}, err
		}

		logger.V(1).Info("pruned old input revision from composition status", "compositionName", comp.Name, "compositionNamespace", comp.Namespace, "ref", ir.Key)
		return ctrl.Result{}, nil
	}

	return ctrl.Result{}, nil
}