---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cmii-uav-watchdog
  namespace: uavcloud-prepro
  labels:
    cmii.type: backend
    cmii.app: cmii-uav-watchdog
    octopus/control: backend-app-1.0.0
    app.kubernetes.io/managed-by: octopus
    app.kubernetes.io/app-version: 6.2.0
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxUnavailable: 1
  selector:
    matchLabels:
      cmii.type: backend
      cmii.app: cmii-uav-watchdog
  template:
    metadata:
      labels:
        cmii.type: backend
        cmii.app: cmii-uav-watchdog
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: uavcloud.env
                    operator: In
                    values:
                      - demo
      imagePullSecrets:
        - name: harborsecret
      containers:
        - name: cmii-uav-watchdog
          image: harbor.cdcyy.com.cn/cmii/cmii-uav-watchdog:2025-04-10-15-24-03
          imagePullPolicy: Always
          env:
            - name: K8S_NAMESPACE
              value: uavcloud-prepro
            - name: APPLICATION_NAME
              value: cmii-uav-watchdog
            - name: CUST_JAVA_OPTS
              value: "-Xms200m -Xmx1500m -Dlog4j2.formatMsgNoLookups=true"
            - name: NACOS_REGISTRY
              value: "helm-nacos:8848"
            - name: NACOS_DISCOVERY_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: NACOS_DISCOVERY_PORT
              value: "8080"
            - name: BIZ_CONFIG_GROUP
              value: 6.2.0
            - name: SYS_CONFIG_GROUP
              value: 6.2.0
            - name: IMAGE_VERSION
              value: 6.2.0
            - name: NACOS_USERNAME
              value: "developer"
            - name: NACOS_PASSWORD
              value: "Deve@9128201"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: NODE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: LIMIT_CPU
              valueFrom:
                resourceFieldRef:
                  containerName: cmii-uav-watchdog
                  resource: limits.cpu
            - name: LIMIT_MEMORY
              valueFrom:
                resourceFieldRef:
                  containerName: cmii-uav-watchdog
                  resource: limits.memory
            - name: REQUEST_CPU
              valueFrom:
                resourceFieldRef:
                  containerName: cmii-uav-watchdog
                  resource: requests.cpu
            - name: REQUEST_MEMORY
              valueFrom:
                resourceFieldRef:
                  containerName: cmii-uav-watchdog
                  resource: requests.memory
          ports:
            - name: pod-port
              containerPort: 8080
              protocol: TCP
          resources:
            limits:
              memory: 2Gi
              cpu: "2"
            requests:
              memory: 200Mi
              cpu: 200m
          volumeMounts:
            - name: nfs-backend-log-volume
              mountPath: /cmii/cmii-uav-watchdog/
              readOnly: false
              subPath: uavcloud-prepro/cmii-uav-watchdog
            - name: cmii-uav-watchdog-conf
              mountPath: /cmii/cmii-uav-watchdog/config.yaml
              subPath: config.yaml
      volumes:
        - name: nfs-backend-log-volume
          persistentVolumeClaim:
            claimName: nfs-backend-log-pvc
        - name: cmii-uav-watchdog-conf
          configMap:
            name: cmii-uav-watchdog-configmap
            items:
              - key: config.yaml
                path: config.yaml
---
apiVersion: v1
kind: Service
metadata:
  name: cmii-uav-watchdog
  namespace: uavcloud-prepro
  labels:
    cmii.type: backend
    cmii.app: cmii-uav-watchdog
    octopus/control: backend-app-1.0.0
    app.kubernetes.io/managed-by: octopus
    app.kubernetes.io/app-version: 6.2.0
spec:
  type: NodePort
  selector:
    cmii.type: backend
    cmii.app: cmii-uav-watchdog
  ports:
    - name: backend-tcp
      port: 8080
      protocol: TCP
      targetPort: 8080
      nodePort: 34567
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: cmii-uav-watchdog-configmap
  namespace: uavcloud-prepro
data:
  config.yaml: |-
    server:
      port: "8080"  # 服务器端口
    
    tier_one_auth:
      tier_one_secret: "FNSVSHOJTMTWWS56QXXNTDEYLNWQTQLFWDJ3YRDODDEIGDSJRNUPETG6BOO6S4ITWFAEUOST2URXSF6VNADBTVTSK5NZUBDDAM5EFYI"  # TOTP密钥
      time_offset_allowed: 30  # 允许的时间偏移（秒）
    
    watchdog_center:
      url: "https://watchdog-center.example.com"  # 一级授权中心地址
    
    project:
      project_namespace: "uavcloud-prepro"  # 项目命名空间
    
    tier_two_auth:
      tier_two_secret: "your_tier_two_secret_here"  # 二级授权密钥