#!/bin/bash
# Script to remove imagePullSecrets from all Kubernetes manifests
# Run this from the repository root: ./infrastructure/kubernetes/remove-imagepullsecrets.sh

echo "Removing imagePullSecrets from all Kubernetes manifests..."

# Find all YAML files in base directory and remove imagePullSecrets
find infrastructure/kubernetes/base -name "*.yaml" -type f | while read file; do
  # Create backup
  cp "$file" "$file.bak"

  # Remove imagePullSecrets and the following line (name: dockerhub-creds)
  sed -i '/imagePullSecrets:/,+1d' "$file"

  echo "Processed: $file"
done

echo ""
echo "✅ Done! Removed imagePullSecrets from all manifests"
echo "Backup files created with .bak extension"
echo ""
echo "Verify removal:"
grep -r "imagePullSecrets" infrastructure/kubernetes/base/ && echo "⚠️  WARNING: Some files still contain imagePullSecrets" || echo "✅ All imagePullSecrets removed successfully"
