Skip to content

Commit

Permalink
Merge pull request kosmos-io#540 from duanmengkk/fix_bug
Browse files Browse the repository at this point in the history
fix the bug of generate_globalnode.sh
  • Loading branch information
duanmengkk authored May 13, 2024
2 parents 9311810 + ee66c0c commit 56fca2f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions hack/generate_globalnode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 56fca2f

Please sign in to comment.