diff --git a/Makefile b/Makefile index c6d4774..33d4de7 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ KUBEBUILDER_ASSETS=$(shell go run sigs.k8s.io/controller-runtime/tools/setup-env .PHONY: test test: manifests generate fmt ## Run tests. - KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out -v + KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -coverprofile cover.out -v ./... ##@ Build diff --git a/pkg/controller/ipam/ipam_suite_test.go b/pkg/controller/ipam/ipam_suite_test.go index 81eaa89..53ec269 100644 --- a/pkg/controller/ipam/ipam_suite_test.go +++ b/pkg/controller/ipam/ipam_suite_test.go @@ -36,7 +36,15 @@ var ( func TestAPIs(t *testing.T) { gomega.RegisterFailHandler(ginkgo.Fail) - ginkgo.RunSpecs(t, "Node IPAM Controller Suite") + // ginkgo only prints test names and output when either tests failed or when ginkgo run with -ginkgo.v (verbose). + // When running test with `go test -v ./... -ginkgo.v` each package is built and run as a separate binary, hence + // for all other packages but node-ipam-controller/pkg/controller/ipam the flag `-ginkgo.v` is unknown, which lead + // to error "flag provided but not defined: -ginkgo.v". + // To work it around the following two lines set verbosity manually, so the output contains test names (and log + // messages from the controller). + suiteCfg, repCfg := ginkgo.GinkgoConfiguration() + repCfg.Verbose = true + ginkgo.RunSpecs(t, "Node IPAM Controller Suite", suiteCfg, repCfg) } var _ = ginkgo.BeforeSuite(func() { diff --git a/pkg/controller/ipam/ipam_test.go b/pkg/controller/ipam/ipam_test.go index ed49c91..76af419 100644 --- a/pkg/controller/ipam/ipam_test.go +++ b/pkg/controller/ipam/ipam_test.go @@ -174,12 +174,19 @@ var _ = ginkgo.Describe("Pod CIDRs", ginkgo.Ordered, func() { clusterCIDR, err := cidrClient.NetworkingV1().ClusterCIDRs().Create(ctx, originalClusterCIDR, metav1.CreateOptions{}) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - clusterCIDR.Spec.NodeSelector = nodeSelector(map[string][]string{"ipv4": {"false"}, "ipv6": {"false"}}) - clusterCIDR.Spec.PerNodeHostBits = int32(9) - clusterCIDR.Spec.IPv4 = "10.10.0.0/23" - clusterCIDR.Spec.IPv6 = "fd00:30:101::/119" + // wait until creation is done and the finalizer is set. + gomega.Eventually(komega.Object(clusterCIDR)).Should(gomega.WithTransform(func(c *v1.ClusterCIDR) []string { + return c.GetFinalizers() + }, gomega.ContainElement(clusterCIDRFinalizer))) - _, err = cidrClient.NetworkingV1().ClusterCIDRs().Update(ctx, clusterCIDR, metav1.UpdateOptions{}) + updated := clusterCIDR.DeepCopy() + + updated.Spec.NodeSelector = nodeSelector(map[string][]string{"ipv4": {"false"}, "ipv6": {"false"}}) + updated.Spec.PerNodeHostBits = int32(9) + updated.Spec.IPv4 = "10.10.0.0/23" + updated.Spec.IPv6 = "fd00:30:101::/119" + + _, err = cidrClient.NetworkingV1().ClusterCIDRs().Update(ctx, updated, metav1.UpdateOptions{}) gomega.Expect(err).Should(gomega.MatchError(gomega.ContainSubstring("NodeSelector cannot be changed."))) gomega.Expect(err).Should(gomega.MatchError(gomega.ContainSubstring("PerNodeHostBits cannot be changed."))) diff --git a/pkg/controller/ipam/multi_cidr_range_allocator.go b/pkg/controller/ipam/multi_cidr_range_allocator.go index c843caa..726ba58 100644 --- a/pkg/controller/ipam/multi_cidr_range_allocator.go +++ b/pkg/controller/ipam/multi_cidr_range_allocator.go @@ -396,7 +396,7 @@ func (r *multiCIDRRangeAllocator) processNextCIDRWorkItem(ctx context.Context) b // Finally, if no error occurs we Forget this item so it does not // get cidrQueued again until another change happens. r.cidrQueue.Forget(obj) - logger.Info("Successfully synced", "key", key) + logger.Info("Successfully synced cidr", "key", key) return nil }(ctx, obj) if err != nil { @@ -454,7 +454,7 @@ func (r *multiCIDRRangeAllocator) processNextNodeWorkItem(ctx context.Context) b // Finally, if no error occurs we Forget this item so it does not // get nodeQueue again until another change happens. r.nodeQueue.Forget(obj) - logger.Info("Successfully synced", "key", key) + logger.Info("Successfully synced node", "key", key) return nil }(klog.FromContext(ctx), obj) if err != nil {