Skip to content

Commit fd16439

Browse files
committed
update
1 parent 85a6f24 commit fd16439

File tree

6 files changed

+44
-17
lines changed

6 files changed

+44
-17
lines changed

exp/addons/internal/controllers/clusterresourceset_controller_test.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ metadata:
110110
g.Expect(env.CreateAndWait(ctx, testCluster)).To(Succeed())
111111
t.Log("Creating the remote Cluster kubeconfig")
112112
g.Expect(env.CreateKubeconfigSecret(ctx, testCluster)).To(Succeed())
113-
_, err = clusterCache.GetClient(ctx, client.ObjectKeyFromObject(testCluster))
114-
g.Expect(err).ToNot(HaveOccurred())
113+
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
114+
patch := client.MergeFrom(testCluster.DeepCopy())
115+
testCluster.Status.InfrastructureReady = true
116+
g.Expect(env.Status().Patch(ctx, testCluster, patch)).To(Succeed())
117+
118+
g.Eventually(func(g Gomega) {
119+
_, err = clusterCache.GetClient(ctx, client.ObjectKeyFromObject(testCluster))
120+
g.Expect(err).ToNot(HaveOccurred())
121+
}, 1*time.Minute, 5*time.Second).Should(Succeed())
115122

116123
createConfigMapAndSecret(g, ns.Name, configmapName, secretName)
117124
return ns

exp/internal/controllers/suite_test.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/controller"
2727

2828
"sigs.k8s.io/cluster-api/api/v1beta1/index"
29+
"sigs.k8s.io/cluster-api/controllers/clustercache"
30+
"sigs.k8s.io/cluster-api/controllers/remote"
2931
"sigs.k8s.io/cluster-api/internal/test/envtest"
3032
)
3133

@@ -42,12 +44,24 @@ func TestMain(m *testing.M) {
4244
}
4345

4446
setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
45-
machinePoolReconciler := MachinePoolReconciler{
46-
Client: mgr.GetClient(),
47-
recorder: mgr.GetEventRecorderFor("machinepool-controller"),
48-
}
49-
err := machinePoolReconciler.SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1})
47+
clusterCache, err := clustercache.SetupWithManager(ctx, mgr, clustercache.Options{
48+
SecretClient: mgr.GetClient(),
49+
Cache: clustercache.CacheOptions{
50+
Indexes: []clustercache.CacheOptionsIndex{clustercache.NodeProviderIDIndex},
51+
},
52+
Client: clustercache.ClientOptions{
53+
UserAgent: remote.DefaultClusterAPIUserAgent("test-controller-manager"),
54+
},
55+
}, controller.Options{MaxConcurrentReconciles: 10})
5056
if err != nil {
57+
panic(fmt.Sprintf("Failed to create new cluster cache tracker: %v", err))
58+
}
59+
60+
if err := (&MachinePoolReconciler{
61+
Client: mgr.GetClient(),
62+
ClusterCache: clusterCache,
63+
recorder: mgr.GetEventRecorderFor("machinepool-controller"),
64+
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
5165
panic(fmt.Sprintf("Failed to set up machine pool reconciler: %v", err))
5266
}
5367
}

internal/controllers/machine/machine_controller_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,11 @@ func TestNodeToMachine(t *testing.T) {
25192519

25202520
g.Expect(env.Create(ctx, testCluster)).To(Succeed())
25212521
g.Expect(env.CreateKubeconfigSecret(ctx, testCluster)).To(Succeed())
2522+
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
2523+
testClusterOriginal := client.MergeFrom(testCluster.DeepCopy())
2524+
testCluster.Status.InfrastructureReady = true
2525+
g.Expect(env.Status().Patch(ctx, testCluster, testClusterOriginal)).To(Succeed())
2526+
25222527
g.Expect(env.Create(ctx, defaultBootstrap)).To(Succeed())
25232528
g.Expect(env.Create(ctx, targetNode)).To(Succeed())
25242529
g.Expect(env.Create(ctx, randomNode)).To(Succeed())

internal/controllers/machinedeployment/machinedeployment_controller_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func TestMachineDeploymentReconciler(t *testing.T) {
6262
t.Log("Creating the Cluster Kubeconfig Secret")
6363
g.Expect(env.CreateKubeconfigSecret(ctx, cluster)).To(Succeed())
6464

65+
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
66+
patch := client.MergeFrom(cluster.DeepCopy())
67+
cluster.Status.InfrastructureReady = true
68+
g.Expect(env.Status().Patch(ctx, cluster, patch)).To(Succeed())
69+
6570
return ns, cluster
6671
}
6772

internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -2351,18 +2351,22 @@ func createCluster(g *WithT, namespaceName string) *clusterv1.Cluster {
23512351
},
23522352
}
23532353

2354-
g.Expect(env.Create(ctx, cluster)).To(Succeed())
2354+
g.Expect(env.CreateAndWait(ctx, cluster)).To(Succeed())
23552355

23562356
// Make sure the cluster is in the cache before proceeding
23572357
g.Eventually(func() error {
23582358
var cl clusterv1.Cluster
23592359
return env.Get(ctx, util.ObjectKey(cluster), &cl)
23602360
}, timeout, 100*time.Millisecond).Should(Succeed())
23612361

2362+
g.Expect(env.CreateKubeconfigSecret(ctx, cluster)).To(Succeed())
2363+
23622364
// This is required for MHC to perform checks
23632365
patchHelper, err := patch.NewHelper(cluster, env.Client)
23642366
g.Expect(err).ToNot(HaveOccurred())
23652367
conditions.MarkTrue(cluster, clusterv1.InfrastructureReadyCondition)
2368+
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
2369+
cluster.Status.InfrastructureReady = true
23662370
g.Expect(patchHelper.Patch(ctx, cluster)).To(Succeed())
23672371

23682372
// Wait for cluster in cache to be updated post-patch
@@ -2375,14 +2379,6 @@ func createCluster(g *WithT, namespaceName string) *clusterv1.Cluster {
23752379
return conditions.IsTrue(cluster, clusterv1.InfrastructureReadyCondition)
23762380
}, timeout, 100*time.Millisecond).Should(BeTrue())
23772381

2378-
g.Expect(env.CreateKubeconfigSecret(ctx, cluster)).To(Succeed())
2379-
2380-
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
2381-
patchHelper, err = patch.NewHelper(cluster, env.Client)
2382-
g.Expect(err).ToNot(HaveOccurred())
2383-
cluster.Status.InfrastructureReady = true
2384-
g.Expect(patchHelper.Patch(ctx, cluster)).To(Succeed())
2385-
23862382
return cluster
23872383
}
23882384

internal/test/envtest/environment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func init() {
7878
// This would lead to race conditions because input.M.Run() writes os.Stderr
7979
// while some go routines in controller-runtime use os.Stderr to write logs.
8080
logOptions := logs.NewOptions()
81-
logOptions.Verbosity = logsv1.VerbosityLevel(6) // FIXME: change to 2 before merge
81+
logOptions.Verbosity = logsv1.VerbosityLevel(8) // FIXME(sbueringer): change to 2 before merge
8282
if err := logsv1.ValidateAndApply(logOptions, nil); err != nil {
8383
klog.ErrorS(err, "Unable to validate and apply log options")
8484
os.Exit(1)

0 commit comments

Comments
 (0)