Skip to content

Commit cb6b4ee

Browse files
authored
build: Move CSI supported provider logic to script (#703)
**What problem does this PR solve?**: PR #695 was merged before I pushed the refactoring to move the logic into a script - this commit contains those changes. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent c9e2b36 commit cb6b4ee

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
readonly SCRIPT_DIR
7+
8+
# shellcheck source=hack/common.sh
9+
source "${SCRIPT_DIR}/../common.sh"
10+
11+
# Below are the lists of CSI Providers allowed for a specific infrastructure.
12+
# - When we support a new infrastructure, we need to a create a new entry in this array using the same convention.
13+
# - When we support a new CSI Provider, we need to add it to one or more of these lists.
14+
declare -rA CSI_PROVIDERS=(
15+
["aws"]='["aws-ebs"]'
16+
["nutanix"]='["nutanix"]'
17+
["docker"]='["local-path"]'
18+
)
19+
20+
readonly CSI_JSONPATH='.spec.versions[].schema.openAPIV3Schema.properties.spec.properties.addons.properties.csi.properties'
21+
22+
for provider in "${!CSI_PROVIDERS[@]}"; do
23+
custerconfig_file="${GIT_REPO_ROOT}/api/v1alpha1/crds/caren.nutanix.com_${provider}clusterconfigs.yaml"
24+
cat <<EOF >"${custerconfig_file}.tmp"
25+
$(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt")
26+
---
27+
$(gojq --yaml-input --yaml-output \
28+
"(${CSI_JSONPATH}.providers.items.properties.name.enum, ${CSI_JSONPATH}.defaultStorage.properties.providerName.enum) |= ${CSI_PROVIDERS[${provider}]}" \
29+
"${custerconfig_file}")
30+
EOF
31+
32+
mv "${custerconfig_file}"{.tmp,}
33+
done

make/addons.mk

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ generate-helm-configmap:
6868
./hack/addons/add-warning-helm-configmap.sh
6969

7070
# Set only the supported CSI providers for each provider.
71-
.PHONY: configure-csi-providers.%
72-
configure-csi-providers.%: CSI_JSONPATH := .spec.versions[].schema.openAPIV3Schema.properties.spec.properties.addons.properties.csi.properties
73-
configure-csi-providers.%: ; $(info $(M) configuring csi providers for $*clusterconfigs)
74-
gojq --yaml-input --yaml-output \
75-
'($(CSI_JSONPATH).providers.items.properties.name.enum, $(CSI_JSONPATH).defaultStorage.properties.providerName.enum) |= $(CSI_PROVIDERS_$(*))' \
76-
api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml > api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml.tmp
77-
cat hack/license-header.yaml.txt <(echo ---) api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml.tmp > api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml
78-
rm api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml.tmp
71+
.PHONY: configure-csi-providers
72+
configure-csi-providers: ; $(info $(M) configuring supported csi providers)
73+
./hack/addons/configure-supported-csi-providers.sh

make/dev.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright 2023 Nutanix. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
ADDONS_PROVIDER := ClusterResourceSet
5-
64
.PHONY: dev.run-on-kind
75
dev.run-on-kind: export KUBECONFIG := $(KIND_KUBECONFIG)
86
dev.run-on-kind: kind.create clusterctl.init

make/go.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ go-generate: ; $(info $(M) running go generate)
201201
object:headerFile="hack/license-header.go.txt" output:object:artifacts:config=/dev/null \
202202
crd:headerFile=hack/license-header.yaml.txt output:crd:artifacts:config=./api/v1alpha1/crds
203203
#$(MAKE) go-fix
204-
$(MAKE) $(addprefix configure-csi-providers.,aws nutanix docker)
204+
$(MAKE) configure-csi-providers
205205

206206
.PHONY: go-mod-upgrade
207207
go-mod-upgrade: ## Interactive check for direct module dependency upgrades

0 commit comments

Comments
 (0)