Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: populate Programmed condition for KongConsumer #4409

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Adding a new version? You'll need three changes:
updates. The controller will now send configuration to such Gateways and will
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
translated into Kong entities and sent to Kong.
[#4409](https://github.com/Kong/kubernetes-ingress-controller/pull/4409

### Changed

Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/configuration.konghq.com_kongconsumers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ spec:
resource.
properties:
conditions:
default:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: "Conditions describe the current conditions of the KongConsumer.
\n Known condition types are: \n * \"Programmed\""
items:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
Expand Down Expand Up @@ -125,7 +133,11 @@ spec:
- status
- type
type: object
maxItems: 8
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
type: object
username:
description: Username is a Kong cluster-unique username of the consumer.
Expand Down
12 changes: 12 additions & 0 deletions deploy/single/all-in-one-dbless-enterprise.yaml

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

12 changes: 12 additions & 0 deletions deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml

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

12 changes: 12 additions & 0 deletions deploy/single/all-in-one-dbless-konnect-enterprise.yaml

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

12 changes: 12 additions & 0 deletions deploy/single/all-in-one-dbless-konnect.yaml

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

12 changes: 12 additions & 0 deletions deploy/single/all-in-one-dbless-legacy.yaml

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

12 changes: 12 additions & 0 deletions deploy/single/all-in-one-dbless.yaml

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

12 changes: 12 additions & 0 deletions deploy/single/all-in-one-postgres-enterprise.yaml

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

12 changes: 12 additions & 0 deletions deploy/single/all-in-one-postgres.yaml

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

57 changes: 46 additions & 11 deletions hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ var inputControllersNeeded = &typesNeeded{
Plural: "ingresses",
CacheType: "IngressV1",
NeedsStatusPermissions: true,
CapableOfStatusUpdates: true,
ConfigStatusNotificationsEnabled: true,
IngressAddressUpdatesEnabled: true,
AcceptsIngressClassNameAnnotation: true,
AcceptsIngressClassNameSpec: true,
NeedsUpdateReferences: true,
Expand Down Expand Up @@ -147,6 +148,8 @@ var inputControllersNeeded = &typesNeeded{
AcceptsIngressClassNameSpec: false,
NeedsUpdateReferences: true,
RBACVerbs: []string{"get", "list", "watch"},
ConfigStatusNotificationsEnabled: true,
ProgrammedConditionUpdatesEnabled: true,
},
typeNeeded{
Group: "configuration.konghq.com",
Expand All @@ -173,7 +176,8 @@ var inputControllersNeeded = &typesNeeded{
Plural: "tcpingresses",
CacheType: "TCPIngress",
NeedsStatusPermissions: true,
CapableOfStatusUpdates: true,
ConfigStatusNotificationsEnabled: true,
IngressAddressUpdatesEnabled: true,
AcceptsIngressClassNameAnnotation: true,
AcceptsIngressClassNameSpec: false,
NeedsUpdateReferences: true,
Expand All @@ -189,7 +193,8 @@ var inputControllersNeeded = &typesNeeded{
Plural: "udpingresses",
CacheType: "UDPIngress",
NeedsStatusPermissions: true,
CapableOfStatusUpdates: true,
ConfigStatusNotificationsEnabled: true,
IngressAddressUpdatesEnabled: true,
AcceptsIngressClassNameAnnotation: true,
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
Expand All @@ -204,7 +209,6 @@ var inputControllersNeeded = &typesNeeded{
Plural: "ingressclassparameterses",
CacheType: "IngressClassParameters",
NeedsStatusPermissions: false,
CapableOfStatusUpdates: false,
AcceptsIngressClassNameAnnotation: false,
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
Expand Down Expand Up @@ -328,9 +332,17 @@ type typeNeeded struct {
// its status
NeedsStatusPermissions bool

// CapableOfStatusUpdates indicates that the controllers should manage status
// updates for the resource.
CapableOfStatusUpdates bool
// ConfigStatusNotificationsEnabled indicates that the controller should receive updates via the StatusQueue when the
// configuration status of the resource changes.
ConfigStatusNotificationsEnabled bool

// IngressAddressUpdatesEnabled indicates that the controllers should update the address of the ingress for the
// resource.
IngressAddressUpdatesEnabled bool

// ProgrammedConditionUpdatesEnabled indicates that the controllers should manage the programmed condition for the
// resource.
ProgrammedConditionUpdatesEnabled bool

// NeedUpdateReferences is true if we need to update the reference relationships
// between reconciled object and other objects.
Expand Down Expand Up @@ -423,9 +435,11 @@ type {{.PackageAlias}}{{.Kind}}Reconciler struct {
Scheme *runtime.Scheme
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration
{{- if .CapableOfStatusUpdates }}
{{- if .IngressAddressUpdatesEnabled }}

DataplaneAddressFinder *dataplane.AddressFinder
{{- end}}
{{- if .ConfigStatusNotificationsEnabled }}
StatusQueue *status.Queue
{{- end}}
{{- if or .AcceptsIngressClassNameSpec .AcceptsIngressClassNameAnnotation}}
Expand Down Expand Up @@ -453,7 +467,7 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) SetupWithManager(mgr ctrl.Manager
return err
}

{{- if .CapableOfStatusUpdates}}
{{- if .ConfigStatusNotificationsEnabled }}
// if configured, start the status updater controller
if r.StatusQueue != nil {
if err := c.Watch(
Expand Down Expand Up @@ -592,7 +606,7 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
return ctrl.Result{}, err
}

{{- if .NeedsUpdateReferences }}
{{- 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) {
Expand All @@ -605,9 +619,16 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
}
{{- end }}

{{- if .CapableOfStatusUpdates}}
{{- /* 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) {
Expand All @@ -626,13 +647,27 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update load balancer address: %w", err)
}
{{- end }}

{{- if .ProgrammedConditionUpdatesEnabled }}
log.V(util.DebugLevel).Info("updating programmed condition status", "namespace", req.Namespace, "name", req.Name)
configurationStatus := r.DataplaneClient.KubernetesObjectConfigurationStatus(obj)
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}}

{{- /* 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
}
`