Skip to content

Commit

Permalink
Add clustersetip conifg to LH deployments
Browse files Browse the repository at this point in the history
Deploy Lighthouse deployments with new ClustersetIP fields
in Submariner and ServiceDiscovery specs.

Signed-off-by: Vishal Thapar <[email protected]>
  • Loading branch information
vthapar authored and aswinsuryan committed Sep 10, 2024
1 parent ee76b52 commit ab6aed4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
2 changes: 2 additions & 0 deletions controllers/servicediscovery/servicediscovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
2 changes: 2 additions & 0 deletions controllers/submariner/servicediscovery_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions controllers/submariner/submariner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions controllers/submariner/submariner_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
9 changes: 8 additions & 1 deletion pkg/discovery/network/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,16 @@ 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{
ObjectMeta: metav1.ObjectMeta{
Name: names.SubmarinerCrName,
},
Spec: v1alpha1.SubmarinerSpec{
GlobalCIDR: globalCIDR,
GlobalCIDR: globalCIDR,
ClustersetIPCIDR: clustersetIPCIDR,
},
})
})
Expand All @@ -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()
})
})
})

Expand Down
27 changes: 17 additions & 10 deletions pkg/discovery/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit ab6aed4

Please sign in to comment.