Skip to content

Commit

Permalink
feat: populate Programmed condition for KongConsumer
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Jul 25, 2023
1 parent 25fa4fa commit d6c2c27
Show file tree
Hide file tree
Showing 21 changed files with 664 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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.

64 changes: 40 additions & 24 deletions hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var inputControllersNeeded = &typesNeeded{
Plural: "ingresses",
CacheType: "IngressV1",
NeedsStatusPermissions: true,
CapableOfStatusUpdates: true,
IngressStatusUpdatesEnabled: true,
AcceptsIngressClassNameAnnotation: true,
AcceptsIngressClassNameSpec: true,
NeedsUpdateReferences: true,
Expand Down Expand Up @@ -147,6 +147,7 @@ var inputControllersNeeded = &typesNeeded{
AcceptsIngressClassNameSpec: false,
NeedsUpdateReferences: true,
RBACVerbs: []string{"get", "list", "watch"},
ProgrammedConditionEnabled: true,
},
typeNeeded{
Group: "configuration.konghq.com",
Expand All @@ -173,7 +174,7 @@ var inputControllersNeeded = &typesNeeded{
Plural: "tcpingresses",
CacheType: "TCPIngress",
NeedsStatusPermissions: true,
CapableOfStatusUpdates: true,
IngressStatusUpdatesEnabled: true,
AcceptsIngressClassNameAnnotation: true,
AcceptsIngressClassNameSpec: false,
NeedsUpdateReferences: true,
Expand All @@ -189,7 +190,7 @@ var inputControllersNeeded = &typesNeeded{
Plural: "udpingresses",
CacheType: "UDPIngress",
NeedsStatusPermissions: true,
CapableOfStatusUpdates: true,
IngressStatusUpdatesEnabled: true,
AcceptsIngressClassNameAnnotation: true,
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
Expand All @@ -204,7 +205,7 @@ var inputControllersNeeded = &typesNeeded{
Plural: "ingressclassparameterses",
CacheType: "IngressClassParameters",
NeedsStatusPermissions: false,
CapableOfStatusUpdates: false,
IngressStatusUpdatesEnabled: false,
AcceptsIngressClassNameAnnotation: false,
AcceptsIngressClassNameSpec: false,
RBACVerbs: []string{"get", "list", "watch"},
Expand Down Expand Up @@ -328,9 +329,12 @@ type typeNeeded struct {
// its status
NeedsStatusPermissions bool

// CapableOfStatusUpdates indicates that the controllers should manage status
// updates for the resource.
CapableOfStatusUpdates bool
// IngressStatusUpdatesEnabled indicates that the controllers should manage status
// updates for the Ingress resource.
IngressStatusUpdatesEnabled bool

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

// NeedUpdateReferences is true if we need to update the reference relationships
// between reconciled object and other objects.
Expand Down Expand Up @@ -423,9 +427,12 @@ type {{.PackageAlias}}{{.Kind}}Reconciler struct {
Scheme *runtime.Scheme
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration
{{- if .CapableOfStatusUpdates }}
{{- if .IngressStatusUpdatesEnabled }}
DataplaneAddressFinder *dataplane.AddressFinder
{{- end}}
{{- if or .IngressStatusUpdatesEnabled .ProgrammedConditionEnabled }}
StatusQueue *status.Queue
{{- end}}
{{- if or .AcceptsIngressClassNameSpec .AcceptsIngressClassNameAnnotation}}
Expand Down Expand Up @@ -453,7 +460,7 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) SetupWithManager(mgr ctrl.Manager
return err
}
{{- if .CapableOfStatusUpdates}}
{{- if or .IngressStatusUpdatesEnabled .ProgrammedConditionEnabled }}
// if configured, start the status updater controller
if r.StatusQueue != nil {
if err := c.Watch(
Expand Down Expand Up @@ -592,24 +599,11 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
return ctrl.Result{}, err
}
{{- 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
}
{{- end }}
{{- if .CapableOfStatusUpdates}}
{{- 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 @@ -626,13 +620,35 @@ 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 .ProgrammedConditionEnabled }}
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}}
{{- 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
}
{{- end }}
return ctrl.Result{}, nil
}
`
Loading

0 comments on commit d6c2c27

Please sign in to comment.