with open('homelab-gitops-repo/manifests/spaceport/homepage/homepage.yaml', 'r', encoding='utf-8') as f: text = f.read() docs = text.split('---') # docs[0] = Deployment # docs[1] = Service # docs[2] = ConfigMap cm = docs[2] # Extract the footer footer_marker = "kind: ConfigMap" idx = cm.find(footer_marker) if idx != -1: footer = cm[idx:] body = cm[:idx] # Remove apiVersion: v1 from body body_clean = body.replace('apiVersion: v1\n', '') # Construct clean ConfigMap new_cm = f""" apiVersion: v1 {footer.strip()} {body_clean.strip()} """ docs[2] = new_cm new_text = '---'.join(docs) with open('homelab-gitops-repo/manifests/spaceport/homepage/homepage.yaml', 'w', encoding='utf-8') as f: f.write(new_text) print("Restructured homepage.yaml successfully!")