Skip to content

Commit

Permalink
Sync Cache configuration in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadd-b committed Feb 2, 2025
1 parent 8a141c5 commit f93a507
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 10 deletions.
15 changes: 15 additions & 0 deletions bootstrap/kubeadm/internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ import (
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/internal/test/envtest"
)

Expand All @@ -48,9 +52,20 @@ func TestMain(m *testing.M) {
panic(fmt.Sprintf("unable to create secretCachingClient: %v", err))
}
}
req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
ManagerUncachedObjs: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
Expand Down
19 changes: 18 additions & 1 deletion controllers/clustercache/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ import (
"os"
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

Check failure on line 26 in controllers/clustercache/suite_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

Check failure on line 30 in controllers/clustercache/suite_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
"sigs.k8s.io/cluster-api/internal/test/envtest"
)
Expand All @@ -31,8 +37,19 @@ var (
)

func TestMain(m *testing.M) {
req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)
os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
}))
}
19 changes: 18 additions & 1 deletion controllers/remote/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import (
"testing"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

Check failure on line 27 in controllers/remote/suite_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

Check failure on line 31 in controllers/remote/suite_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gci)
"sigs.k8s.io/cluster-api/internal/test/envtest"
)
Expand All @@ -36,8 +42,19 @@ var (
)

func TestMain(m *testing.M) {
req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)
os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
}))
}
16 changes: 16 additions & 0 deletions controlplane/kubeadm/internal/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ import (
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/internal/test/envtest"
)

Expand All @@ -48,8 +52,20 @@ func TestMain(m *testing.M) {
panic(fmt.Sprintf("unable to create secretCachingClient: %v", err))
}
}
req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
ManagerUncachedObjs: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
Expand Down
18 changes: 17 additions & 1 deletion exp/internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import (
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/api/v1beta1/index"
"sigs.k8s.io/cluster-api/controllers/clustercache"
"sigs.k8s.io/cluster-api/controllers/remote"
Expand Down Expand Up @@ -76,8 +80,20 @@ func TestMain(m *testing.M) {
}
}

req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
17 changes: 16 additions & 1 deletion internal/controllers/cluster/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/selection"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

Expand Down Expand Up @@ -110,8 +113,20 @@ func TestMain(m *testing.M) {
SetDefaultEventuallyPollingInterval(100 * time.Millisecond)
SetDefaultEventuallyTimeout(timeout)

req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
18 changes: 17 additions & 1 deletion internal/controllers/clusterclass/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import (
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/selection"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/component-base/featuregate"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

Expand Down Expand Up @@ -72,8 +75,21 @@ func TestMain(m *testing.M) {
}
SetDefaultEventuallyPollingInterval(100 * time.Millisecond)
SetDefaultEventuallyTimeout(30 * time.Second)

req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
ManagerUncachedObjs: []client.Object{},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
Expand Down
17 changes: 16 additions & 1 deletion internal/controllers/machine/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/selection"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

Expand Down Expand Up @@ -102,8 +105,20 @@ func TestMain(m *testing.M) {
SetDefaultEventuallyPollingInterval(100 * time.Millisecond)
SetDefaultEventuallyTimeout(timeout)

req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
17 changes: 16 additions & 1 deletion internal/controllers/machinedeployment/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/uuid"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

Expand Down Expand Up @@ -116,8 +119,20 @@ func TestMain(m *testing.M) {
SetDefaultEventuallyPollingInterval(100 * time.Millisecond)
SetDefaultEventuallyTimeout(timeout)

req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
18 changes: 17 additions & 1 deletion internal/controllers/machinehealthcheck/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ import (

. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/api/v1beta1/index"
"sigs.k8s.io/cluster-api/controllers/clustercache"
"sigs.k8s.io/cluster-api/controllers/remote"
Expand Down Expand Up @@ -115,8 +119,20 @@ func TestMain(m *testing.M) {
SetDefaultEventuallyPollingInterval(100 * time.Millisecond)
SetDefaultEventuallyTimeout(timeout)

req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
17 changes: 16 additions & 1 deletion internal/controllers/machineset/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/util/uuid"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

Expand Down Expand Up @@ -109,8 +112,20 @@ func TestMain(m *testing.M) {
SetDefaultEventuallyPollingInterval(100 * time.Millisecond)
SetDefaultEventuallyTimeout(timeout)

req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
M: m,
M: m,
ManagerCacheOptions: cache.Options{
ByObject: map[client.Object]cache.ByObject{
// Only cache Secrets with the cluster name label.
// This is similar to the real world.
&corev1.Secret{}: {
Label: clusterSecretCacheSelector,
},
},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
Loading

0 comments on commit f93a507

Please sign in to comment.