From 67b6251052a743a584463d4fe0236ff581385d47 Mon Sep 17 00:00:00 2001 From: Sedef Date: Tue, 8 Jun 2021 00:10:55 -0700 Subject: [PATCH] Make envtest to accept list of objects to be read from live client --- .../clusterresourceset_controller_test.go | 2 +- exp/addons/controllers/suite_test.go | 5 ++++- internal/envtest/environment.go | 16 +++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/exp/addons/controllers/clusterresourceset_controller_test.go b/exp/addons/controllers/clusterresourceset_controller_test.go index 46c7951abe07..540863cd0ac0 100644 --- a/exp/addons/controllers/clusterresourceset_controller_test.go +++ b/exp/addons/controllers/clusterresourceset_controller_test.go @@ -34,7 +34,7 @@ import ( ) const ( - timeout = time.Second * 5 + timeout = time.Second * 15 defaultNamespaceName = "default" ) diff --git a/exp/addons/controllers/suite_test.go b/exp/addons/controllers/suite_test.go index 75545fb2d333..976ce2acdacd 100644 --- a/exp/addons/controllers/suite_test.go +++ b/exp/addons/controllers/suite_test.go @@ -21,9 +21,12 @@ import ( "os" "testing" + corev1 "k8s.io/api/core/v1" "sigs.k8s.io/cluster-api/controllers/remote" + "sigs.k8s.io/cluster-api/exp/addons/api/v1alpha4" "sigs.k8s.io/cluster-api/internal/envtest" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/log" // +kubebuilder:scaffold:imports @@ -36,7 +39,7 @@ var ( func TestMain(m *testing.M) { fmt.Println("Creating new test environment") - env = envtest.New() + env = envtest.New([]client.Object{&corev1.ConfigMap{}, &corev1.Secret{}, &v1alpha4.ClusterResourceSetBinding{}}...) trckr, err := remote.NewClusterCacheTracker(log.NullLogger{}, env.Manager) if err != nil { diff --git a/internal/envtest/environment.go b/internal/envtest/environment.go index a7c95ee108d1..929fd2a901f3 100644 --- a/internal/envtest/environment.go +++ b/internal/envtest/environment.go @@ -103,7 +103,7 @@ type Environment struct { // // This function should be called only once for each package you're running tests within, // usually the environment is initialized in a suite_test.go file within a `BeforeSuite` ginkgo block. -func New() *Environment { +func New(uncachedObjs ...client.Object) *Environment { // Get the root of the current file to use in CRD paths. _, filename, _, _ := goruntime.Caller(0) //nolint root := path.Join(path.Dir(filename), "..", "..") @@ -134,11 +134,17 @@ func New() *Environment { panic(err) } + objs := []client.Object{} + if len(uncachedObjs) > 0 { + objs = append(objs, uncachedObjs...) + } + options := manager.Options{ - Scheme: scheme.Scheme, - MetricsBindAddress: "0", - CertDir: env.WebhookInstallOptions.LocalServingCertDir, - Port: env.WebhookInstallOptions.LocalServingPort, + Scheme: scheme.Scheme, + MetricsBindAddress: "0", + CertDir: env.WebhookInstallOptions.LocalServingCertDir, + Port: env.WebhookInstallOptions.LocalServingPort, + ClientDisableCacheFor: objs, } mgr, err := ctrl.NewManager(env.Config, options)