Skip to content

Commit

Permalink
build: Move CSI supported provider logic to script (#703)
Browse files Browse the repository at this point in the history
**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.
-->
  • Loading branch information
jimmidyson authored Jun 10, 2024
1 parent c9e2b36 commit cb6b4ee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
33 changes: 33 additions & 0 deletions hack/addons/configure-supported-csi-providers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_DIR

# shellcheck source=hack/common.sh
source "${SCRIPT_DIR}/../common.sh"

# Below are the lists of CSI Providers allowed for a specific infrastructure.
# - When we support a new infrastructure, we need to a create a new entry in this array using the same convention.
# - When we support a new CSI Provider, we need to add it to one or more of these lists.
declare -rA CSI_PROVIDERS=(
["aws"]='["aws-ebs"]'
["nutanix"]='["nutanix"]'
["docker"]='["local-path"]'
)

readonly CSI_JSONPATH='.spec.versions[].schema.openAPIV3Schema.properties.spec.properties.addons.properties.csi.properties'

for provider in "${!CSI_PROVIDERS[@]}"; do
custerconfig_file="${GIT_REPO_ROOT}/api/v1alpha1/crds/caren.nutanix.com_${provider}clusterconfigs.yaml"
cat <<EOF >"${custerconfig_file}.tmp"
$(cat "${GIT_REPO_ROOT}/hack/license-header.yaml.txt")
---
$(gojq --yaml-input --yaml-output \
"(${CSI_JSONPATH}.providers.items.properties.name.enum, ${CSI_JSONPATH}.defaultStorage.properties.providerName.enum) |= ${CSI_PROVIDERS[${provider}]}" \
"${custerconfig_file}")
EOF

mv "${custerconfig_file}"{.tmp,}
done
11 changes: 3 additions & 8 deletions make/addons.mk
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ generate-helm-configmap:
./hack/addons/add-warning-helm-configmap.sh

# Set only the supported CSI providers for each provider.
.PHONY: configure-csi-providers.%
configure-csi-providers.%: CSI_JSONPATH := .spec.versions[].schema.openAPIV3Schema.properties.spec.properties.addons.properties.csi.properties
configure-csi-providers.%: ; $(info $(M) configuring csi providers for $*clusterconfigs)
gojq --yaml-input --yaml-output \
'($(CSI_JSONPATH).providers.items.properties.name.enum, $(CSI_JSONPATH).defaultStorage.properties.providerName.enum) |= $(CSI_PROVIDERS_$(*))' \
api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml > api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml.tmp
cat hack/license-header.yaml.txt <(echo ---) api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml.tmp > api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml
rm api/v1alpha1/crds/caren.nutanix.com_$(*)clusterconfigs.yaml.tmp
.PHONY: configure-csi-providers
configure-csi-providers: ; $(info $(M) configuring supported csi providers)
./hack/addons/configure-supported-csi-providers.sh
2 changes: 0 additions & 2 deletions make/dev.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright 2023 Nutanix. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

ADDONS_PROVIDER := ClusterResourceSet

.PHONY: dev.run-on-kind
dev.run-on-kind: export KUBECONFIG := $(KIND_KUBECONFIG)
dev.run-on-kind: kind.create clusterctl.init
Expand Down
2 changes: 1 addition & 1 deletion make/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ go-generate: ; $(info $(M) running go generate)
object:headerFile="hack/license-header.go.txt" output:object:artifacts:config=/dev/null \
crd:headerFile=hack/license-header.yaml.txt output:crd:artifacts:config=./api/v1alpha1/crds
#$(MAKE) go-fix
$(MAKE) $(addprefix configure-csi-providers.,aws nutanix docker)
$(MAKE) configure-csi-providers

.PHONY: go-mod-upgrade
go-mod-upgrade: ## Interactive check for direct module dependency upgrades
Expand Down

0 comments on commit cb6b4ee

Please sign in to comment.