Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 +20,14 @@ import (
"os"
"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 @@ -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 },
}))
}
23 changes: 22 additions & 1 deletion controllers/remote/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ import (
"testing"
"time"

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 @@ -36,8 +42,23 @@ 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,
},
},
},
ManagerUncachedObjs: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
},
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
22 changes: 21 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,24 @@ 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,
},
},
},
ManagerUncachedObjs: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
21 changes: 21 additions & 0 deletions exp/runtime/internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ import (
"os"
"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/api/v1beta1/index"
"sigs.k8s.io/cluster-api/internal/test/envtest"
)
Expand All @@ -39,8 +45,23 @@ func TestMain(m *testing.M) {
panic(fmt.Sprintf("unable to setup index: %v", err))
}
}
req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
clusterSecretCacheSelector := labels.NewSelector().Add(*req)

os.Exit(envtest.Run(ctx, envtest.RunInput{
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{},
},
M: m,
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
Expand Down
21 changes: 20 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,24 @@ 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,
},
},
},
ManagerUncachedObjs: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
29 changes: 24 additions & 5 deletions 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,12 +75,28 @@ 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,
ManagerUncachedObjs: []client.Object{},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
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{},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
}))
}

Expand Down
21 changes: 20 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,24 @@ 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,
},
},
},
ManagerUncachedObjs: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
21 changes: 20 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,24 @@ 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,
},
},
},
ManagerUncachedObjs: []client.Object{
&corev1.ConfigMap{},
&corev1.Secret{},
},
SetupEnv: func(e *envtest.Environment) { env = e },
SetupIndexes: setupIndexes,
SetupReconcilers: setupReconcilers,
Expand Down
Loading