#!/bin/bash
#***************************************************************#
# ScriptName: opsk8spod.sh
# Author: xhy
# Create Date: 2025-03-23 23:10
# Modify Author: xhy
# Modify Date: 2025-03-23 23:34
# Version: v1
#***************************************************************#


OPSIMAGE="uhub.service.ucloud.cn/imxhy/netshoot:latest"
NAMESPACE=monitoring

kubectl delete pod opstestpod -n $NAMESPACE --ignore-not-found >/dev/null 2>&1

cat > opstestpod.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: opstestpod
  namespace: ${NAMESPACE}
spec:
  containers:
  - name: opstestpod
    image: ${OPSIMAGE}
    command: ["/bin/bash", "-c", "--"]
    args: ["while true; do sleep 86400; done"]
    stdin: true
    tty: true 
    securityContext:
      capabilities:
        add: ["NET_ADMIN", "SYS_PTRACE"]
  tolerations:
    - key: node-role.kubernetes.io/control-plane
      operator: Exists
      effect: NoSchedule   
EOF

kubectl apply -f opstestpod.yaml || exit 1

echo -e "\n\033[32m[INFO] 等待Pod启动... \033[0m"

until kubectl -n $NAMESPACE get pod opstestpod -o jsonpath='{.status.phase}' | grep -q Running; do
  sleep 1
  echo -n "."
done

echo -e "\n\033[32m[SUCC] Pod启动成功... \033[0m"

kubectl -n ${NAMESPACE} exec -ti opstestpod -- bash

