1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 01:16:55 +00:00
kyverno/pkg/controllers/cleanup/controller.go

399 lines
14 KiB
Go
Raw Normal View History

package cleanup
import (
"context"
"time"
"github.com/go-logr/logr"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
kyvernov2 "github.com/kyverno/kyverno/api/kyverno/v2"
"github.com/kyverno/kyverno/pkg/client/clientset/versioned"
kyvernov2informers "github.com/kyverno/kyverno/pkg/client/informers/externalversions/kyverno/v2"
kyvernov2listers "github.com/kyverno/kyverno/pkg/client/listers/kyverno/v2"
"github.com/kyverno/kyverno/pkg/clients/dclient"
"github.com/kyverno/kyverno/pkg/config"
"github.com/kyverno/kyverno/pkg/controllers"
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
enginecontext "github.com/kyverno/kyverno/pkg/engine/context"
feat: enhance global context (#9710) * feat(globalcontext): add event handling Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): handle cache sync error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): ensure api is called during init Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * design(events): decouple events from policies a bit Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): use status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): make status optional Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): status update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): codegen Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): delete yaml annotations Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): fix status in tests Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcotext): update enqueue func Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): rbac Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): retry logic Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): unknown api call in test Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * bump Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix: set unique name for each testing resource Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: update readme Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: log msg Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: add delays Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: delay gctce creation Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: check Kyverno status Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: update chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: revert chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * test(globalcontext): print actual status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add necessary delays and check status before applying Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * test(globalcontext): long refreshInterval Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: log success Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print informer data Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): use client instead of informer Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print status after update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print ResourceVersion Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: remove gcecontroller from other controllers Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): update status only once Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore: remove excess logs Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add store to cleanup controller Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> --------- Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-02-23 12:34:04 +02:00
"github.com/kyverno/kyverno/pkg/engine/context/loaders"
"github.com/kyverno/kyverno/pkg/engine/factories"
"github.com/kyverno/kyverno/pkg/engine/jmespath"
"github.com/kyverno/kyverno/pkg/event"
"github.com/kyverno/kyverno/pkg/logging"
"github.com/kyverno/kyverno/pkg/metrics"
"github.com/kyverno/kyverno/pkg/toggle"
feat: support conditions in PolicyException (#8577) * feat: support conditions in PolicyException Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * fix matchesException func Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * add codegen-all files Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * fix after review Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * remove variable validation from PolicyException Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * fix after review Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * add kuttl tests Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * remove ValidateVariables() from tests Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * fix errors Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * remove check-variables kuttl test Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * fix after review Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> * add sleep step to kuttl Signed-off-by: Rakshit Gondwal <98955085+rakshitgondwal@users.noreply.github.com> * miinor fix Signed-off-by: Rakshit Gondwal <98955085+rakshitgondwal@users.noreply.github.com> * add readme for kuttl test Signed-off-by: Rakshit Gondwal <98955085+rakshitgondwal@users.noreply.github.com> --------- Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com> Signed-off-by: Rakshit Gondwal <98955085+rakshitgondwal@users.noreply.github.com> Signed-off-by: Jim Bugwadia <jim@nirmata.com> Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com> Co-authored-by: Jim Bugwadia <jim@nirmata.com>
2023-10-24 16:15:52 +05:30
"github.com/kyverno/kyverno/pkg/utils/conditions"
controllerutils "github.com/kyverno/kyverno/pkg/utils/controller"
"github.com/kyverno/kyverno/pkg/utils/match"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.uber.org/multierr"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/util/workqueue"
)
type controller struct {
// clients
client dclient.Interface
kyvernoClient versioned.Interface
// listers
cpolLister kyvernov2listers.ClusterCleanupPolicyLister
polLister kyvernov2listers.CleanupPolicyLister
nsLister corev1listers.NamespaceLister
// queue
queue workqueue.TypedRateLimitingInterface[any]
enqueue controllerutils.EnqueueFuncT[kyvernov2.CleanupPolicyInterface]
// config
configuration config.Configuration
cmResolver engineapi.ConfigmapResolver
eventGen event.Interface
jp jmespath.Interface
metrics cleanupMetrics
feat: enhance global context (#9710) * feat(globalcontext): add event handling Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): handle cache sync error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): ensure api is called during init Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * design(events): decouple events from policies a bit Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): use status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): make status optional Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): status update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): codegen Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): delete yaml annotations Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): fix status in tests Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcotext): update enqueue func Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): rbac Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): retry logic Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): unknown api call in test Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * bump Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix: set unique name for each testing resource Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: update readme Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: log msg Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: add delays Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: delay gctce creation Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: check Kyverno status Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: update chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: revert chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * test(globalcontext): print actual status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add necessary delays and check status before applying Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * test(globalcontext): long refreshInterval Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: log success Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print informer data Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): use client instead of informer Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print status after update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print ResourceVersion Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: remove gcecontroller from other controllers Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): update status only once Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore: remove excess logs Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add store to cleanup controller Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> --------- Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-02-23 12:34:04 +02:00
gctxStore loaders.Store
}
type cleanupMetrics struct {
deletedObjectsTotal metric.Int64Counter
cleanupFailuresTotal metric.Int64Counter
}
const (
maxRetries = 10
Workers = 3
ControllerName = "cleanup-controller"
)
func NewController(
client dclient.Interface,
kyvernoClient versioned.Interface,
cpolInformer kyvernov2informers.ClusterCleanupPolicyInformer,
polInformer kyvernov2informers.CleanupPolicyInformer,
nsLister corev1listers.NamespaceLister,
configuration config.Configuration,
cmResolver engineapi.ConfigmapResolver,
jp jmespath.Interface,
eventGen event.Interface,
feat: enhance global context (#9710) * feat(globalcontext): add event handling Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): handle cache sync error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): ensure api is called during init Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * design(events): decouple events from policies a bit Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): use status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): make status optional Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): status update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): codegen Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): delete yaml annotations Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): fix status in tests Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcotext): update enqueue func Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): rbac Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): retry logic Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): unknown api call in test Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * bump Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix: set unique name for each testing resource Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: update readme Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: log msg Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: add delays Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: delay gctce creation Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: check Kyverno status Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: update chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: revert chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * test(globalcontext): print actual status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add necessary delays and check status before applying Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * test(globalcontext): long refreshInterval Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: log success Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print informer data Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): use client instead of informer Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print status after update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print ResourceVersion Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: remove gcecontroller from other controllers Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): update status only once Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore: remove excess logs Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add store to cleanup controller Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> --------- Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-02-23 12:34:04 +02:00
gctxStore loaders.Store,
) controllers.Controller {
queue := workqueue.NewTypedRateLimitingQueueWithConfig(
workqueue.DefaultTypedControllerRateLimiter[any](),
workqueue.TypedRateLimitingQueueConfig[any]{Name: ControllerName},
)
keyFunc := controllerutils.MetaNamespaceKeyT[kyvernov2.CleanupPolicyInterface]
baseEnqueueFunc := controllerutils.LogError(logger, controllerutils.Parse(keyFunc, controllerutils.Queue(queue)))
enqueueFunc := func(logger logr.Logger, operation, kind string) controllerutils.EnqueueFuncT[kyvernov2.CleanupPolicyInterface] {
logger = logger.WithValues("kind", kind, "operation", operation)
return func(obj kyvernov2.CleanupPolicyInterface) error {
logger := logger.WithValues("name", obj.GetName())
if obj.GetNamespace() != "" {
logger = logger.WithValues("namespace", obj.GetNamespace())
}
logger.V(2).Info(operation)
if err := baseEnqueueFunc(obj); err != nil {
logger.Error(err, "failed to enqueue object", "obj", obj)
return err
}
return nil
}
}
c := &controller{
client: client,
kyvernoClient: kyvernoClient,
cpolLister: cpolInformer.Lister(),
polLister: polInformer.Lister(),
nsLister: nsLister,
queue: queue,
enqueue: baseEnqueueFunc,
configuration: configuration,
cmResolver: cmResolver,
eventGen: eventGen,
metrics: newCleanupMetrics(logger),
jp: jp,
feat: enhance global context (#9710) * feat(globalcontext): add event handling Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): handle cache sync error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): ensure api is called during init Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * design(events): decouple events from policies a bit Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): use status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): make status optional Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): status update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): codegen Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): delete yaml annotations Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): fix status in tests Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcotext): update enqueue func Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): rbac Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): retry logic Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): unknown api call in test Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * bump Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix: set unique name for each testing resource Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: update readme Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: log msg Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: add delays Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: delay gctce creation Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: check Kyverno status Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: update chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: revert chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * test(globalcontext): print actual status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add necessary delays and check status before applying Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * test(globalcontext): long refreshInterval Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: log success Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print informer data Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): use client instead of informer Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print status after update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print ResourceVersion Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: remove gcecontroller from other controllers Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): update status only once Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore: remove excess logs Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add store to cleanup controller Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> --------- Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-02-23 12:34:04 +02:00
gctxStore: gctxStore,
}
if _, err := controllerutils.AddEventHandlersT(
cpolInformer.Informer(),
controllerutils.AddFuncT(logger, enqueueFunc(logger, "added", "ClusterCleanupPolicy")),
controllerutils.UpdateFuncT(logger, enqueueFunc(logger, "updated", "ClusterCleanupPolicy")),
controllerutils.DeleteFuncT(logger, enqueueFunc(logger, "deleted", "ClusterCleanupPolicy")),
); err != nil {
logger.Error(err, "failed to register event handlers")
}
if _, err := controllerutils.AddEventHandlersT(
polInformer.Informer(),
controllerutils.AddFuncT(logger, enqueueFunc(logger, "added", "CleanupPolicy")),
controllerutils.UpdateFuncT(logger, enqueueFunc(logger, "updated", "CleanupPolicy")),
controllerutils.DeleteFuncT(logger, enqueueFunc(logger, "deleted", "CleanupPolicy")),
); err != nil {
logger.Error(err, "failed to register event handlers")
}
return c
}
func newCleanupMetrics(logger logr.Logger) cleanupMetrics {
meter := otel.GetMeterProvider().Meter(metrics.MeterName)
deletedObjectsTotal, err := meter.Int64Counter(
"kyverno_cleanup_controller_deletedobjects",
metric.WithDescription("can be used to track number of deleted objects."),
)
if err != nil {
logger.Error(err, "Failed to create instrument, cleanup_controller_deletedobjects_total")
}
cleanupFailuresTotal, err := meter.Int64Counter(
"kyverno_cleanup_controller_errors",
metric.WithDescription("can be used to track number of cleanup failures."),
)
if err != nil {
logger.Error(err, "Failed to create instrument, cleanup_controller_errors_total")
}
return cleanupMetrics{
deletedObjectsTotal: deletedObjectsTotal,
cleanupFailuresTotal: cleanupFailuresTotal,
}
}
func (c *controller) Run(ctx context.Context, workers int) {
controllerutils.Run(ctx, logger.V(3), ControllerName, time.Second, c.queue, workers, maxRetries, c.reconcile)
}
func (c *controller) getPolicy(namespace, name string) (kyvernov2.CleanupPolicyInterface, error) {
if namespace == "" {
cpolicy, err := c.cpolLister.Get(name)
if err != nil {
return nil, err
}
return cpolicy, nil
} else {
policy, err := c.polLister.CleanupPolicies(namespace).Get(name)
if err != nil {
return nil, err
}
return policy, nil
}
}
func (c *controller) cleanup(ctx context.Context, logger logr.Logger, policy kyvernov2.CleanupPolicyInterface) error {
spec := policy.GetSpec()
kinds := sets.New(spec.MatchResources.GetKinds()...)
debug := logger.V(4)
var errs []error
Introduced the DeletionPropagationPolicy field in CleanupPolicy and C… (#11368) * Introduced the DeletionPropagationPolicy field in CleanupPolicy and ClusterCleanupPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Add DeletionPropagation field to API versions and implement handling in controller.go for improved cleanup functionality Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * removed the type for DeletionPrpagationPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Add DeletionPropagationPolicy to CleanupPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Updated DeletionPropagationPolicy in different api versions Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Removed the string type declaration from the DeletionPropagationPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Reverted the changes Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Added the DeletionPropagation to the cleanup/controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed minor bugs Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed the verify-codegen error Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Revert "Fixed the verify-codegen error" This reverts commit 05428bd99b187b93086dc403e674f06f8eeb5a40. Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Changed the field's type string to pointer Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixing the linter issue Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * changing the v1 to metav1 in the controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Resolved linter problem Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: codegen Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * Refactor DeletionPropagationPolicy to use a pointer type Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Refactor String type to pointer in controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fixing Linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Make DeletionPropagationPolicy optional in validation Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: Update validation for DeletionPropagationPolicy in CleanupPolicySpec Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Refactored deletion policy handling Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Resolved linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Updated logic to set deletion options based on user-provided deletion policy. Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Removed default deletion policy assignment in the deletion logic Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fix: removed default deletion policy in the deletion logic Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixing minor issues Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fix: Linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: propagation policy Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * codegen Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-10-22 16:34:01 +05:30
deleteOptions := metav1.DeleteOptions{
PropagationPolicy: spec.DeletionPropagationPolicy,
}
enginectx := enginecontext.NewContext(c.jp)
feat: enhance global context (#9710) * feat(globalcontext): add event handling Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): handle cache sync error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): ensure api is called during init Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * design(events): decouple events from policies a bit Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * feat(globalcontext): use status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): make status optional Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): status update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): codegen Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): delete yaml annotations Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): fix status in tests Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcotext): update enqueue func Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): error Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): rbac Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore(globalcontext): retry logic Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): unknown api call in test Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * bump Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix: set unique name for each testing resource Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: update readme Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: log msg Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: add delays Signed-off-by: ShutingZhao <shuting@nirmata.com> * fix: delay gctce creation Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: check Kyverno status Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: update chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * debug: revert chainsaw config Signed-off-by: ShutingZhao <shuting@nirmata.com> * test(globalcontext): print actual status Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add necessary delays and check status before applying Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * test(globalcontext): long refreshInterval Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: log success Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print informer data Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): use client instead of informer Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print status after update Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: print ResourceVersion Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * debug: remove gcecontroller from other controllers Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): update status only once Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * chore: remove excess logs Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> * fix(globalcontext): add store to cleanup controller Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> --------- Signed-off-by: Khaled Emara <khaled.emara@nirmata.com> Signed-off-by: ShutingZhao <shuting@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-02-23 12:34:04 +02:00
ctxFactory := factories.DefaultContextLoaderFactory(c.cmResolver, factories.WithGlobalContextStore(c.gctxStore))
loader := ctxFactory(nil, kyvernov1.Rule{})
if err := loader.Load(
ctx,
c.jp,
c.client,
nil,
spec.Context,
enginectx,
); err != nil {
return err
}
for kind := range kinds {
commonLabels := []attribute.KeyValue{
attribute.String("policy_type", policy.GetKind()),
attribute.String("policy_namespace", policy.GetNamespace()),
attribute.String("policy_name", policy.GetName()),
attribute.String("resource_kind", kind),
}
debug := debug.WithValues("kind", kind)
debug.Info("processing...")
list, err := c.client.ListResource(ctx, "", kind, policy.GetNamespace(), nil)
if err != nil {
debug.Error(err, "failed to list resources")
errs = append(errs, err)
if c.metrics.cleanupFailuresTotal != nil {
c.metrics.cleanupFailuresTotal.Add(ctx, 1, metric.WithAttributes(commonLabels...))
}
} else {
for i := range list.Items {
resource := list.Items[i]
namespace := resource.GetNamespace()
name := resource.GetName()
debug := debug.WithValues("name", name, "namespace", namespace)
// check if the resource is owned by Kyverno
if controllerutils.IsManagedByKyverno(&resource) && toggle.FromContext(ctx).ProtectManagedResources() {
continue
}
var nsLabels map[string]string
if namespace != "" {
ns, err := c.nsLister.Get(namespace)
if err != nil {
debug.Error(err, "failed to get namespace labels")
errs = append(errs, err)
}
nsLabels = ns.GetLabels()
}
// match namespaces
if err := match.CheckNamespace(policy.GetNamespace(), resource); err != nil {
debug.Info("resource namespace didn't match policy namespace", "result", err)
}
// match resource with match/exclude clause
matched := match.CheckMatchesResources(
resource,
spec.MatchResources,
nsLabels,
// TODO(eddycharly): we don't have user info here, we should check that
// we don't have user conditions in the policy rule
kyvernov2.RequestInfo{},
resource.GroupVersionKind(),
"",
)
if matched != nil {
debug.Info("resource/match didn't match", "result", matched)
continue
}
if spec.ExcludeResources != nil {
excluded := match.CheckMatchesResources(
resource,
*spec.ExcludeResources,
nsLabels,
// TODO(eddycharly): we don't have user info here, we should check that
// we don't have user conditions in the policy rule
kyvernov2.RequestInfo{},
resource.GroupVersionKind(),
"",
)
if excluded == nil {
debug.Info("resource/exclude matched")
continue
} else {
debug.Info("resource/exclude didn't match", "result", excluded)
}
}
// check conditions
if spec.Conditions != nil {
enginectx.Reset()
if err := enginectx.SetTargetResource(resource.Object); err != nil {
debug.Error(err, "failed to add resource in context")
errs = append(errs, err)
continue
}
if err := enginectx.AddNamespace(resource.GetNamespace()); err != nil {
debug.Error(err, "failed to add namespace in context")
errs = append(errs, err)
continue
}
if err := enginectx.AddImageInfos(&resource, c.configuration); err != nil {
debug.Error(err, "failed to add image infos in context")
errs = append(errs, err)
continue
}
passed, err := conditions.CheckAnyAllConditions(logger, enginectx, *spec.Conditions)
if err != nil {
debug.Error(err, "failed to check condition")
errs = append(errs, err)
continue
}
if !passed {
debug.Info("conditions did not pass")
continue
}
}
var labels []attribute.KeyValue
labels = append(labels, commonLabels...)
labels = append(labels, attribute.String("resource_namespace", namespace))
Introduced the DeletionPropagationPolicy field in CleanupPolicy and C… (#11368) * Introduced the DeletionPropagationPolicy field in CleanupPolicy and ClusterCleanupPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Add DeletionPropagation field to API versions and implement handling in controller.go for improved cleanup functionality Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * removed the type for DeletionPrpagationPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Add DeletionPropagationPolicy to CleanupPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Updated DeletionPropagationPolicy in different api versions Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Removed the string type declaration from the DeletionPropagationPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Reverted the changes Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Added the DeletionPropagation to the cleanup/controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed minor bugs Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed the verify-codegen error Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Revert "Fixed the verify-codegen error" This reverts commit 05428bd99b187b93086dc403e674f06f8eeb5a40. Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Changed the field's type string to pointer Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixing the linter issue Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * changing the v1 to metav1 in the controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Resolved linter problem Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: codegen Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * Refactor DeletionPropagationPolicy to use a pointer type Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Refactor String type to pointer in controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fixing Linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Make DeletionPropagationPolicy optional in validation Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: Update validation for DeletionPropagationPolicy in CleanupPolicySpec Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Refactored deletion policy handling Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Resolved linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Updated logic to set deletion options based on user-provided deletion policy. Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Removed default deletion policy assignment in the deletion logic Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fix: removed default deletion policy in the deletion logic Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixing minor issues Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fix: Linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: propagation policy Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * codegen Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-10-22 16:34:01 +05:30
if deleteOptions.PropagationPolicy != nil {
labels = append(labels, attribute.String("deletion_policy", string(*deleteOptions.PropagationPolicy)))
}
logger.WithValues("name", name, "namespace", namespace).Info("resource matched, it will be deleted...")
if err := c.client.DeleteResource(ctx, resource.GetAPIVersion(), resource.GetKind(), namespace, name, false, deleteOptions); err != nil {
if c.metrics.cleanupFailuresTotal != nil {
c.metrics.cleanupFailuresTotal.Add(ctx, 1, metric.WithAttributes(labels...))
}
debug.Error(err, "failed to delete resource")
errs = append(errs, err)
e := event.NewCleanupPolicyEvent(policy, resource, err)
c.eventGen.Add(e)
} else {
if c.metrics.deletedObjectsTotal != nil {
c.metrics.deletedObjectsTotal.Add(ctx, 1, metric.WithAttributes(labels...))
}
Introduced the DeletionPropagationPolicy field in CleanupPolicy and C… (#11368) * Introduced the DeletionPropagationPolicy field in CleanupPolicy and ClusterCleanupPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Add DeletionPropagation field to API versions and implement handling in controller.go for improved cleanup functionality Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * removed the type for DeletionPrpagationPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Add DeletionPropagationPolicy to CleanupPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Updated DeletionPropagationPolicy in different api versions Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Removed the string type declaration from the DeletionPropagationPolicy Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Reverted the changes Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Added the DeletionPropagation to the cleanup/controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed minor bugs Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed the verify-codegen error Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Revert "Fixed the verify-codegen error" This reverts commit 05428bd99b187b93086dc403e674f06f8eeb5a40. Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Changed the field's type string to pointer Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixing the linter issue Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * changing the v1 to metav1 in the controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Resolved linter problem Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: codegen Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * Refactor DeletionPropagationPolicy to use a pointer type Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixed linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Refactor String type to pointer in controller.go Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fixing Linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Make DeletionPropagationPolicy optional in validation Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: Update validation for DeletionPropagationPolicy in CleanupPolicySpec Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Refactored deletion policy handling Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Resolved linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Updated logic to set deletion options based on user-provided deletion policy. Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Removed default deletion policy assignment in the deletion logic Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fix: removed default deletion policy in the deletion logic Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fixing minor issues Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * Fix: Linter Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> * fix: propagation policy Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * codegen Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: ShivamJha2436 <shivamkumar87148@gmail.com> Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2024-10-22 16:34:01 +05:30
debug.Info("resource deleted")
e := event.NewCleanupPolicyEvent(policy, resource, nil)
c.eventGen.Add(e)
}
}
}
}
return multierr.Combine(errs...)
}
func (c *controller) reconcile(ctx context.Context, logger logr.Logger, key, namespace, name string) error {
policy, err := c.getPolicy(namespace, name)
if err != nil {
if apierrors.IsNotFound(err) {
return nil
}
logger.Error(err, "unable to get the policy from policy informer")
return err
}
var nextExecutionTime *time.Time
executionTime, err := policy.GetExecutionTime()
if err != nil {
logger.Error(err, "failed to get the policy execution time")
return err
}
// In case it is the time to do the cleanup process
if time.Now().After(*executionTime) {
err := c.cleanup(ctx, logger, policy)
if err != nil {
return err
}
if err := c.updateCleanupPolicyStatus(ctx, policy, namespace, *executionTime); err != nil {
logger.Error(err, "failed to update the cleanup policy status")
return err
}
nextExecutionTime, err = policy.GetNextExecutionTime(*executionTime)
if err != nil {
logger.Error(err, "failed to get the policy next execution time")
return err
}
} else {
nextExecutionTime = executionTime
}
// calculate the remaining time until deletion.
timeRemaining := time.Until(*nextExecutionTime)
// add the item back to the queue after the remaining time.
c.queue.AddAfter(key, timeRemaining)
return nil
}
func (c *controller) updateCleanupPolicyStatus(ctx context.Context, policy kyvernov2.CleanupPolicyInterface, namespace string, time time.Time) error {
switch obj := policy.(type) {
case *kyvernov2.ClusterCleanupPolicy:
latest := obj.DeepCopy()
latest.Status.LastExecutionTime = metav1.NewTime(time)
new, err := c.kyvernoClient.KyvernoV2().ClusterCleanupPolicies().UpdateStatus(ctx, latest, metav1.UpdateOptions{})
if err != nil {
return err
}
logging.V(3).Info("updated cluster cleanup policy status", "name", policy.GetName(), "status", new.Status)
case *kyvernov2.CleanupPolicy:
latest := obj.DeepCopy()
latest.Status.LastExecutionTime = metav1.NewTime(time)
new, err := c.kyvernoClient.KyvernoV2().CleanupPolicies(namespace).UpdateStatus(ctx, latest, metav1.UpdateOptions{})
if err != nil {
return err
}
logging.V(3).Info("updated cleanup policy status", "name", policy.GetName(), "namespace", policy.GetNamespace(), "status", new.Status)
}
return nil
}