Skip to content

Commit 9977128

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

19 files changed

+138
-7
lines changed

config/crd/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ resources:
77
- bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml
88
- bases/infrastructure.cluster.x-k8s.io_vsphereclusters.yaml
99
- bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml
10+
- bases/infrastructure.cluster.x-k8s.io_loadbalancers.yaml
11+
- bases/infrastructure.cluster.x-k8s.io_awsloadbalancerconfigs.yaml
1012
# +kubebuilder:scaffold:crdkustomizeresource
1113

1214
#patches:

examples/default/provider-components/manager_tolerations_patch.yaml renamed to examples/default/provider-components/base/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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: capv-controller-manager
5+
namespace: capv-system
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: manager
11+
env:
12+
- name: AWS_ACCESS_KEY_ID
13+
valueFrom:
14+
secretKeyRef:
15+
key: access-id
16+
name: manager-bootstrap-credentials
17+
- name: AWS_SECRET_ACCESS_KEY
18+
valueFrom:
19+
secretKeyRef:
20+
key: secret-id
21+
name: manager-bootstrap-credentials
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
secret-id=${AWS_SECRET_KEY}
2+
access-id=${AWS_ACCESS_KEY}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
generatorOptions:
4+
disableNameSuffixHash: true
5+
secretGenerator:
6+
- name: manager-bootstrap-credentials
7+
namespace: capv-system
8+
envs:
9+
- credentials
10+
resources:
11+
- ../base
12+
patchesStrategicMerge:
13+
- capv_loadbalancer_patch.yaml
14+

examples/generate.sh

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ CAPI_MANAGER_IMAGE="${CAPI_MANAGER_IMAGE:-us.gcr.io/k8s-artifacts-prod/cluster-a
3535
CAPV_MANAGER_IMAGE="${CAPV_MANAGER_IMAGE:-gcr.io/cluster-api-provider-vsphere/release/manager:latest}"
3636
K8S_IMAGE_REPOSITORY="${K8S_IMAGE_REPOSITORY:-k8s.gcr.io}"
3737

38+
KUSTOMIZE_OVERLAY='base'
39+
AWS_VPC="${AWS_VPC:-}"
40+
AWS_REGION="${AWS_REGION:-}"
41+
AWS_SUBNET="${AWS_SUBNET:-}"
42+
3843
# Set the default log levels for the manager containers.
3944
CABPK_MANAGER_LOG_LEVEL="${CABPK_MANAGER_LOG_LEVEL:-4}"
4045
CAPI_MANAGER_LOG_LEVEL="${CAPI_MANAGER_LOG_LEVEL:-4}"
@@ -55,6 +60,7 @@ FLAGS
5560
-f force overwrite of existing files
5661
-h prints this help screen
5762
-i input directory (default ${SRC_DIR})
63+
-l enables load balancer
5864
-m capv manager image (default "${CAPV_MANAGER_IMAGE}")
5965
-M capv manager log level (default "${CAPV_MANAGER_LOG_LEVEL}")
6066
-r kubernetes container image repository (default "${K8S_IMAGE_REPOSITORY}")
@@ -65,7 +71,7 @@ FLAGS
6571
EOF
6672
}
6773

68-
while getopts ':b:B:c:dfhi:m:M:r:o:p:P:u' opt; do
74+
while getopts ':b:B:c:dfhi:lm:M:r:o:p:P:u' opt; do
6975
case "${opt}" in
7076
b)
7177
CABPK_MANAGER_IMAGE="${OPTARG}"
@@ -88,6 +94,9 @@ while getopts ':b:B:c:dfhi:m:M:r:o:p:P:u' opt; do
8894
i)
8995
SRC_DIR="${OPTARG}"
9096
;;
97+
l)
98+
KUSTOMIZE_OVERLAY='loadbalancer'
99+
;;
91100
m)
92101
CAPV_MANAGER_IMAGE="${OPTARG}"
93102
;;
@@ -138,9 +147,10 @@ export CAPI_MANAGER_IMAGE CAPI_MANAGER_LOG_LEVEL
138147
export CAPV_MANAGER_IMAGE CAPV_MANAGER_LOG_LEVEL
139148

140149
# Outputs
141-
COMPONENTS_CLUSTER_API_GENERATED_FILE=${SRC_DIR}/provider-components/provider-components-cluster-api.yaml
142-
COMPONENTS_KUBEADM_GENERATED_FILE=${SRC_DIR}/provider-components/provider-components-kubeadm.yaml
143-
COMPONENTS_VSPHERE_GENERATED_FILE=${SRC_DIR}/provider-components/provider-components-vsphere.yaml
150+
COMPONENTS_CLUSTER_API_GENERATED_FILE=${SRC_DIR}/provider-components/base/provider-components-cluster-api.yaml
151+
COMPONENTS_KUBEADM_GENERATED_FILE=${SRC_DIR}/provider-components/base/provider-components-kubeadm.yaml
152+
COMPONENTS_VSPHERE_GENERATED_FILE=${SRC_DIR}/provider-components/base/provider-components-vsphere.yaml
153+
CREDENTIALS_GENERATED_FILE=${SRC_DIR}/provider-components/loadbalancer/credentials
144154

145155
ADDONS_GENERATED_FILE=${OUT_DIR}/addons.yaml
146156
PROVIDER_COMPONENTS_GENERATED_FILE=${OUT_DIR}/provider-components.yaml
@@ -157,7 +167,7 @@ no_file() {
157167
}
158168

159169
# Remove the temporary provider components files.
160-
for f in COMPONENTS_CLUSTER_API COMPONENTS_KUBEADM COMPONENTS_VSPHERE; do \
170+
for f in CREDENTIALS COMPONENTS_CLUSTER_API COMPONENTS_KUBEADM COMPONENTS_VSPHERE; do \
161171
eval "rm -f \"\${${f}_GENERATED_FILE}\""
162172
done
163173

@@ -208,6 +218,9 @@ record_and_export SSH_AUTHORIZED_KEY ":-''"
208218
# single quote string variables that can start with special characters like "*"
209219
# otherwise invalid yaml will be generated
210220
export VSPHERE_RESOURCE_POOL="'${VSPHERE_RESOURCE_POOL}'"
221+
record_and_export AWS_VPC ':-'
222+
record_and_export AWS_SUBNET ':-'
223+
record_and_export AWS_REGION ':-'
211224

212225
verify_cpu_mem_dsk() {
213226
eval "[[ \${${1}-} =~ [[:digit:]]+ ]] || ${1}=\"${2}\"; \
@@ -267,7 +280,7 @@ envsubst >"${ADDONS_GENERATED_FILE}" <"${SRC_DIR}/addons.yaml"
267280
echo "Generated ${ADDONS_GENERATED_FILE}"
268281

269282
# Generate cluster resources.
270-
kustomize build "${SRC_DIR}/cluster" | envsubst >"${CLUSTER_GENERATED_FILE}"
283+
kustomize build "${SRC_DIR}/cluster/" | envsubst >"${CLUSTER_GENERATED_FILE}"
271284
echo "Generated ${CLUSTER_GENERATED_FILE}"
272285

273286
# Generate controlplane resources.
@@ -290,11 +303,23 @@ echo "Generated ${COMPONENTS_KUBEADM_GENERATED_FILE}"
290303
kustomize build "${SRC_DIR}/../../config/default" | envsubst >"${COMPONENTS_VSPHERE_GENERATED_FILE}"
291304
echo "Generated ${COMPONENTS_VSPHERE_GENERATED_FILE}"
292305

306+
# Generate a loadbalancer
307+
if [ "$KUSTOMIZE_OVERLAY" == 'loadbalancer' ]
308+
then
309+
envsubst >"${CREDENTIALS_GENERATED_FILE}" <"${SRC_DIR}/provider-components/${KUSTOMIZE_OVERLAY}/credentials.template"
310+
fi
311+
293312
# Generate a single provider components file.
294-
kustomize build "${SRC_DIR}/provider-components" | envsubst >"${PROVIDER_COMPONENTS_GENERATED_FILE}"
313+
kustomize build "${SRC_DIR}/provider-components/${KUSTOMIZE_OVERLAY}" | envsubst >"${PROVIDER_COMPONENTS_GENERATED_FILE}"
295314
echo "Generated ${PROVIDER_COMPONENTS_GENERATED_FILE}"
296315
echo "WARNING: ${PROVIDER_COMPONENTS_GENERATED_FILE} includes vSphere credentials"
297316

317+
# Generate a loadbalancer
318+
if [ "$KUSTOMIZE_OVERLAY" == 'loadbalancer' ]
319+
then
320+
envsubst >>"${PROVIDER_COMPONENTS_GENERATED_FILE}" <"${SRC_DIR}/../loadbalancer.yaml"
321+
echo "Generated loadbalancer resource in ${PROVIDER_COMPONENTS_GENERATED_FILE}"
322+
fi
298323
# If running in Docker then ensure the contents of the OUT_DIR have the
299324
# the same owner as the volume mounted to the /out directory.
300325
[ "${DOCKER_ENABLED-}" ] && chown -R "$(stat -c '%u:%g' /out)" "${OUT_DIR}"

0 commit comments

Comments
 (0)