Added local custom manifests

This feature introduces support for creating local
custom manifest files without losing visibility
of new updates. It ensures flexibility for local
customization while maintaining alignment
with official changes

Test Plan:

- PASS: Build package with specific custom manifest
directory (/custom-manifests)
- PASS: Execute build-helm-charts.sh
- PASS: Compare diffs between official and merged manifests

Change-Id: Ifbdb14e30e8ecccba6b6f7a93ce0914247c7c71d
Signed-off-by: jbarboza <joaopedro.barbozalioneza@windriver.com>
This commit is contained in:
jbarboza
2024-11-07 17:42:24 -03:00
committed by João Pedro Barboza Lioneza
parent 15cc010032
commit 35526f8f69
2 changed files with 73 additions and 0 deletions

View File

@@ -302,9 +302,34 @@ function build_application_tarball_armada {
fi
}
function compare_custom_manifests {
MANIFEST_LIST=$1
for manifest in ${MANIFEST_LIST}; do
MAIN_MANIFESTS=$(ls usr/lib/fluxcd/${manifest})
CUSTOM_MANIFESTS=$(ls usr/lib/fluxcd/custom-manifests/${manifest})
for manifest_file in ${MAIN_MANIFESTS}; do
if [ ! -f usr/lib/fluxcd/custom-manifests/${manifest}/${manifest_file} ]; then
echo "Warning: missing ${manifest_file} in custom manifests"
else
${PYTHON_2_OR_3} $BUILD_HELM_CHARTS_DIR/merge_manifests.py usr/lib/fluxcd/${manifest}/${manifest_file} usr/lib/fluxcd/custom-manifests/${manifest}/${manifest_file}
fi
done
done
}
function build_application_tarball_fluxcd {
FLUXCD_MANIFEST_DIR='fluxcd-manifests'
CUSTOM_MANIFEST_LIST=$(ls usr/lib/fluxcd/custom-manifests)
if [ ${#CUSTOM_MANIFEST_LIST} -ne 0 ]; then
echo "Custom manifests detected. Merging custom manifests with FluxCD manifests"
compare_custom_manifests "${CUSTOM_MANIFEST_LIST}"
# Removing custom manifests directory to prevent unnecessary files from being included
rm -rd usr/lib/fluxcd/custom-manifests
fi
# Stage all the fluxcd manifests
cp -R usr/lib/fluxcd staging/${FLUXCD_MANIFEST_DIR}

View File

@@ -0,0 +1,48 @@
#!/usr/bin/python
#
# Copyright (c) 2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import os
import sys
import ruamel.yaml as yaml
def merge_dicts(main: dict, custom: dict) -> None:
for key, value in custom.items():
if key in main and isinstance(main[key], dict) and isinstance(value, dict):
merge_dicts(main[key], value)
else:
main[key] = value
def handle_manifests_merge(main_manifests_path: str, custom_manifests_path: str):
with open(main_manifests_path, 'r') as main_file, open(custom_manifests_path, 'r') as custom_file:
main_data = yaml.safe_load(main_file)
custom_data = yaml.safe_load(custom_file)
# If both main file data and custom data are identical, no merge is needed
if main_data == custom_data:
return
# Handle empty YAML files as empty dictionaries for comparison purposes
main_data = {} if main_data is None else main_data
custom_data = {} if custom_data is None else custom_data
merged_data = main_data.copy()
merge_dicts(merged_data, custom_data)
with open(main_manifests_path, 'w') as main_file:
yaml.dump(merged_data, main_file, default_flow_style=False)
if __name__ == "__main__":
main_manifests_path = sys.argv[1]
custom_manifests_path = sys.argv[2]
try:
handle_manifests_merge(main_manifests_path, custom_manifests_path)
except Exception as e:
print(f"Error trying to merge {main_manifests_path}: {e}")
sys.exit(1)