From 6703924d5a3703f71e967adba8a28e170a03a05c Mon Sep 17 00:00:00 2001 From: ties Date: Tue, 27 Aug 2024 08:46:51 +0000 Subject: [PATCH] Add createHelmYaml.sh --- createHelmYaml.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 createHelmYaml.sh diff --git a/createHelmYaml.sh b/createHelmYaml.sh new file mode 100644 index 0000000..6483331 --- /dev/null +++ b/createHelmYaml.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Load values from Chart.yaml +chart_version=$(yq e '.version' Chart.yaml) +chart_name=$(yq e '.name' Chart.yaml) +chart_repo=$(yq e '.dependencies[0].repository' Chart.yaml) +chart_namespace=$(yq e '.annotations.namespace' Chart.yaml) + +# Determine the correct chart and repo values based on chart_repo +if [[ $chart_repo == oci://* ]]; then + chart="${chart_repo}/${chart_name}" +else + repo="$chart_repo" + chart="$chart_name" +fi + +# Load the raw content of values.yaml +values_content=$(cat values.yaml) + +# Create HelmChart content in a variable +helm_chart_yaml=$(yq eval -n ".apiVersion = \"helm.cattle.io/v1\" | + .kind = \"HelmChart\" | + .metadata.name = \"$chart_name\" | + .metadata.namespace = \"$chart_namespace\" | + .spec.chart = \"$chart\" | + .spec.version = \"$chart_version\" | + .spec.targetNamespace = \"$chart_namespace\" | + .spec.valuesContent = \"$values_content\"") + +# If repo is set, add it to the spec +if [[ -n "$repo" ]]; then + helm_chart_yaml=$(echo "$helm_chart_yaml" | yq eval ".spec.repo = \"$repo\"") +fi + +# Print the final YAML to stdout +echo "$helm_chart_yaml" \ No newline at end of file