From fcde68396f462a4e28253a8fcb387972e5ff085d Mon Sep 17 00:00:00 2001 From: Avinash Patnala Date: Wed, 23 Oct 2024 18:46:14 +0000 Subject: [PATCH] update test cases Signed-off-by: Avinash Patnala --- .../constrainttemplate/constrainttemplate_controller.go | 2 -- .../constrainttemplate_controller_test.go | 9 +++++---- pkg/drivers/k8scel/transform/vap_util.go | 7 +++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/controller/constrainttemplate/constrainttemplate_controller.go b/pkg/controller/constrainttemplate/constrainttemplate_controller.go index 45a530cf66b..380e4a63c84 100644 --- a/pkg/controller/constrainttemplate/constrainttemplate_controller.go +++ b/pkg/controller/constrainttemplate/constrainttemplate_controller.go @@ -22,7 +22,6 @@ import ( "reflect" "time" - "github.com/go-logr/logr" "github.com/open-policy-agent/frameworks/constraint/pkg/apis/templates/v1beta1" constraintclient "github.com/open-policy-agent/frameworks/constraint/pkg/client" "github.com/open-policy-agent/frameworks/constraint/pkg/core/templates" @@ -70,7 +69,6 @@ var ( discoveryErr *apiutil.ErrResourceDiscoveryFailed ) -var g *logr.Logger var gvkConstraintTemplate = schema.GroupVersionKind{ Group: v1beta1.SchemeGroupVersion.Group, Version: v1beta1.SchemeGroupVersion.Version, diff --git a/pkg/controller/constrainttemplate/constrainttemplate_controller_test.go b/pkg/controller/constrainttemplate/constrainttemplate_controller_test.go index b1b282c13ed..895043b253f 100644 --- a/pkg/controller/constrainttemplate/constrainttemplate_controller_test.go +++ b/pkg/controller/constrainttemplate/constrainttemplate_controller_test.go @@ -32,6 +32,7 @@ import ( "github.com/open-policy-agent/gatekeeper/v3/pkg/controller/constraint" "github.com/open-policy-agent/gatekeeper/v3/pkg/drivers/k8scel" celSchema "github.com/open-policy-agent/gatekeeper/v3/pkg/drivers/k8scel/schema" + "github.com/open-policy-agent/gatekeeper/v3/pkg/drivers/k8scel/transform" "github.com/open-policy-agent/gatekeeper/v3/pkg/fakes" "github.com/open-policy-agent/gatekeeper/v3/pkg/readiness" "github.com/open-policy-agent/gatekeeper/v3/pkg/target" @@ -271,8 +272,8 @@ func TestReconcile(t *testing.T) { ctx := context.Background() testutils.StartManager(ctx, t, mgr) - constraint.VapAPIEnabled = ptr.To[bool](true) - constraint.GroupVersion = &admissionregistrationv1beta1.SchemeGroupVersion + transform.VapAPIEnabled = ptr.To[bool](true) + transform.GroupVersion = &admissionregistrationv1beta1.SchemeGroupVersion t.Run("CRD Gets Created", func(t *testing.T) { suffix := "CRDGetsCreated" @@ -696,7 +697,7 @@ func TestReconcile(t *testing.T) { suffix := "VapShouldBeCreatedV1" logger.Info("Running test: Vap should be created with v1") - constraint.GroupVersion = &admissionregistrationv1.SchemeGroupVersion + transform.GroupVersion = &admissionregistrationv1.SchemeGroupVersion constraintTemplate := makeReconcileConstraintTemplateForVap(suffix, ptr.To[bool](true)) t.Cleanup(testutils.DeleteObjectAndConfirm(ctx, t, c, expectedCRD(suffix))) testutils.CreateThenCleanup(ctx, t, c, constraintTemplate) @@ -721,7 +722,7 @@ func TestReconcile(t *testing.T) { suffix := "VapBindingShouldBeCreatedV1" logger.Info("Running test: VapBinding should be created with v1") constraint.DefaultGenerateVAPB = ptr.To[bool](true) - constraint.GroupVersion = &admissionregistrationv1.SchemeGroupVersion + transform.GroupVersion = &admissionregistrationv1.SchemeGroupVersion constraintTemplate := makeReconcileConstraintTemplateForVap(suffix, ptr.To[bool](true)) cstr := newDenyAllCstr(suffix) t.Cleanup(testutils.DeleteObjectAndConfirm(ctx, t, c, expectedCRD(suffix))) diff --git a/pkg/drivers/k8scel/transform/vap_util.go b/pkg/drivers/k8scel/transform/vap_util.go index 2f9a088c659..5907c236f9d 100644 --- a/pkg/drivers/k8scel/transform/vap_util.go +++ b/pkg/drivers/k8scel/transform/vap_util.go @@ -5,13 +5,12 @@ import ( "sync" "github.com/go-logr/logr" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/kubernetes" - "sigs.k8s.io/controller-runtime/pkg/client" - admissionregistrationv1 "k8s.io/api/admissionregistration/v1" admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/client-go/kubernetes" rest "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" ) var vapMux sync.RWMutex