From 7b3372eedd5293bdb342eb3f5a7423313e65b264 Mon Sep 17 00:00:00 2001 From: "liheng.zms" Date: Mon, 18 Mar 2024 16:00:37 +0800 Subject: [PATCH] add generate helm crds scripts Signed-off-by: liheng.zms --- CONTRIBUTING.md | 17 +++++++++++++ Makefile | 4 ++- scripts/generate_helm_crds.sh | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 scripts/generate_helm_crds.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3640e54e9b..d9a2181e93 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -112,6 +112,23 @@ make test If you are going to contribute a feature with new API or needs significant effort, please submit a proposal in [./docs/proposals/](./docs/proposals) first. +### Kruise Helm Charts +[kruise charts](https://github.com/openkruise/charts) is openKruise charts repo, include kruise, kruise rollout, kruise game. +You can add the corresponding charts package in the versions directory as follows: +``` + versions + - kruise-game + - kruise-rollout + - kruise-state-metrics + - kruise + - 1.5.0 + - 1.5.1 + - 1.6.0 + - 1.6.1 +``` + +**make generate_helm_crds** automatically generates crds files under the bin/ directory, which in turn simplifies the generation of helm charts. + ## Engage to help anything We choose GitHub as the primary place for Openkruise to collaborate. diff --git a/Makefile b/Makefile index 76f8e87bd9..53711c5ec9 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ GOBIN=$(shell go env GOBIN) endif GOOS ?= $(shell go env GOOS) -# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. +# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. # Run `setup-envtest list` to list available versions. ENVTEST_K8S_VERSION ?= 1.28.0 @@ -173,6 +173,8 @@ run-kruise-e2e-test: @echo -e "\n\033[36mRunning kruise e2e tests...\033[0m" tools/hack/run-kruise-e2e-test.sh +generate_helm_crds: + scripts/generate_helm_crds.sh # kruise-e2e-test runs kruise e2e tests. .PHONY: kruise-e2e-test diff --git a/scripts/generate_helm_crds.sh b/scripts/generate_helm_crds.sh new file mode 100755 index 0000000000..1ef60cdac4 --- /dev/null +++ b/scripts/generate_helm_crds.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Check if yq command is installed, otherwise install it +if ! command -v yq &> /dev/null; then + echo "yq command not found. You need install yq first." + exit 0 +fi + +rm -rf bin/templates +mkdir bin/templates + +# Get the current directory +current_dir=$(pwd) +echo $current_dir +# Create a temporary directory +temp_dir=$(mktemp -d) +echo $temp_dir + +kustomize build config/crd > $temp_dir/crds.yaml +cd $temp_dir +awk 'BEGIN {RS="\n---\n"} {print > ("output-" NR ".yaml")}' crds.yaml +rm -f crds.yaml + +# Process each file in the directory +for file in *; do + # Parse the YAML file and extract the value of the desired fields + group=$(yq eval '.spec.group' $file) + plural=$(yq eval '.spec.names.plural' $file) + + # Remove leading and trailing whitespace from the field values + group=$(echo $group | sed -e 's/^ *//' -e 's/ *$//') + plural=$(echo $plural | sed -e 's/^ *//' -e 's/ *$//') + + sed -i '.bak' '1i\ +{{- if .Values.crds.managed }}\ + \ +--- + ' $file + rm -f $file.bak + echo "{{- end }}" >> $file + # Rename the file using the extracted field values + mv $file "$current_dir/bin/templates/${group}_${plural}.yaml" +done + +# Clean up the temporary directory +cd .. +rm -rf $temp_dir