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

feat: Add the ServiceLoadbalancer Addon, with MetalLB as first provider #592

Merged
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
12 changes: 12 additions & 0 deletions api/v1alpha1/addon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (

VirtualIPProviderKubeVIP = "KubeVIP"

ServiceLoadBalancerProviderMetalLB = "MetalLB"

AddonStrategyClusterResourceSet AddonStrategy = "ClusterResourceSet"
AddonStrategyHelmAddon AddonStrategy = "HelmAddon"

Expand Down Expand Up @@ -69,6 +71,9 @@ type Addons struct {

// +optional
CSIProviders *CSI `json:"csi,omitempty"`

// +optional
ServiceLoadBalancer *ServiceLoadBalancer `json:"serviceLoadBalancer,omitempty"`
}

type AddonStrategy string
Expand Down Expand Up @@ -160,3 +165,10 @@ type CCM struct {
// +optional
Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"`
}

type ServiceLoadBalancer struct {
// The LoadBalancer-type Service provider to deploy. Not required in infrastructures where
// the CCM acts as the provider.
// +kubebuilder:validation:Enum=MetalLB
Provider string `json:"provider"`
}
2 changes: 2 additions & 0 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ const (
AWSVariableName = "aws"
// NutanixVariableName is the Nutanix config patch variable name.
NutanixVariableName = "nutanix"
// ServiceLoadBalancerName is the Service LoadBalancer config patch variable name.
ServiceLoadBalancerVariableName = "serviceLoadBalancer"
)
12 changes: 12 additions & 0 deletions api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ spec:
required:
- strategy
type: object
serviceLoadBalancer:
properties:
provider:
description: |-
The LoadBalancer-type Service provider to deploy. Not required in infrastructures where
the CCM acts as the provider.
enum:
- MetalLB
type: string
required:
- provider
type: object
type: object
aws:
description: AWS cluster configuration.
Expand Down
12 changes: 12 additions & 0 deletions api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ spec:
required:
- strategy
type: object
serviceLoadBalancer:
properties:
provider:
description: |-
The LoadBalancer-type Service provider to deploy. Not required in infrastructures where
the CCM acts as the provider.
enum:
- MetalLB
type: string
required:
- provider
type: object
type: object
controlPlane:
description: DockerNodeConfigSpec defines the desired state of DockerNodeSpec.
Expand Down
12 changes: 12 additions & 0 deletions api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ spec:
required:
- strategy
type: object
serviceLoadBalancer:
properties:
provider:
description: |-
The LoadBalancer-type Service provider to deploy. Not required in infrastructures where
the CCM acts as the provider.
enum:
- MetalLB
type: string
required:
- provider
type: object
type: object
controlPlane:
description: NutanixNodeSpec defines the desired state of NutanixNodeSpec.
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions charts/cluster-api-runtime-extensions-nutanix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ A Helm chart for cluster-api-runtime-extensions-nutanix
| hooks.nfd.crsStrategy.defaultInstallationConfigMap.name | string | `"node-feature-discovery"` | |
| hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.create | bool | `true` | |
| hooks.nfd.helmAddonStrategy.defaultValueTemplateConfigMap.name | string | `"default-nfd-helm-values-template"` | |
| hooks.serviceLoadBalancer.metalLB.defaultValueTemplateConfigMap.create | bool | `true` | |
| hooks.serviceLoadBalancer.metalLB.defaultValueTemplateConfigMap.name | string | `"default-metallb-helm-values-template"` | |
| hooks.virtualIP.kubeVip.defaultTemplateConfigMap.create | bool | `true` | |
| hooks.virtualIP.kubeVip.defaultTemplateConfigMap.name | string | `"default-kube-vip-template"` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ data:
ChartName: cluster-autoscaler
ChartVersion: 9.35.0
RepositoryURL: https://kubernetes.github.io/autoscaler
metallb: |
ChartName: metallb
ChartVersion: v0.14.5
RepositoryURL: https://metallb.github.io/metallb
nfd: |
ChartName: node-feature-discovery
ChartVersion: 0.15.2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2023 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

{{- if .Values.hooks.serviceLoadBalancer.metalLB.defaultValueTemplateConfigMap.create }}
apiVersion: v1
kind: ConfigMap
metadata:
name: '{{ .Values.hooks.serviceLoadBalancer.metalLB.defaultValueTemplateConfigMap.name }}'
data:
values.yaml: |-
controller:
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
operator: Exists
- key: CriticalAddonsOnly
operator: Exists
- effect: NoExecute
operator: Exists
tolerationSeconds: 300
speaker:
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
operator: Exists
- key: CriticalAddonsOnly
operator: Exists
- effect: NoExecute
operator: Exists
tolerationSeconds: 300
{{- end -}}
6 changes: 5 additions & 1 deletion charts/cluster-api-runtime-extensions-nutanix/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ hooks:
defaultValueTemplateConfigMap:
create: true
name: default-cluster-autoscaler-helm-values-template

serviceLoadBalancer:
metalLB:
defaultValueTemplateConfigMap:
create: true
name: default-metallb-helm-values-template
virtualIP:
kubeVip:
defaultTemplateConfigMap:
Expand Down
40 changes: 40 additions & 0 deletions docs/content/addons/serviceloadbalancer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
+++
title = "Service LoadBalancer"
+++

When an application running in a cluster needs to be exposed outside of the cluster, one option is
to use an [external load balancer], by creating a Kubernetes Service of the
`LoadBalancer` type.

The Service Load Balancer is the component that backs this Kubernetes Service, either by creating
a Virtual IP, creating a machine that runs load balancer software, by delegating to APIs, such as
the underlying infrastructure, or a hardware load balancer.

CAREN currently supports the following Service Load Balancers:

- [MetalLB]

## Example

To enable deployment of MetalLB on a cluster, specify the following values:

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: <NAME>
spec:
topology:
variables:
- name: clusterConfig
value:
addons:
serviceLoadBalancer:
provider: MetalLB
```

See [MetalLB documentation] for details on configuration.

[external load balancer]: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/
[MetalLB]: https://metallb.org
[MetalLB documentation]: https://metallb.org/configuration/
27 changes: 27 additions & 0 deletions hack/addons/kustomize/metallb/kustomization.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# NOTE This file is used by the tool in `hack/tools/helm-cm` to add
# metallb chart metadata to the "helm-addons" ConfigMap. The tool takes
# a kustomization as input. We do not use this file with kustomize.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

metadata:
name: metallb

sortOptions:
order: fifo

helmCharts:
- name: metallb
repo: https://metallb.github.io/metallb
releaseName: metallb
version: ${METALLB_CHART_VERSION}
valuesFile: helm-values.yaml
includeCRDs: true
skipTests: true
namespace: metallb-system

namespace: metallb-system
2 changes: 2 additions & 0 deletions make/addons.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export NUTANIX_CCM_CHART_VERSION := 0.3.3

export KUBE_VIP_VERSION := v0.8.0

export METALLB_CHART_VERSION := v0.14.5

.PHONY: addons.sync
addons.sync: $(addprefix update-addon.,calico cilium nfd cluster-autoscaler aws-ebs-csi aws-ccm.127 aws-ccm.128 aws-ccm.129 kube-vip)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("Generate AWS ControlPlane LoadBalancer patches", func() {
Name: "unset variable",
},
{
Name: "ControlPlaneLoadbalancer scheme set to internet-facing",
Name: "ControlPlaneLoadBalancer scheme set to internet-facing",
Vars: []runtimehooksv1.Variable{
capitest.VariableWithValue(
clusterconfig.MetaVariableName,
Expand All @@ -55,7 +55,7 @@ var _ = Describe("Generate AWS ControlPlane LoadBalancer patches", func() {
}},
},
{
Name: "ControlPlaneLoadbalancer scheme set to internal",
Name: "ControlPlaneLoadBalancer scheme set to internal",
Vars: []runtimehooksv1.Variable{
capitest.VariableWithValue(
clusterconfig.MetaVariableName,
Expand Down
1 change: 1 addition & 0 deletions pkg/handlers/generic/lifecycle/config/cm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
NutanixStorageCSI Component = "nutanix-storage-csi"
NutanixSnapshotCSI Component = "nutanix-snapshot-csi"
NutanixCCM Component = "nutanix-ccm"
MetalLB Component = "metallb"
)

type HelmChartGetter struct {
Expand Down
13 changes: 13 additions & 0 deletions pkg/handlers/generic/lifecycle/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
nutanixcsi "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/csi/nutanix-csi"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/nfd"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/servicelbgc"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/serviceloadbalancer"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/serviceloadbalancer/metallb"
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options"
)

Expand All @@ -34,6 +36,7 @@ type Handlers struct {
nutnaixCSIConfig *nutanixcsi.NutanixCSIConfig
awsccmConfig *awsccm.AWSCCMConfig
nutanixCCMConfig *nutanixccm.Config
metalLBConfig *metallb.Config
}

func New(
Expand All @@ -51,6 +54,7 @@ func New(
awsccmConfig: &awsccm.AWSCCMConfig{GlobalOptions: globalOptions},
nutnaixCSIConfig: &nutanixcsi.NutanixCSIConfig{GlobalOptions: globalOptions},
nutanixCCMConfig: &nutanixccm.Config{GlobalOptions: globalOptions},
metalLBConfig: &metallb.Config{GlobalOptions: globalOptions},
}
}

Expand All @@ -76,6 +80,13 @@ func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
helmChartInfoGetter,
),
}
serviceLoadBalancerHandlers := map[string]serviceloadbalancer.ServiceLoadBalancerProvider{
v1alpha1.ServiceLoadBalancerProviderMetalLB: metallb.New(
mgr.GetClient(),
h.metalLBConfig,
helmChartInfoGetter,
),
}
return []handlers.Named{
calico.New(mgr.GetClient(), h.calicoCNIConfig, helmChartInfoGetter),
cilium.New(mgr.GetClient(), h.ciliumCNIConfig, helmChartInfoGetter),
Expand All @@ -84,6 +95,7 @@ func (h *Handlers) AllHandlers(mgr manager.Manager) []handlers.Named {
servicelbgc.New(mgr.GetClient()),
csi.New(mgr.GetClient(), csiHandlers),
ccm.New(mgr.GetClient(), ccmHandlers),
serviceloadbalancer.New(mgr.GetClient(), serviceLoadBalancerHandlers),
}
}

Expand All @@ -96,4 +108,5 @@ func (h *Handlers) AddFlags(flagSet *pflag.FlagSet) {
h.awsccmConfig.AddFlags("awsccm", pflag.CommandLine)
h.nutnaixCSIConfig.AddFlags("nutanixcsi", flagSet)
h.nutanixCCMConfig.AddFlags("nutanixccm", flagSet)
h.metalLBConfig.AddFlags("metallb", flagSet)
}
Loading
Loading