diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 7246f0406..44306fcf5 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -30,6 +30,7 @@ import ( mp "github.com/aquasecurity/trivy/pkg/policy" "github.com/bluele/gcache" corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" @@ -73,6 +74,23 @@ func Start(ctx context.Context, buildInfo trivyoperator.BuildInfo, operatorConfi }, }, }, + Cache: cache.Options{ + DefaultTransform: func(obj interface{}) (interface{}, error) { + obj, err := cache.TransformStripManagedFields()(obj) + if err != nil { + return obj, err + } + if metaObj, ok := obj.(metav1.ObjectMetaAccessor); ok { + annotations := metaObj.GetObjectMeta().GetAnnotations() + if annotations != nil { + delete(annotations, "kubectl.kubernetes.io/last-applied-configuration") + metaObj.GetObjectMeta().SetAnnotations(annotations) + } + } + + return obj, nil + }, + }, Controller: controllerconfig.Controller{SkipNameValidation: &skipNameValidation}, }