Feature 11055: Update cluster configuration to support the feature
Change-Id: I7a92c29a943d8767524ed40636eb204bd4ec2718
Signed-off-by: rshri <shrinithi.r@tataelxsi.co.in>
diff --git a/docker/osm-krm-functions/scripts/library/helper-functions.rc b/docker/osm-krm-functions/scripts/library/helper-functions.rc
index f5e4a55..03614d1 100644
--- a/docker/osm-krm-functions/scripts/library/helper-functions.rc
+++ b/docker/osm-krm-functions/scripts/library/helper-functions.rc
@@ -379,6 +379,47 @@
"| select(.kind == \"Kustomization\") | select(.metadata.name == \"${KUSTOMIZATION_NAME}\")"
}
+function patch_add_value_as_list() {
+ local KEY_PATH="$1"
+ local VALUE="$2"
+ local TARGET_FILTERS="${3:-}"
+
+ yq "(.items[]${TARGET_FILTERS})${KEY_PATH} += [${VALUE}]"
+}
+
+function add_patch_to_kustomization_as_list() {
+ local KUSTOMIZATION_NAME="$1"
+ local PATCH_VALUE="$2"
+
+ local VALUE_AS_JSON=$(echo "$PATCH_VALUE" | yq -o json -I0)
+
+ patch_add_value_as_list \
+ ".spec.patches" \
+ "${VALUE_AS_JSON}" \
+ "| select(.kind == \"Kustomization\") | select(.metadata.name == \"${KUSTOMIZATION_NAME}\")"
+}
+
+function add_component_to_kustomization_as_list() {
+ local KUSTOMIZATION_NAME="$1"
+ shift
+ local COMPONENT=("$@")
+
+ local COMPONENT_JSON=$(printf '"%s",' "${COMPONENT[@]}" | sed 's/,$//')
+
+ patch_add_value_as_list \
+ ".spec.components" \
+ "${COMPONENT_JSON}" \
+ "| select(.kind == \"Kustomization\") | select(.metadata.name == \"${KUSTOMIZATION_NAME}\")"
+}
+
+function add_config_to_kustomization() {
+ local KUSTOMIZATION_NAME="$1"
+
+ yq '
+ (.items[] | select(.kind == "Kustomization") | select(.metadata.name == "'"${KUSTOMIZATION_NAME}"'"))
+ .spec.postBuild.substituteFrom = [{"kind": "ConfigMap", "name": "'"${KUSTOMIZATION_NAME}"'-parameters"}]
+ '
+}
# Helper function to produce a JSON Patch as specified in RFC 6902
function as_json_patch() {