Skip to content

Commit

Permalink
multiple-lb-ip-pool-in-wc (#266)
Browse files Browse the repository at this point in the history
* multiple-lb-ip-pool-in-wc

* separator

* docs

* default value

* fix while loop

* fix count

---------

Co-authored-by: Antonia <[email protected]>
Co-authored-by: Antonia von den Driesch <[email protected]>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent e234f6d commit d7f7f3e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions helm/cluster-vsphere/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Configurations related to cluster connectivity such as container registries.
| `global.connectivity.network.loadBalancers.cidrBlocks` |**None**|**Type:** `array`<br/>|
| `global.connectivity.network.loadBalancers.cidrBlocks[*]` |IPv4 address range, in CIDR notation.|**Type:** `string`<br/>**Example:** `"10.244.0.0/16"`<br/>**Value pattern:** `^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/([0-9]|[1,2][0-9]|[3][0-2]))?$`<br/>|
| `global.connectivity.network.loadBalancers.ipPoolName` | **Ip Pool Name** - Ip for Service LB running in WC will be drawn from this GlobalInClusterIPPool resource.|**Type:** `string`<br/>**Value pattern:** `^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`<br/>**Default:** `"svc-lb-ips"`|
| `global.connectivity.network.loadBalancers.numberOfIps` | **Number of LB IPs to reserve**|**Type:** `integer`<br/>**Default:** `3`|
| `global.connectivity.network.pods` | **Pods**|**Type:** `object`<br/>|
| `global.connectivity.network.pods.cidrBlocks` |**None**|**Type:** `array`<br/>|
| `global.connectivity.network.pods.cidrBlocks[*]` |IPv4 address range, in CIDR notation.|**Type:** `string`<br/>**Example:** `"10.244.0.0/16"`<br/>**Value pattern:** `^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/([0-9]|[1,2][0-9]|[3][0-2]))?$`<br/>|
Expand Down
33 changes: 24 additions & 9 deletions helm/cluster-vsphere/templates/ipam/assign-ip-pre-install-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,34 @@ spec:
set -o errexit
set -o pipefail
set -o nounset
new_ip=""
while [ -z "${new_ip}" ] ; do
echo "waiting for a free IP address.."
new_ip=$(kubectl get ipaddresses.ipam.cluster.x-k8s.io --ignore-not-found -n {{ $.Release.Namespace }} {{ include "lbClaimName" $ }} -o 'jsonpath={.spec.address}')
sleep 2
ip_list=""
# Iterate over each ipAddressClaim
count=0
while [ $count -lt {{ .Values.global.connectivity.network.loadBalancers.numberOfIps }} ]
do
new_ip=""
while [ -z "${new_ip}" ] ; do
echo "waiting for a free IP address.."
new_ip=$(kubectl get ipaddresses.ipam.cluster.x-k8s.io --ignore-not-found -n {{ $.Release.Namespace }} {{ include "lbClaimName" $ }}-${count} -o 'jsonpath={.spec.address}')
sleep 2
done
echo "Got the IP: ${new_ip}"
new_ip="${new_ip}/32"
if [ -n "$ip_list" ]; then
ip_list="${ip_list},${new_ip}"
else
ip_list="${new_ip}"
fi
count=$((count+1))
done
echo "Got the IP: ${new_ip}"
new_ip="${new_ip}/32"
# patch the cloud-provider-vsphere-helmrelease
{{- if .Values.global.connectivity.network.loadBalancers.cidrBlocks }}
new_ip="${new_ip},{{ join "," .Values.global.connectivity.network.loadBalancers.cidrBlocks }}"
ip_list="${ip_list},{{ join "," .Values.global.connectivity.network.loadBalancers.cidrBlocks }}"
{{- end }}
kubectl patch helmrelease -n {{ $.Release.Namespace }} {{ include "resource.default.name" $ }}-cloud-provider-vsphere --type=merge -p '{"spec":{"suspend":false,"values":{"kube-vip-cloud-provider": {"cidrGlobal": "'${new_ip}'"}}}}'
kubectl patch helmrelease -n {{ $.Release.Namespace }} {{ include "resource.default.name" $ }}-cloud-provider-vsphere --type=merge -p '{"spec":{"suspend":false,"values":{"kube-vip-cloud-provider": {"cidrGlobal": "'${ip_list}'"}}}}'
{{- end }}
containers:
- name: resume-cluster
Expand Down
7 changes: 5 additions & 2 deletions helm/cluster-vsphere/templates/ipam/ipAddressClaimLB.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{{- if (include "isIpamSvcLoadBalancerEnabled" $) -}}
{{- range $i := until (int .Values.global.connectivity.network.loadBalancers.numberOfIps) }}
---
apiVersion: ipam.cluster.x-k8s.io/v1beta1
kind: IPAddressClaim
metadata:
name: {{ include "lbClaimName" $ }}
name: {{ include "lbClaimName" $ }}-{{$i}}
labels:
{{- include "ipamLabels" $ | nindent 4 }}
spec:
poolRef:
apiGroup: ipam.cluster.x-k8s.io
kind: GlobalInClusterIPPool
name: {{ .Values.global.connectivity.network.loadBalancers.ipPoolName }}
name: {{ $.Values.global.connectivity.network.loadBalancers.ipPoolName }}
{{- end }}
{{- end }}
5 changes: 5 additions & 0 deletions helm/cluster-vsphere/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@
"description": "Ip for Service LB running in WC will be drawn from this GlobalInClusterIPPool resource.",
"default": "svc-lb-ips",
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
},
"numberOfIps": {
"type": "integer",
"title": "Number of LB IPs to reserve",
"default": 3
}
}
},
Expand Down
1 change: 1 addition & 0 deletions helm/cluster-vsphere/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ global:
port: 6443
loadBalancers:
ipPoolName: svc-lb-ips
numberOfIps: 3
pods:
cidrBlocks:
- 10.244.0.0/16
Expand Down

0 comments on commit d7f7f3e

Please sign in to comment.