Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry-pick: fix the bug of generate_globalnode.sh #541

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading