Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Oct 1, 2024
1 parent 85a6f24 commit d6bb5d9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,15 @@ metadata:
g.Expect(env.CreateAndWait(ctx, testCluster)).To(Succeed())
t.Log("Creating the remote Cluster kubeconfig")
g.Expect(env.CreateKubeconfigSecret(ctx, testCluster)).To(Succeed())
_, err = clusterCache.GetClient(ctx, client.ObjectKeyFromObject(testCluster))
g.Expect(err).ToNot(HaveOccurred())
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
patch := client.MergeFrom(testCluster.DeepCopy())
testCluster.Status.InfrastructureReady = true
g.Expect(env.Status().Patch(ctx, testCluster, patch))

Check failure on line 116 in exp/addons/internal/controllers/clusterresourceset_controller_test.go

View workflow job for this annotation

GitHub Actions / lint

ginkgo-linter: "Expect": missing assertion method. Expected "To()", "ToNot()" or "NotTo()" (ginkgolinter)

g.Eventually(func(g Gomega) {
_, err = clusterCache.GetClient(ctx, client.ObjectKeyFromObject(testCluster))
g.Expect(err).ToNot(HaveOccurred())
}, 1*time.Minute, 5*time.Second).Should(Succeed())

createConfigMapAndSecret(g, ns.Name, configmapName, secretName)
return ns
Expand Down
24 changes: 19 additions & 5 deletions exp/internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"

"sigs.k8s.io/cluster-api/api/v1beta1/index"
"sigs.k8s.io/cluster-api/controllers/clustercache"
"sigs.k8s.io/cluster-api/controllers/remote"
"sigs.k8s.io/cluster-api/internal/test/envtest"
)

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

setupReconcilers := func(ctx context.Context, mgr ctrl.Manager) {
machinePoolReconciler := MachinePoolReconciler{
Client: mgr.GetClient(),
recorder: mgr.GetEventRecorderFor("machinepool-controller"),
}
err := machinePoolReconciler.SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1})
clusterCache, err := clustercache.SetupWithManager(ctx, mgr, clustercache.Options{
SecretClient: mgr.GetClient(),
Cache: clustercache.CacheOptions{
Indexes: []clustercache.CacheOptionsIndex{clustercache.NodeProviderIDIndex},
},
Client: clustercache.ClientOptions{
UserAgent: remote.DefaultClusterAPIUserAgent("test-controller-manager"),
},
}, controller.Options{MaxConcurrentReconciles: 10})
if err != nil {
panic(fmt.Sprintf("Failed to create new cluster cache tracker: %v", err))
}

if err := (&MachinePoolReconciler{
Client: mgr.GetClient(),
ClusterCache: clusterCache,
recorder: mgr.GetEventRecorderFor("machinepool-controller"),
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: 1}); err != nil {
panic(fmt.Sprintf("Failed to set up machine pool reconciler: %v", err))
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/controllers/machine/machine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,11 @@ func TestNodeToMachine(t *testing.T) {

g.Expect(env.Create(ctx, testCluster)).To(Succeed())
g.Expect(env.CreateKubeconfigSecret(ctx, testCluster)).To(Succeed())
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
testClusterOriginal := client.MergeFrom(testCluster.DeepCopy())
testCluster.Status.InfrastructureReady = true
g.Expect(env.Status().Patch(ctx, testCluster, testClusterOriginal))

Check failure on line 2525 in internal/controllers/machine/machine_controller_test.go

View workflow job for this annotation

GitHub Actions / lint

ginkgo-linter: "Expect": missing assertion method. Expected "To()", "ToNot()" or "NotTo()" (ginkgolinter)

g.Expect(env.Create(ctx, defaultBootstrap)).To(Succeed())
g.Expect(env.Create(ctx, targetNode)).To(Succeed())
g.Expect(env.Create(ctx, randomNode)).To(Succeed())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func TestMachineDeploymentReconciler(t *testing.T) {
t.Log("Creating the Cluster Kubeconfig Secret")
g.Expect(env.CreateKubeconfigSecret(ctx, cluster)).To(Succeed())

// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
patch := client.MergeFrom(cluster.DeepCopy())
cluster.Status.InfrastructureReady = true
g.Expect(env.Status().Patch(ctx, cluster, patch))

Check failure on line 68 in internal/controllers/machinedeployment/machinedeployment_controller_test.go

View workflow job for this annotation

GitHub Actions / lint

ginkgo-linter: "Expect": missing assertion method. Expected "To()", "ToNot()" or "NotTo()" (ginkgolinter)

return ns, cluster
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2351,18 +2351,22 @@ func createCluster(g *WithT, namespaceName string) *clusterv1.Cluster {
},
}

g.Expect(env.Create(ctx, cluster)).To(Succeed())
g.Expect(env.CreateAndWait(ctx, cluster)).To(Succeed())

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

g.Expect(env.CreateKubeconfigSecret(ctx, cluster)).To(Succeed())

// This is required for MHC to perform checks
patchHelper, err := patch.NewHelper(cluster, env.Client)
g.Expect(err).ToNot(HaveOccurred())
conditions.MarkTrue(cluster, clusterv1.InfrastructureReadyCondition)
// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
cluster.Status.InfrastructureReady = true
g.Expect(patchHelper.Patch(ctx, cluster)).To(Succeed())

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

g.Expect(env.CreateKubeconfigSecret(ctx, cluster)).To(Succeed())

// Set InfrastructureReady to true so ClusterCache creates the clusterAccessor.
patchHelper, err = patch.NewHelper(cluster, env.Client)
g.Expect(err).ToNot(HaveOccurred())
cluster.Status.InfrastructureReady = true
g.Expect(patchHelper.Patch(ctx, cluster)).To(Succeed())

return cluster
}

Expand Down
2 changes: 1 addition & 1 deletion internal/test/envtest/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func init() {
// This would lead to race conditions because input.M.Run() writes os.Stderr
// while some go routines in controller-runtime use os.Stderr to write logs.
logOptions := logs.NewOptions()
logOptions.Verbosity = logsv1.VerbosityLevel(6) // FIXME: change to 2 before merge
logOptions.Verbosity = logsv1.VerbosityLevel(8) // FIXME(sbueringer): change to 2 before merge
if err := logsv1.ValidateAndApply(logOptions, nil); err != nil {
klog.ErrorS(err, "Unable to validate and apply log options")
os.Exit(1)
Expand Down

0 comments on commit d6bb5d9

Please sign in to comment.