diff --git a/tools/nocloud-factory-install/factory-install/setup/10-system-setup b/tools/nocloud-factory-install/factory-install/setup/10-system-setup index 557002bc..08faeca2 100755 --- a/tools/nocloud-factory-install/factory-install/setup/10-system-setup +++ b/tools/nocloud-factory-install/factory-install/setup/10-system-setup @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (c) 2024 Wind River Systems, Inc. +# Copyright (c) 2024-2025 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -17,15 +17,48 @@ echo "Ready - host goenabled" system_mode=$(awk -F= '/system_mode/ {print $2}' /etc/platform/platform.conf) +# Get namespace from deployment config +# Using the default namespace if fail to it +system_ns=$(python3 << 'EOF' +import yaml +import os + +try: + if os.path.exists('/home/sysadmin/dm-playbook-overrides.yaml'): + with open('/home/sysadmin/dm-playbook-overrides.yaml') as f: + override_data = yaml.safe_load(f) + config_file = override_data.get('deployment_config') + + if config_file and os.path.exists(config_file): + with open(config_file) as f: + docs = list(yaml.safe_load_all(f)) + sys_doc = next((d for d in docs if d and d.get('kind') == 'System'), None) + + if sys_doc and 'metadata' in sys_doc: + namespace = sys_doc['metadata'].get('namespace') + if namespace: + print(namespace) +except: + pass +EOF +) + +# Default to deployment if namespace not found +# The host ns must be allocated in the same namespace of the system +if [ -z "$system_ns" ]; then + echo "Warning: Namespace not found from existing config files, using default namespace 'deployment'" + system_ns="deployment" +fi + echo "Wait - system deployment reconciled" while true; do if [ "$system_mode" = "duplex" ]; then SYSTEM_RECONCILED=true else - SYSTEM_RECONCILED=$(kubectl --kubeconfig=/etc/kubernetes/admin.conf -n deployment get system -o jsonpath='{.items[0].status.reconciled}') + SYSTEM_RECONCILED=$(kubectl --kubeconfig=/etc/kubernetes/admin.conf -n "$system_ns" get system -o jsonpath='{.items[0].status.reconciled}') fi - HOST_RECONCILED=$(kubectl --kubeconfig=/etc/kubernetes/admin.conf -n deployment get host controller-0 -o jsonpath='{.status.reconciled}') + HOST_RECONCILED=$(kubectl --kubeconfig=/etc/kubernetes/admin.conf -n "$system_ns" get host controller-0 -o jsonpath='{.status.reconciled}') if [ "$SYSTEM_RECONCILED" = true ] && [ "$HOST_RECONCILED" = true ]; then break diff --git a/tools/nocloud-factory-install/factory-install/systemd/utils/disable-factory-install b/tools/nocloud-factory-install/factory-install/systemd/utils/disable-factory-install index add4369b..bce95bc9 100644 --- a/tools/nocloud-factory-install/factory-install/systemd/utils/disable-factory-install +++ b/tools/nocloud-factory-install/factory-install/systemd/utils/disable-factory-install @@ -1,13 +1,54 @@ #!/bin/bash # -# Copyright (c) 2024 Wind River Systems, Inc. +# Copyright (c) 2024-2025 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # # script to disable the factory install services after the installation is complete # -echo "Disabling factory install services" +log_info() { echo "$(date '+%F %H:%M:%S') INFO: $*"; } +log_warn() { echo "$(date '+%F %H:%M:%S') WARN: $*"; } + +log_info "Disabling factory install services" + +# Delete System CRs from cluster +# Using the default namespace if fail to it +system_ns=$(python3 << 'EOF' +import yaml +import os + +try: + if os.path.exists('/home/sysadmin/dm-playbook-overrides.yaml'): + with open('/home/sysadmin/dm-playbook-overrides.yaml') as f: + override_data = yaml.safe_load(f) + config_file = override_data.get('deployment_config') + + if config_file and os.path.exists(config_file): + with open(config_file) as f: + docs = list(yaml.safe_load_all(f)) + sys_doc = next((d for d in docs if d and d.get('kind') == 'System'), None) + + if sys_doc and 'metadata' in sys_doc: + namespace = sys_doc['metadata'].get('namespace') + if namespace: + print(namespace) +except: + pass +EOF +) + +# Default to deployment if namespace not found +if [ -z "$system_ns" ]; then + log_warn "Namespace not found from existing config files, using default namespace 'deployment'" + system_ns="deployment" +fi + +log_info "Deleting all System CRs in namespace $system_ns" +kubectl_output=$(kubectl --kubeconfig=/etc/kubernetes/admin.conf delete system --all -n "$system_ns" 2>&1) +if [ $? -ne 0 ]; then + log_warn "Failed to delete System CRs: $kubectl_output" +fi rm -f /var/lib/factory-install/enabled rm -f /etc/systemd/system-preset/20-factory-install.preset