Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllocateCIDRFromConfigMap should return if clusterset IP is enabled #3234

Merged
merged 1 commit into from
Sep 30, 2024
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
30 changes: 17 additions & 13 deletions pkg/discovery/clustersetip/clustersetip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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")
}
Expand All @@ -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
}
10 changes: 5 additions & 5 deletions pkg/discovery/clustersetip/clustersetip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
})
})
Expand All @@ -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)
Expand All @@ -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))
})
})
Expand All @@ -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"))
})
})
Expand Down
Loading