From 70b24123471cd37d3c58cd0e18d6f8915ccf709f Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Fri, 27 Sep 2024 21:11:39 -0400 Subject: [PATCH] AllocateCIDRFromConfigMap should return if clusterset IP is enabled Signed-off-by: Tom Pantelis --- pkg/discovery/clustersetip/clustersetip.go | 30 +++++++++++-------- .../clustersetip/clustersetip_test.go | 10 +++---- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/pkg/discovery/clustersetip/clustersetip.go b/pkg/discovery/clustersetip/clustersetip.go index f2c20e4d0..99b2c14dc 100644 --- a/pkg/discovery/clustersetip/clustersetip.go +++ b/pkg/discovery/clustersetip/clustersetip.go @@ -165,14 +165,16 @@ func ValidateExistingClustersetIPNetworks(ctx context.Context, client controller } func AllocateCIDRFromConfigMap(ctx context.Context, brokerAdminClient controllerClient.Client, brokerNamespace string, - netconfig *Config, status reporter.Interface, -) error { + config *Config, status reporter.Interface, +) (bool, error) { // Setup default clustersize if nothing specified - if netconfig.ClustersetIPCIDR == "" && netconfig.AllocationSize == 0 { - netconfig.AllocationSize = DefaultAllocationSize + if config.ClustersetIPCIDR == "" && config.AllocationSize == 0 { + config.AllocationSize = DefaultAllocationSize } - userClustersetIPCIDR := netconfig.ClustersetIPCIDR + enabled := false + userClustersetIPCIDR := config.ClustersetIPCIDR + retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error { status.Start("Retrieving ClustersetIP information from the Broker") defer status.End() @@ -182,21 +184,23 @@ func AllocateCIDRFromConfigMap(ctx context.Context, brokerAdminClient controller return status.Error(err, "unable to retrieve ClustersetIP information") } - netconfig.ClustersetIPCIDR, err = ValidateClustersetIPConfiguration(clustersetIPInfo, *netconfig, status) + config.ClustersetIPCIDR, err = ValidateClustersetIPConfiguration(clustersetIPInfo, *config, status) if err != nil { return status.Error(err, "error validating the ClustersetIP configuration") } - netconfig.ClustersetIPCIDR, err = assignClustersetIPs(clustersetIPInfo, *netconfig, status) + config.ClustersetIPCIDR, err = assignClustersetIPs(clustersetIPInfo, *config, status) if err != nil { return status.Error(err, "error assigning ClustersetIP IPs") } - if clustersetIPInfo.Clusters[netconfig.ClusterID] == nil || - clustersetIPInfo.Clusters[netconfig.ClusterID].CIDRs[0] != netconfig.ClustersetIPCIDR { + enabled = clustersetIPInfo.Enabled + + if clustersetIPInfo.Clusters[config.ClusterID] == nil || + clustersetIPInfo.Clusters[config.ClusterID].CIDRs[0] != config.ClustersetIPCIDR { newClusterInfo := cidr.ClusterInfo{ - ClusterID: netconfig.ClusterID, - CIDRs: []string{netconfig.ClustersetIPCIDR}, + ClusterID: config.ClusterID, + CIDRs: []string{config.ClustersetIPCIDR}, } status.Start("Updating the ClustersetIP information on the Broker") @@ -205,7 +209,7 @@ func AllocateCIDRFromConfigMap(ctx context.Context, brokerAdminClient controller if apierrors.IsConflict(err) { status.Warning("Conflict occurred updating the ClustersetIP ConfigMap - retrying") // Conflict with allocation, retry with user given CIDR to try reallocation - netconfig.ClustersetIPCIDR = userClustersetIPCIDR + config.ClustersetIPCIDR = userClustersetIPCIDR } else { return status.Error(err, "error updating the ClustersetIP ConfigMap") } @@ -216,5 +220,5 @@ func AllocateCIDRFromConfigMap(ctx context.Context, brokerAdminClient controller return nil }) - return retryErr //nolint:wrapcheck // No need to wrap here + return enabled, retryErr //nolint:wrapcheck // No need to wrap here } diff --git a/pkg/discovery/clustersetip/clustersetip_test.go b/pkg/discovery/clustersetip/clustersetip_test.go index 447aac6d4..6719e6c42 100644 --- a/pkg/discovery/clustersetip/clustersetip_test.go +++ b/pkg/discovery/clustersetip/clustersetip_test.go @@ -49,7 +49,7 @@ var _ = Describe("AllocateCIDRFromConfigMap", func() { } Expect(clustersetip.AllocateCIDRFromConfigMap(ctx, client, namespace, - netconfig, reporter.Klog())).To(Succeed()) + netconfig, reporter.Klog())).To(BeTrue()) Expect(netconfig.ClustersetIPCIDR).To(Equal(expClustersetIPCIDR)) clustersetipInfo, _, err := clustersetip.GetClustersetIPNetworks(ctx, client, namespace) @@ -61,7 +61,7 @@ var _ = Describe("AllocateCIDRFromConfigMap", func() { netconfig.ClustersetIPCIDR = "" Expect(clustersetip.AllocateCIDRFromConfigMap(ctx, client, namespace, - netconfig, reporter.Klog())).To(Succeed()) + netconfig, reporter.Klog())).To(BeTrue()) Expect(netconfig.ClustersetIPCIDR).To(Equal(expClustersetIPCIDR)) }) }) @@ -76,7 +76,7 @@ var _ = Describe("AllocateCIDRFromConfigMap", func() { } Expect(clustersetip.AllocateCIDRFromConfigMap(ctx, client, namespace, - netconfig, reporter.Klog())).To(Succeed()) + netconfig, reporter.Klog())).To(BeTrue()) Expect(netconfig.ClustersetIPCIDR).To(Equal(expClustersetIPCIDR)) clustersetipInfo, _, err := clustersetip.GetClustersetIPNetworks(ctx, client, namespace) @@ -88,7 +88,7 @@ var _ = Describe("AllocateCIDRFromConfigMap", func() { netconfig.ClustersetIPCIDR = "" Expect(clustersetip.AllocateCIDRFromConfigMap(ctx, client, namespace, - netconfig, reporter.Klog())).To(Succeed()) + netconfig, reporter.Klog())).To(BeTrue()) Expect(netconfig.ClustersetIPCIDR).To(Equal(expClustersetIPCIDR)) }) }) @@ -101,7 +101,7 @@ var _ = Describe("AllocateCIDRFromConfigMap", func() { } Expect(clustersetip.AllocateCIDRFromConfigMap(ctx, client, namespace, - netconfig, reporter.Klog())).To(Succeed()) + netconfig, reporter.Klog())).To(BeTrue()) Expect(netconfig.ClustersetIPCIDR).To(Equal("168.254.0.0/22")) }) })