Skip to content

Commit cd490cd

Browse files
committed
add kustomization and manifest generation for loadbalancer resources
Signed-off-by: Yassine TIJANI <[email protected]>
1 parent fe98be3 commit cd490cd

File tree

8 files changed

+58
-7
lines changed

8 files changed

+58
-7
lines changed
File renamed without changes.
File renamed without changes.

examples/cluster/kustomizeconfig.yaml renamed to examples/cluster/base/kustomizeconfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ namespace:
33
group: cluster.x-k8s.io
44
version: v1alpha2
55
path: spec/infrastructureRef/namespace
6-
create: true
6+
create: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
2+
kind: VSphereCluster
3+
metadata:
4+
name: ${CLUSTER_NAME}
5+
spec:
6+
loadBalancerRef:
7+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
8+
Kind: ${PROVIDER_KIND}
9+
Name: ${CLUSTER_NAME}
10+
namespace: default
11+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: default
4+
resources:
5+
- ../base
6+
patchesStrategicMerge:
7+
- cluster_loadbalancer_patch.yaml

examples/generate.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ CABPK_MANAGER_IMAGE="${CABPK_MANAGER_IMAGE:-us.gcr.io/k8s-artifacts-prod/capi-ku
3434
CAPI_MANAGER_IMAGE="${CAPI_MANAGER_IMAGE:-us.gcr.io/k8s-artifacts-prod/cluster-api/cluster-api-controller:v0.2.1}"
3535
CAPV_MANAGER_IMAGE="${CAPV_MANAGER_IMAGE:-gcr.io/cluster-api-provider-vsphere/release/manager:latest}"
3636

37+
LOADBALANCER=
38+
AWS_VPC="${AWS_VPC:-}"
39+
AWS_REGION="${AWS_REGION:-}"
40+
AWS_SUBNET="${AWS_SUBNET:-}"
41+
3742
# Set the default log levels for the manager containers.
3843
CABPK_MANAGER_LOG_LEVEL="${CABPK_MANAGER_LOG_LEVEL:-4}"
3944
CAPI_MANAGER_LOG_LEVEL="${CAPI_MANAGER_LOG_LEVEL:-4}"
@@ -52,6 +57,7 @@ FLAGS
5257
-f force overwrite of existing files
5358
-h prints this help screen
5459
-i input directory (default ${SRC_DIR})
60+
-l enables load balancer
5561
-m capv manager image (default "${CAPV_MANAGER_IMAGE}")
5662
-M capv manager log level (default "${CAPV_MANAGER_LOG_LEVEL}")
5763
-o output directory (default ${OUT_DIR})
@@ -60,7 +66,7 @@ FLAGS
6066
EOF
6167
}
6268

63-
while getopts ':b:B:c:dfhi:m:M:o:p:P:' opt; do
69+
while getopts ':b:B:c:dfhi:lm:M:o:p:P:' opt; do
6470
case "${opt}" in
6571
b)
6672
CABPK_MANAGER_IMAGE="${OPTARG}"
@@ -83,6 +89,9 @@ while getopts ':b:B:c:dfhi:m:M:o:p:P:' opt; do
8389
i)
8490
SRC_DIR="${OPTARG}"
8591
;;
92+
l)
93+
LOADBALANCER=1
94+
;;
8695
m)
8796
CAPV_MANAGER_IMAGE="${OPTARG}"
8897
;;
@@ -130,6 +139,7 @@ PROVIDER_COMPONENTS_GENERATED_FILE=${OUT_DIR}/provider-components.yaml
130139
CLUSTER_GENERATED_FILE=${OUT_DIR}/cluster.yaml
131140
CONTROLPLANE_GENERATED_FILE=${OUT_DIR}/controlplane.yaml
132141
MACHINEDEPLOYMENT_GENERATED_FILE=${OUT_DIR}/machinedeployment.yaml
142+
LB_GENERATED_FILE=${OUT_DIR}/loadbalancer.yaml
133143

134144
ok_file() {
135145
[ -f "${1}" ] || { echo "${1} is missing" 1>&2; exit 1; }
@@ -185,7 +195,9 @@ record_and_export VSPHERE_NETWORK "${ENV_VAR_REQ}"
185195
record_and_export VSPHERE_RESOURCE_POOL ':-'
186196
record_and_export VSPHERE_FOLDER ':-'
187197
record_and_export VSPHERE_TEMPLATE ':-'
188-
record_and_export SSH_AUTHORIZED_KEY ':-'
198+
record_and_export AWS_VPC ':-'
199+
record_and_export AWS_SUBNET ':-'
200+
record_and_export AWS_REGION ':-'
189201

190202
verify_cpu_mem_dsk() {
191203
eval "[[ \${${1}-} =~ [[:digit:]]+ ]] || ${1}=\"${2}\"; \
@@ -241,10 +253,15 @@ envsubst() {
241253
# Generate the addons file.
242254
envsubst >"${ADDONS_GENERATED_FILE}" <"${SRC_DIR}/addons.yaml"
243255
echo "Generated ${ADDONS_GENERATED_FILE}"
244-
245256
# Generate cluster resources.
246-
kustomize build "${SRC_DIR}/cluster" | envsubst >"${CLUSTER_GENERATED_FILE}"
247-
echo "Generated ${CLUSTER_GENERATED_FILE}"
257+
if [ ! -z "$LOADBALANCER" ]
258+
then
259+
kustomize build "${SRC_DIR}/cluster/loadbalancer" | envsubst >"${CLUSTER_GENERATED_FILE}"
260+
echo "Generated ${CLUSTER_GENERATED_FILE}"
261+
else
262+
kustomize build "${SRC_DIR}/cluster/base" | envsubst >"${CLUSTER_GENERATED_FILE}"
263+
echo "Generated ${CLUSTER_GENERATED_FILE}"
264+
fi
248265

249266
# Generate controlplane resources.
250267
kustomize build "${SRC_DIR}/controlplane" | envsubst >"${CONTROLPLANE_GENERATED_FILE}"
@@ -270,7 +287,11 @@ echo "Generated ${COMPONENTS_VSPHERE_GENERATED_FILE}"
270287
kustomize build "${SRC_DIR}/provider-components" | envsubst >"${PROVIDER_COMPONENTS_GENERATED_FILE}"
271288
echo "Generated ${PROVIDER_COMPONENTS_GENERATED_FILE}"
272289
echo "WARNING: ${PROVIDER_COMPONENTS_GENERATED_FILE} includes vSphere credentials"
273-
290+
if [ ! -z "$LOADBALANCER" ]
291+
then
292+
envsubst >>"${PROVIDER_COMPONENTS_GENERATED_FILE}" <"${SRC_DIR}/loadbalancer.yaml"
293+
echo "Generated loadbalancer resource in ${PROVIDER_COMPONENTS_GENERATED_FILE}"
294+
fi
274295
# If running in Docker then ensure the contents of the OUT_DIR have the
275296
# the same owner as the volume mounted to the /out directory.
276297
[ "${DOCKER_ENABLED-}" ] && chown -R "$(stat -c '%u:%g' /out)" "${OUT_DIR}"

examples/loadbalancer.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
3+
kind: AWSLoadBalancer
4+
metadata:
5+
name: ${CLUSTER_NAME}
6+
namespace: default
7+
spec:
8+
vpcId: ${AWS_VPC}
9+
subnetIds:
10+
- ${AWS_SUBNET}
11+
region: ${AWS_REGION}

examples/provider-components/manager_tolerations_patch.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ spec:
3838
- effect: NoExecute
3939
key: node.alpha.kubernetes.io/unreachable
4040
operator: Exists
41+
4142
---
4243
apiVersion: apps/v1
4344
kind: Deployment

0 commit comments

Comments
 (0)