Skip to content

Commit

Permalink
add generate helm crds scripts (#1525)
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
  • Loading branch information
zmberg committed Jun 18, 2024
1 parent bbb2d26 commit 837b671
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions scripts/generate_helm_crds.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 837b671

Please sign in to comment.