in pkg/controller/nginxingress/nginx_ingress_controller.go [187:220]
func (n *nginxIngressControllerReconciler) ReconcileResource(ctx context.Context, nic *approutingv1alpha1.NginxIngressController, res *manifests.NginxResources) ([]approutingv1alpha1.ManagedObjectReference, error) {
if nic == nil {
return nil, errors.New("nginxIngressController cannot be nil")
}
if res == nil {
return nil, errors.New("resources cannot be nil")
}
lgr := log.FromContext(ctx)
var managedResourceRefs []approutingv1alpha1.ManagedObjectReference
for _, obj := range res.Objects() {
// TODO: upsert works fine for now but we want to set annotations exactly on the nginx service, we should use an alternative strategy for that in the future
if err := util.Upsert(ctx, n.client, obj); err != nil {
// publish an event so cx can see things like their policy is preventing us from creating a resource
n.events.Eventf(nic, corev1.EventTypeWarning, "EnsuringManagedResourcesFailed", "Failed to ensure managed resource %s %s/%s: %s", obj.GetObjectKind().GroupVersionKind().Kind, obj.GetNamespace(), obj.GetName(), err.Error())
lgr.Error(err, "unable to upsert object", "name", obj.GetName(), "kind", obj.GetObjectKind().GroupVersionKind().Kind, "namespace", obj.GetNamespace())
return nil, fmt.Errorf("upserting object: %w", err)
}
if manifests.HasTopLevelLabels(obj.GetLabels()) {
managedResourceRefs = append(managedResourceRefs, approutingv1alpha1.ManagedObjectReference{
Name: obj.GetName(),
Namespace: obj.GetNamespace(),
Kind: obj.GetObjectKind().GroupVersionKind().Kind,
APIGroup: obj.GetObjectKind().GroupVersionKind().Group,
})
}
}
return managedResourceRefs, nil
}