Skip to content

Commit

Permalink
move updateReferredObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Jul 26, 2023
1 parent 180d86a commit fac6062
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
32 changes: 20 additions & 12 deletions hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -628,25 +646,15 @@ 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)
}
log.V(util.DebugLevel).Info("status update not needed", "namespace", req.Namespace, "name", req.Name)
}
{{- 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
Expand Down
47 changes: 23 additions & 24 deletions internal/controllers/configuration/zz_generated_controllers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fac6062

Please sign in to comment.