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 b9d3e8a commit cd6a62e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 92 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ Adding a new version? You'll need three changes:
actively monitor their readiness for accepting configuration updates.
[#4368](https://github.com/Kong/kubernetes-ingress-controller/pull/4368
- `KongConsumer` CRD was extended with `Status.Conditions` field. It will now
contain the `Programmed` condition describing whether an object was successfully
contain the `Programmed` condition describing whether an object was successfully
translated into Kong entities and sent to Kong.
[#4409](https://github.com/Kong/kubernetes-ingress-controller/pull/4409
[#4409](https://github.com/Kong/kubernetes-ingress-controller/pull/4409

### Changed

Expand Down
41 changes: 26 additions & 15 deletions hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ var inputControllersNeeded = &typesNeeded{
AcceptsIngressClassNameSpec: false,
NeedsUpdateReferences: true,
RBACVerbs: []string{"get", "list", "watch"},
ConfigStatusNotificationsEnabled: true,
ProgrammedConditionUpdatesEnabled: true,
},
typeNeeded{
Expand Down Expand Up @@ -208,8 +209,6 @@ var inputControllersNeeded = &typesNeeded{
Plural: "ingressclassparameterses",
CacheType: "IngressClassParameters",
NeedsStatusPermissions: false,
ConfigStatusNotificationsEnabled: true,
IngressAddressUpdatesEnabled: true,
AcceptsIngressClassNameAnnotation: false,
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
Expand Down Expand Up @@ -436,8 +435,8 @@ type {{.PackageAlias}}{{.Kind}}Reconciler struct {
Scheme *runtime.Scheme
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration
{{- if .IngressAddressUpdatesEnabled }}
{{ if .IngressAddressUpdatesEnabled }}
DataplaneAddressFinder *dataplane.AddressFinder
{{- end}}
{{- if .ConfigStatusNotificationsEnabled }}
Expand Down Expand Up @@ -607,11 +606,31 @@ 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 }}
{{- /* For ProgrammedConditionUpdatesEnabled we do not update references before status is updated because in case of
a reference to non-existing object, the status update would never happen. */ -}}
{{- if and .NeedsUpdateReferences (not .ProgrammedConditionUpdatesEnabled) }}
{{- template "updateReferences" . }}
{{- end }}
{{- if .ConfigStatusNotificationsEnabled }}
// if status updates are enabled report the status for the object
if r.DataplaneClient.AreKubernetesObjectReportsEnabled() {
{{- if .IngressAddressUpdatesEnabled }}
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 @@ -636,25 +655,17 @@ 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
}
{{- /* For ProgrammedConditionUpdatesEnabled we update references after status is updated because otherwise in case of
a reference to non-existing object, the status update would never happen. */ -}}
{{- if and .NeedsUpdateReferences .ProgrammedConditionUpdatesEnabled }}
{{- template "updateReferences" . }}
{{- end }}
return ctrl.Result{}, nil
Expand Down
130 changes: 56 additions & 74 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.

2 changes: 1 addition & 1 deletion internal/dataplane/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5411,7 +5411,7 @@ func mustNewParser(t *testing.T, storer store.Storer) *Parser {

p, err := NewParser(logrus.New(), storer,
FeatureFlags{
// We'll assume these is true for all tests.
// We'll assume these are true for all tests.
FillIDs: true,
ReportConfiguredKubernetesObjects: true,
},
Expand Down

0 comments on commit cd6a62e

Please sign in to comment.