diff --git a/hack/generate_globalnode.sh b/hack/generate_globalnode.sh index 4862d47cd..cddea714a 100755 --- a/hack/generate_globalnode.sh +++ b/hack/generate_globalnode.sh @@ -5,20 +5,36 @@ if [ -z "$KUBECONFIG" ]; then exit 1 fi +# Creating a directory for logs +mkdir -p kube_apply_logs + nodes=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}') for node in ${nodes}; do nodeIP=$(kubectl get node ${node} -o jsonpath='{.status.addresses[0].address}') labels=$(kubectl get node ${node} -o jsonpath='{.metadata.labels}') - labelsFormatted=$(echo "$labels" | jq -r 'to_entries | .[] | " \(.key): \(.value)"') - echo " + + # Use jq to ensure all values are strings, but also explicitly add quotes in the YAML formatting step below + labelsFormatted=$(echo "$labels" | jq -r 'to_entries | map(.value |= tostring) | .[] | " \(.key): \"\(.value)\""') + + yamlContent=" apiVersion: kosmos.io/v1alpha1 kind: GlobalNode metadata: name: ${node} spec: + state: \"reserved\" nodeIP: \"${nodeIP}\" labels: -$(echo "${labelsFormatted}" | sed 's/=/": "/g' | awk '{print " " $0}') -" | kubectl apply -f - +$(echo "${labelsFormatted}" | awk '{print " " $0}') +" + + # Log the YAML content to a file for inspection + echo "$yamlContent" > kube_apply_logs/${node}.yaml + + # Apply the YAML + echo "$yamlContent" | kubectl apply -f - + + # clear resources + rm -rf kube_apply_logs done