Skip to content

build: Move CSI supported provider logic to script #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading