new set to create configmap

This commit is contained in:
Vaibhav Pathak 2026-01-21 19:48:35 +05:30
parent b887bf2919
commit d4eb33a02b

View File

@ -434,12 +434,6 @@ spec:
destination:
server: https://kubernetes.default.svc
namespace: $NAMESPACE
ignoreDifferences:
- group: ""
kind: ConfigMap
name: ${SANITIZED_SERVICE}-allhosts
jsonPointers:
- /data/allhosts.tsv
syncPolicy:
automated:
prune: true
@ -661,6 +655,33 @@ spec:
# kubectl is already available in this image
# Create allhosts ConfigMap for each hades service (if it doesn't exist)
echo "=== Creating allhosts ConfigMaps ==="
SERVICES_LIST=$(echo "$SERVICES" | tr ',' ' ')
for service in $SERVICES_LIST; do
service=$(echo "$service" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
# Check if this is a hades service
if echo "$service" | grep -qi "hades"; then
# Sanitize service name (same logic as ArgoCD app creation)
SANITIZED_SERVICE=$(echo "$service" | tr '[:upper:]' '[:lower:]' | tr ' _' '-' | sed 's/[^a-z0-9-]//g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//' | cut -c1-53)
CONFIGMAP_NAME="${SANITIZED_SERVICE}-allhosts"
echo "Checking ConfigMap: $CONFIGMAP_NAME"
# Create ConfigMap if it doesn't exist
if ! kubectl get configmap "$CONFIGMAP_NAME" -n "$NAMESPACE" > /dev/null 2>&1; then
echo " Creating allhosts ConfigMap: $CONFIGMAP_NAME"
kubectl create configmap "$CONFIGMAP_NAME" -n "$NAMESPACE" \
--from-literal="allhosts.tsv=Host Ipaddress HostGroup Team Type"
echo " ConfigMap created successfully"
else
echo " ConfigMap already exists: $CONFIGMAP_NAME"
fi
fi
done
echo ""
# Wait for pods to be created by ArgoCD (may take time to sync)
echo "Waiting for Hades MySQL pod to be created..."
MYSQL_POD=""
@ -915,8 +936,43 @@ spec:
# Get current content
CURRENT_CONTENT=$(kubectl get configmap "$CONFIGMAP_NAME" -n "$NAMESPACE" -o jsonpath='{.data.allhosts\.tsv}')
# Build new entries for each service
# Build new entries
NEW_ENTRIES=""
# Add node gateway IPs (pod CIDR gateways from all nodes)
echo "Adding node gateway IPs to ConfigMap..."
GATEWAY_COUNT=1
for gateway_ip in $COMMON_BRIDGE_IPS; do
[ -z "$gateway_ip" ] && continue
HOSTNAME="k8s-gateway-${GATEWAY_COUNT}.${NAMESPACE}.internal"
if ! echo "$CURRENT_CONTENT" | grep -q "${gateway_ip}"; then
NEW_ENTRY="${HOSTNAME}\t${gateway_ip}\tinfra\tplatform\tk8s.gateway"
NEW_ENTRIES="${NEW_ENTRIES}${NEW_ENTRY}\n"
echo " Adding gateway: $HOSTNAME -> $gateway_ip"
GATEWAY_COUNT=$((GATEWAY_COUNT + 1))
else
echo " Skipping (exists): $gateway_ip"
fi
done
# Add node internal IPs
echo "Adding node IPs to ConfigMap..."
NODE_COUNT=1
for node_ip in $NODE_IPS; do
[ -z "$node_ip" ] && continue
HOSTNAME="k8s-node-${NODE_COUNT}.${NAMESPACE}.internal"
if ! echo "$CURRENT_CONTENT" | grep -q "${node_ip}"; then
NEW_ENTRY="${HOSTNAME}\t${node_ip}\tinfra\tplatform\tk8s.node"
NEW_ENTRIES="${NEW_ENTRIES}${NEW_ENTRY}\n"
echo " Adding node: $HOSTNAME -> $node_ip"
NODE_COUNT=$((NODE_COUNT + 1))
else
echo " Skipping (exists): $node_ip"
fi
done
# Add service pod IPs
echo "Adding service pod IPs to ConfigMap..."
for service in $SERVICES_LIST; do
service=$(echo "$service" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
[ -z "$service" ] && continue