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

kubenest deployment script #701

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions hack/k8s-in-k8s/gen-globalnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export KUBECONFIG=host-config
bash generate_globalnode.sh
kubectl get globalnodes
41 changes: 41 additions & 0 deletions hack/k8s-in-k8s/generate_globalnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

if [ -z "$KUBECONFIG" ]; then
echo "KUBECONFIG环境变量未设置."
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}')

# 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}" | 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

done
rm -rf kube_apply_logs

2 changes: 1 addition & 1 deletion hack/k8s-in-k8s/globalnodes_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ case "$1" in
*)
echo $"usage: $0 free|reserved"
exit 1
esac
esac
Loading
Loading