diff --git a/hack/generators/controllers/networking/main.go b/hack/generators/controllers/networking/main.go index 97d3d2a0d3..c1be470357 100644 --- a/hack/generators/controllers/networking/main.go +++ b/hack/generators/controllers/networking/main.go @@ -599,11 +599,29 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re return ctrl.Result{}, err } +{{- define "updateReferences" }} + // update reference relationship from the {{.Kind}} to other objects. + if err := updateReferredObjects(ctx, r.Client, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { + if apierrors.IsNotFound(err) { + // reconcile again if the secret does not exist yet + return ctrl.Result{ + Requeue: true, + }, nil + } + return ctrl.Result{}, err + } +{{- end }} + +{{- if and .NeedsUpdateReferences (not .ProgrammedConditionEnabled) }} + {{- template "updateReferences" . }} +{{- end }} + {{- if or .IngressStatusUpdatesEnabled .ProgrammedConditionEnabled }} // if status updates are enabled report the status for the object if r.DataplaneClient.AreKubernetesObjectReportsEnabled() { {{- if .IngressStatusUpdatesEnabled }} log.V(util.DebugLevel).Info("determining whether data-plane configuration has succeeded", "namespace", req.Namespace, "name", req.Name) + if !r.DataplaneClient.KubernetesObjectIsConfigured(obj) { log.V(util.DebugLevel).Info("resource not yet configured in the data-plane", "namespace", req.Namespace, "name", req.Name) return ctrl.Result{Requeue: true}, nil // requeue until the object has been properly configured @@ -628,7 +646,6 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re conditions, updateNeeded := ctrlutils.EnsureProgrammedCondition(configurationStatus, obj.Generation, obj.Status.Conditions) obj.Status.Conditions = conditions {{- end }} - if updateNeeded { return ctrl.Result{}, r.Status().Update(ctx, obj) } @@ -636,17 +653,8 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re } {{- end}} -{{- if .NeedsUpdateReferences }} - // update reference relationship from the {{.Kind}} to other objects. - if err := updateReferredObjects(ctx, r.Client, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { - if apierrors.IsNotFound(err) { - // reconcile again if the secret does not exist yet - return ctrl.Result{ - Requeue: true, - }, nil - } - return ctrl.Result{}, err - } +{{- if and .NeedsUpdateReferences .ProgrammedConditionEnabled }} + {{- template "updateReferences" . }} {{- end }} return ctrl.Result{}, nil diff --git a/internal/controllers/configuration/zz_generated_controllers.go b/internal/controllers/configuration/zz_generated_controllers.go index d5d6cf3a01..7ae33db7d2 100644 --- a/internal/controllers/configuration/zz_generated_controllers.go +++ b/internal/controllers/configuration/zz_generated_controllers.go @@ -401,9 +401,20 @@ func (r *NetV1IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request if err := r.DataplaneClient.UpdateObject(obj); err != nil { return ctrl.Result{}, err } + // update reference relationship from the Ingress to other objects. + if err := updateReferredObjects(ctx, r.Client, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { + if apierrors.IsNotFound(err) { + // reconcile again if the secret does not exist yet + return ctrl.Result{ + Requeue: true, + }, nil + } + return ctrl.Result{}, err + } // if status updates are enabled report the status for the object if r.DataplaneClient.AreKubernetesObjectReportsEnabled() { log.V(util.DebugLevel).Info("determining whether data-plane configuration has succeeded", "namespace", req.Namespace, "name", req.Name) + if !r.DataplaneClient.KubernetesObjectIsConfigured(obj) { log.V(util.DebugLevel).Info("resource not yet configured in the data-plane", "namespace", req.Namespace, "name", req.Name) return ctrl.Result{Requeue: true}, nil // requeue until the object has been properly configured @@ -420,22 +431,11 @@ func (r *NetV1IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request if err != nil { return ctrl.Result{}, fmt.Errorf("failed to update load balancer address: %w", err) } - if updateNeeded { return ctrl.Result{}, r.Status().Update(ctx, obj) } log.V(util.DebugLevel).Info("status update not needed", "namespace", req.Namespace, "name", req.Name) } - // update reference relationship from the Ingress to other objects. - if err := updateReferredObjects(ctx, r.Client, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { - if apierrors.IsNotFound(err) { - // reconcile again if the secret does not exist yet - return ctrl.Result{ - Requeue: true, - }, nil - } - return ctrl.Result{}, err - } return ctrl.Result{}, nil } @@ -1040,7 +1040,6 @@ func (r *KongV1KongConsumerReconciler) Reconcile(ctx context.Context, req ctrl.R configurationStatus := r.DataplaneClient.KubernetesObjectConfigurationStatus(obj) conditions, updateNeeded := ctrlutils.EnsureProgrammedCondition(configurationStatus, obj.Generation, obj.Status.Conditions) obj.Status.Conditions = conditions - if updateNeeded { return ctrl.Result{}, r.Status().Update(ctx, obj) } @@ -1384,9 +1383,20 @@ func (r *KongV1Beta1TCPIngressReconciler) Reconcile(ctx context.Context, req ctr if err := r.DataplaneClient.UpdateObject(obj); err != nil { return ctrl.Result{}, err } + // update reference relationship from the TCPIngress to other objects. + if err := updateReferredObjects(ctx, r.Client, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { + if apierrors.IsNotFound(err) { + // reconcile again if the secret does not exist yet + return ctrl.Result{ + Requeue: true, + }, nil + } + return ctrl.Result{}, err + } // if status updates are enabled report the status for the object if r.DataplaneClient.AreKubernetesObjectReportsEnabled() { log.V(util.DebugLevel).Info("determining whether data-plane configuration has succeeded", "namespace", req.Namespace, "name", req.Name) + if !r.DataplaneClient.KubernetesObjectIsConfigured(obj) { log.V(util.DebugLevel).Info("resource not yet configured in the data-plane", "namespace", req.Namespace, "name", req.Name) return ctrl.Result{Requeue: true}, nil // requeue until the object has been properly configured @@ -1403,22 +1413,11 @@ func (r *KongV1Beta1TCPIngressReconciler) Reconcile(ctx context.Context, req ctr if err != nil { return ctrl.Result{}, fmt.Errorf("failed to update load balancer address: %w", err) } - if updateNeeded { return ctrl.Result{}, r.Status().Update(ctx, obj) } log.V(util.DebugLevel).Info("status update not needed", "namespace", req.Namespace, "name", req.Name) } - // update reference relationship from the TCPIngress to other objects. - if err := updateReferredObjects(ctx, r.Client, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil { - if apierrors.IsNotFound(err) { - // reconcile again if the secret does not exist yet - return ctrl.Result{ - Requeue: true, - }, nil - } - return ctrl.Result{}, err - } return ctrl.Result{}, nil } @@ -1578,6 +1577,7 @@ func (r *KongV1Beta1UDPIngressReconciler) Reconcile(ctx context.Context, req ctr // if status updates are enabled report the status for the object if r.DataplaneClient.AreKubernetesObjectReportsEnabled() { log.V(util.DebugLevel).Info("determining whether data-plane configuration has succeeded", "namespace", req.Namespace, "name", req.Name) + if !r.DataplaneClient.KubernetesObjectIsConfigured(obj) { log.V(util.DebugLevel).Info("resource not yet configured in the data-plane", "namespace", req.Namespace, "name", req.Name) return ctrl.Result{Requeue: true}, nil // requeue until the object has been properly configured @@ -1594,7 +1594,6 @@ func (r *KongV1Beta1UDPIngressReconciler) Reconcile(ctx context.Context, req ctr if err != nil { return ctrl.Result{}, fmt.Errorf("failed to update load balancer address: %w", err) } - if updateNeeded { return ctrl.Result{}, r.Status().Update(ctx, obj) }