diff --git a/controllers/servicediscovery/servicediscovery_controller.go b/controllers/servicediscovery/servicediscovery_controller.go index 6b4e19c94..1e9d945cc 100644 --- a/controllers/servicediscovery/servicediscovery_controller.go +++ b/controllers/servicediscovery/servicediscovery_controller.go @@ -238,6 +238,8 @@ func newLighthouseAgent(cr *submarinerv1alpha1.ServiceDiscovery, name string) *a Env: httpproxy.AddEnvVars([]corev1.EnvVar{ {Name: "SUBMARINER_NAMESPACE", Value: cr.Spec.Namespace}, {Name: "SUBMARINER_CLUSTERID", Value: cr.Spec.ClusterID}, + {Name: "SUBMARINER_CLUSTERSET_IP_CIDR", Value: cr.Spec.ClustersetIPCIDR}, + {Name: "SUBMARINER_CLUSTERSET_IP_ENABLED", Value: strconv.FormatBool(cr.Spec.ClustersetIPEnabled)}, {Name: "SUBMARINER_DEBUG", Value: strconv.FormatBool(cr.Spec.Debug)}, {Name: "SUBMARINER_GLOBALNET_ENABLED", Value: strconv.FormatBool(cr.Spec.GlobalnetEnabled)}, {Name: "SUBMARINER_HALT_ON_CERT_ERROR", Value: strconv.FormatBool(cr.Spec.HaltOnCertificateError)}, diff --git a/controllers/submariner/servicediscovery_resources.go b/controllers/submariner/servicediscovery_resources.go index c966ce550..72de7bc5c 100644 --- a/controllers/submariner/servicediscovery_resources.go +++ b/controllers/submariner/servicediscovery_resources.go @@ -54,6 +54,8 @@ func (r *Reconciler) serviceDiscoveryReconciler(ctx context.Context, submariner ClusterID: submariner.Spec.ClusterID, Namespace: submariner.Spec.Namespace, GlobalnetEnabled: submariner.Spec.GlobalCIDR != "", + ClustersetIPEnabled: submariner.Spec.ClustersetIPEnabled, + ClustersetIPCIDR: submariner.Spec.ClustersetIPCIDR, ImageOverrides: submariner.Spec.ImageOverrides, CoreDNSCustomConfig: submariner.Spec.CoreDNSCustomConfig, NodeSelector: submariner.Spec.NodeSelector, diff --git a/controllers/submariner/submariner_controller.go b/controllers/submariner/submariner_controller.go index 3e68f08a2..c50c69576 100644 --- a/controllers/submariner/submariner_controller.go +++ b/controllers/submariner/submariner_controller.go @@ -225,6 +225,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) ( instance.Status.ColorCodes = instance.Spec.ColorCodes instance.Status.ClusterID = instance.Spec.ClusterID instance.Status.GlobalCIDR = instance.Spec.GlobalCIDR + instance.Status.ClustersetIPCIDR = instance.Spec.ClustersetIPCIDR instance.Status.Gateways = &gatewayStatuses err = updateDaemonSetStatus(ctx, r.config.ScopedClient, gatewayDaemonSet, &instance.Status.GatewayDaemonSetStatus, request.Namespace) diff --git a/controllers/submariner/submariner_suite_test.go b/controllers/submariner/submariner_suite_test.go index 343213ae7..aaad3bd20 100644 --- a/controllers/submariner/submariner_suite_test.go +++ b/controllers/submariner/submariner_suite_test.go @@ -236,6 +236,7 @@ func (t *testDriver) withNetworkDiscovery() *v1alpha1.Submariner { t.submariner.Status.ClusterCIDR = getClusterCIDR(t.submariner, t.clusterNetwork) t.submariner.Status.ServiceCIDR = getServiceCIDR(t.submariner, t.clusterNetwork) t.submariner.Status.GlobalCIDR = getGlobalCIDR(t.submariner, t.clusterNetwork) + t.submariner.Status.ClustersetIPCIDR = getClustersetIPCIDR(t.submariner, t.clusterNetwork) t.submariner.Status.NetworkPlugin = t.clusterNetwork.NetworkPlugin return t.submariner @@ -293,3 +294,11 @@ func getGlobalCIDR(submariner *v1alpha1.Submariner, clusterNetwork *network.Clus return clusterNetwork.GlobalCIDR } + +func getClustersetIPCIDR(submariner *v1alpha1.Submariner, clusterNetwork *network.ClusterNetwork) string { + if submariner.Spec.ClustersetIPCIDR != "" { + return submariner.Spec.ClustersetIPCIDR + } + + return clusterNetwork.ClustersetIPCIDR +} diff --git a/pkg/discovery/network/generic_test.go b/pkg/discovery/network/generic_test.go index b53791cf9..1eb955d54 100644 --- a/pkg/discovery/network/generic_test.go +++ b/pkg/discovery/network/generic_test.go @@ -314,6 +314,7 @@ var _ = Describe("Generic Network", func() { When("the Submariner resource exists", func() { const globalCIDR = "242.112.0.0/24" + const clustersetIPCIDR = "243.110.0.0/20" BeforeEach(func(ctx SpecContext) { clusterNet = testDiscoverGenericWith(ctx, &v1alpha1.Submariner{ @@ -321,7 +322,8 @@ var _ = Describe("Generic Network", func() { Name: names.SubmarinerCrName, }, Spec: v1alpha1.SubmarinerSpec{ - GlobalCIDR: globalCIDR, + GlobalCIDR: globalCIDR, + ClustersetIPCIDR: clustersetIPCIDR, }, }) }) @@ -330,6 +332,11 @@ var _ = Describe("Generic Network", func() { Expect(clusterNet.GlobalCIDR).To(Equal(globalCIDR)) clusterNet.Show() }) + + It("should return the ClusterNetwork structure with the clustersetIP CIDR", func() { + Expect(clusterNet.ClustersetIPCIDR).To(Equal(clustersetIPCIDR)) + clusterNet.Show() + }) }) }) diff --git a/pkg/discovery/network/network.go b/pkg/discovery/network/network.go index 265883cd1..ee013d437 100644 --- a/pkg/discovery/network/network.go +++ b/pkg/discovery/network/network.go @@ -31,11 +31,12 @@ import ( ) type ClusterNetwork struct { - PodCIDRs []string - ServiceCIDRs []string - NetworkPlugin string - GlobalCIDR string - PluginSettings map[string]string + PodCIDRs []string + ServiceCIDRs []string + NetworkPlugin string + GlobalCIDR string + ClustersetIPCIDR string + PluginSettings map[string]string } func (cn *ClusterNetwork) Show() { @@ -49,6 +50,10 @@ func (cn *ClusterNetwork) Show() { if cn.GlobalCIDR != "" { fmt.Printf(" Global CIDR: %v\n", cn.GlobalCIDR) } + + if cn.ClustersetIPCIDR != "" { + fmt.Printf(" ClustersetIP CIDR: %v\n", cn.ClustersetIPCIDR) + } } } @@ -88,8 +93,9 @@ func Discover(ctx context.Context, client controllerClient.Client, operatorNames } if discovery != nil { - globalCIDR, _ := getGlobalCIDRs(ctx, client, operatorNamespace) + globalCIDR, clustersetIPCIDR, _ := getCIDRs(ctx, client, operatorNamespace) discovery.GlobalCIDR = globalCIDR + discovery.ClustersetIPCIDR = clustersetIPCIDR } return discovery, err @@ -119,19 +125,20 @@ func networkPluginsDiscovery(ctx context.Context, client controllerClient.Client return nil, nil } -func getGlobalCIDRs(ctx context.Context, operatorClient controllerClient.Client, operatorNamespace string) (string, error) { +func getCIDRs(ctx context.Context, operatorClient controllerClient.Client, operatorNamespace string) (string, string, error) { if operatorClient == nil { - return "", nil + return "", "", nil } existingCfg := v1alpha1.Submariner{} err := operatorClient.Get(ctx, types.NamespacedName{Namespace: operatorNamespace, Name: names.SubmarinerCrName}, &existingCfg) if err != nil { - return "", errors.Wrap(err, "error retrieving Submariner resource") + return "", "", errors.Wrap(err, "error retrieving Submariner resource") } globalCIDR := existingCfg.Spec.GlobalCIDR + clustersetIPCIDR := existingCfg.Spec.ClustersetIPCIDR - return globalCIDR, nil + return globalCIDR, clustersetIPCIDR, nil }