-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-templates.sh
More file actions
executable file
·55 lines (44 loc) · 1.78 KB
/
generate-templates.sh
File metadata and controls
executable file
·55 lines (44 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Generate Helm templates from CRDs by copying full CRDs and replacing labels/annotations with templating
CRDS_DIR="crds"
CHART_DIR="chart"
TEMPLATES_DIR="$CHART_DIR/templates"
mkdir -p "$TEMPLATES_DIR"
# Process each CRD file
for crd_file in "$CRDS_DIR"/*.yaml; do
base_name=$(basename "$crd_file")
echo "Processing $base_name..."
# Extract CRD name for templating
crd_name=$(yq eval '.metadata.name' "$crd_file")
# Create a proper Helm template by manually constructing it
{
# Start with the document separator and API info
echo "---"
echo "apiVersion: $(yq eval '.apiVersion' "$crd_file")"
echo "kind: $(yq eval '.kind' "$crd_file")"
# Start metadata section
echo "metadata:"
echo " name: $crd_name"
# Add Helm templating for labels
echo " labels:"
echo "{{- include \"velero-crds.labels\" . | nindent 4 }}"
echo "{{- \$crdKey := printf \"%s\" \"$crd_name\" | replace \".\" \"_\" }}"
echo "{{- if .Values.crds }}"
echo "{{- with (index .Values.crds \$crdKey).metadata.labels }}"
echo "{{- toYaml . | nindent 4 }}"
echo "{{- end }}"
echo "{{- end }}"
# Add Helm templating for annotations
echo " annotations:"
echo "{{- if .Values.crds }}"
echo "{{- with (index .Values.crds \$crdKey).metadata.annotations }}"
echo "{{- toYaml . | nindent 4 }}"
echo "{{- end }}"
echo "{{- end }}"
# Copy the spec section as-is
echo "spec:"
yq eval '.spec' "$crd_file" | sed 's/^/ /'
} > "$TEMPLATES_DIR/$base_name"
echo " -> Created $TEMPLATES_DIR/$base_name with Helm templating"
done
echo "Template generation complete!"