kubewarden / kubewarden-controller

Manage admission policies in your Kubernetes cluster with ease
https://kubewarden.io
Apache License 2.0
193 stars 33 forks source link

Revisit Policy status, policy mode status and conditions and refactor the policy subreconciler #804

Open fabriziosestito opened 4 months ago

fabriziosestito commented 4 months ago

Status

At the time of writing, the policy status is composed by [PolicyModeStatus](https://github.com/kubewarden/kubewarden-controller/blob/a331d8d2d4ccd26396935fd9333118c85185280a/api/policies/v1/policy.go#L31) and [PolicyStatusEnum](https://github.com/kubewarden/kubewarden-controller/blob/a331d8d2d4ccd26396935fd9333118c85185280a/api/policies/v1/policy.go#L11). Unfortunately this adds complexity in the reconciliation loop and it could be ambiguous for the user. Instead, we could merge PolicyModeStatus with PolicyStatusEnum having two different final active states PolicyStatusActiveMonitor and PolicyStatusActiveProtect.

Condition

Also, we could revisit the PolicyConditionType. We could either remove them or refactor them to be more explicit. See: https://maelvls.dev/kubernetes-conditions/

Reconciler

The policy subreconciler reconciliation loop could be simplified using the new statuses/conditions.

This is related to: #743, #616

fabriziosestito commented 3 months ago

Also we need to investigate this error

2024-07-19T15:03:43+02:00     ERROR   Reconciler error        {"controller": "policyserver", "controllerGroup": "policies.kubewarden.io", "controllerKind": "PolicyServer", "PolicyServer": {"name":"policy-server-u0y4ypm0"}, "namespace": "", "name": "policy-server-u0y4ypm0", "reconcileID": "44def5e9-383a-4e85-9ed3-770d384c7ac2", "error": "update policy server status error: Operation cannot be fulfilled on policyservers.policies.kubewarden.io \"policy-server-u0y4ypm0\": the object has been modified; please apply your changes to the latest version and try again"}
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        /home/lain/.asdf/installs/golang/1.22.3/packages/pkg/mod/sigs.k8s.io/controller-runtime@v0.18.4/pkg/internal/controller/controller.go:324
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        /home/lain/.asdf/installs/golang/1.22.3/packages/pkg/mod/sigs.k8s.io/controller-runtime@v0.18.4/pkg/internal/controller/controller.go:261
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
        /home/lain/.asdf/installs/golang/1.22.3/packages/pkg/mod/sigs.k8s.io/controller-runtime@v0.18.4/pkg/internal/controller/controller.go:222

which might be related.