-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add crd install as flag for values.yaml
- Loading branch information
1 parent
1a66bf1
commit 224a936
Showing
5 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import yaml | ||
import sys | ||
|
||
|
||
if len(sys.argv) != 3: | ||
print("Missing arguments: inputFile outputDir") | ||
sys.exit(1) | ||
|
||
# Input and output file names | ||
INPUT_FILE = sys.argv[1] | ||
OUTPUT_DIR = sys.argv[2] | ||
|
||
# Read and split CRDs by "---" | ||
with open(INPUT_FILE, "r") as file: | ||
crd_docs = list(yaml.safe_load_all(file)) | ||
|
||
# Process each CRD separately | ||
modified_crds = [] | ||
for crd in crd_docs: | ||
if not isinstance(crd, dict): | ||
continue # Skip empty sections | ||
|
||
# Ensure metadata and annotations exist | ||
metadata = crd.setdefault("metadata", {}) | ||
annotations = metadata.setdefault("annotations", {}) | ||
|
||
# Inject Helm annotations | ||
# annotations["helm.sh/resource-policy"] = "keep" | ||
|
||
# Convert CRD back to YAML | ||
crd_yaml = yaml.dump(crd, default_flow_style=False, sort_keys=False) | ||
|
||
fixedYaml = "" | ||
for line in crd_yaml.splitlines(): | ||
# if line.strip() == "helm.sh/resource-policy: keep": | ||
# print("Modify line:", line) | ||
# fixedYaml += " " + "{{- if .Values.crds.keep }}" + "\n" | ||
# fixedYaml += line + "\n" | ||
# fixedYaml += " " + "{{- end}}" + "\n" | ||
# continue | ||
|
||
fixedYaml += line + "\n" | ||
|
||
# Wrap with Helm conditional for each CRD | ||
wrapped_yaml = f"""{{{{- if .Values.crds.install }}}} | ||
{fixedYaml} | ||
{{{{- end }}}} | ||
""" | ||
modified_crds.append( | ||
{"name": crd["spec"]["names"]["kind"], "content": wrapped_yaml} | ||
) | ||
|
||
# Save the modified CRD YAML | ||
for i in range(len(modified_crds)): | ||
with open("%s/%s.yaml" % (OUTPUT_DIR, modified_crds[i]["name"]), "w") as file: | ||
file.write(modified_crds[i]["content"]) | ||
|
||
print("Modified CRD file saved as", modified_crds[i]["name"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
namespace: "{{ .Release.Namespace }}" | ||
namePrefix: '{{ .Release.Name }}-' | ||
namePrefix: "{{ .Release.Name }}-" | ||
|
||
resources: | ||
- ../rbac | ||
- ../rbac |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters