Skip to content

Commit

Permalink
Change loadbalancer type for HCP deployments
Browse files Browse the repository at this point in the history
The Kubevirt(HCP) clusters do not have their loadbalancer installed and rely
on the host loadblancer( like netallb) when a loadbalancer is created.So when
the Submariner exposes the submariner-gateway loadbalancer service with
ServiceExternalTrafficPolicy locally does not work, as the traffic from
the remotecluster first lands on the host cluster. Hence the traffic policy
need to be updated to cluster in these deployments.

A new parameter hostedCluster is added to submariner config, if set the
traffic policy will be set to cluster

Signed-off-by: Aswin Suryanarayanan <[email protected]>
  • Loading branch information
aswinsuryan committed Jan 10, 2025
1 parent ca3c8fd commit 99bab08
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
13 changes: 11 additions & 2 deletions api/v1alpha1/submariner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,14 @@ type SubmarinerSpec struct {
// Enable NAT between clusters.
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Enable NAT"
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
NatEnabled bool `json:"natEnabled"`

NatEnabled bool `json:"natEnabled"`
AirGappedDeployment bool `json:"airGappedDeployment,omitempty"`

// Is the cluster a hosted cluster.
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Hosted Cluster"
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
HostedCluster bool `json:"hostedCluster,omitempty"`

// Enable automatic Load Balancer in front of the gateways.
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Enable Load Balancer"
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
Expand Down Expand Up @@ -228,6 +232,11 @@ type SubmarinerStatus struct {

AirGappedDeployment bool `json:"airGappedDeployment,omitempty"`

// Is the cluster a hosted cluster.
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Hosted Cluster"
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
HostedCluster bool `json:"hostedCluster,omitempty"`

ColorCodes string `json:"colorCodes,omitempty"`

// The current cluster ID.
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/submariner.io_submariners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ spec:
haltOnCertificateError:
description: Halt on certificate error (so the pod gets restarted).
type: boolean
hostedCluster:
type: boolean
imageOverrides:
additionalProperties:
type: string
Expand Down
8 changes: 7 additions & 1 deletion internal/controllers/submariner/loadbalancer_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func (r *Reconciler) getOCPPlatformType(ctx context.Context) (string, error) {
}

func newLoadBalancerService(instance *v1alpha1.Submariner, platformTypeOCP string) *corev1.Service {
externalTrafficPolicy := corev1.ServiceExternalTrafficPolicyTypeLocal

var svcAnnotations map[string]string

switch platformTypeOCP {
Expand All @@ -108,14 +110,18 @@ func newLoadBalancerService(instance *v1alpha1.Submariner, platformTypeOCP strin
svcAnnotations = map[string]string{}
}

if instance.Spec.HostedCluster {
externalTrafficPolicy = corev1.ServiceExternalTrafficPolicyTypeCluster
}

return &corev1.Service{
ObjectMeta: v1meta.ObjectMeta{
Name: loadBalancerName,
Namespace: instance.Spec.Namespace,
Annotations: svcAnnotations,
},
Spec: corev1.ServiceSpec{
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeLocal,
ExternalTrafficPolicy: externalTrafficPolicy,
Type: corev1.ServiceTypeLoadBalancer,
Selector: map[string]string{
// Traffic is directed to the active gateway
Expand Down
6 changes: 6 additions & 0 deletions pkg/embeddedyamls/yamls.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ spec:
haltOnCertificateError:
description: Halt on certificate error (so the pod gets restarted).
type: boolean
hostedCluster:
description: Is the cluster a hosted cluster.
type: boolean
imageOverrides:
additionalProperties:
type: string
Expand Down Expand Up @@ -840,6 +843,9 @@ spec:
required:
- mismatchedContainerImages
type: object
hostedCluster:
description: Is the cluster a hosted cluster.
type: boolean
loadBalancerStatus:
description: The status of the load balancer DaemonSet.
properties:
Expand Down

0 comments on commit 99bab08

Please sign in to comment.