package cmii_operator

const cmiiBackendDeploymentTemplate = `
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .AppName }}
  namespace: {{ .Namespace }}
  labels:
    cmii.type: backend
    cmii.app: {{ .AppName }}
    octopus/control: backend-app-1.0.0
    app.kubernetes.io/managed-by: octopus/control
    app.kubernetes.io/app-version: {{ .TagVersion }}
spec:
  replicas: {{ .Replicas }}
  strategy:
    rollingUpdate:
      maxUnavailable: 1
  selector:
    matchLabels:
      cmii.type: backend
      cmii.app: {{ .AppName }}
  template:
    metadata:
      labels:
        cmii.type: backend
        cmii.app: {{ .AppName }}
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: uavcloud.env
                    operator: In
                    values:
                      - demo
      imagePullSecrets:
        - name: harborsecret
      containers:
        - name: {{ .AppName }}
          image: "harbor.cdcyy.com.cn/cmii/{{ .AppName }}:{{ .ImageTag }}"
          imagePullPolicy: Always
          env:
            - name: K8S_NAMESPACE
              value: "{{ .Namespace }}"
            - name: APPLICATION_NAME
              value: "{{ .AppName }}"
            - name: CUST_JAVA_OPTS
              value: "-Xms500m -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: {{ .TagVersion }}
            - name: SYS_CONFIG_GROUP
              value: {{ .TagVersion }}
            - name: IMAGE_VERSION
              value: {{ .TagVersion }}
            - name: NACOS_USERNAME
              value: "developer"
            - name: NACOS_PASSWORD
              value: "Deve@9128201"
          ports:
            - name: pod-port
              containerPort: 8080
              protocol: TCP
          resources:
             limits:
               memory: 2Gi
               cpu: 2
             requests:
               memory: 1Gi
               cpu: 200m
          livenessProbe:
            httpGet:
              path: /cmii/ping
              port: pod-port
              scheme: HTTP
            initialDelaySeconds: 60
            timeoutSeconds: 5
            periodSeconds: 20
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /cmii/ping
              port: pod-port
              scheme: HTTP
            initialDelaySeconds: 60
            timeoutSeconds: 5
            periodSeconds: 20
            successThreshold: 1
            failureThreshold: 3
          startupProbe:
            httpGet:
              path: /cmii/ping
              port: pod-port
              scheme: HTTP
            initialDelaySeconds: 60
            timeoutSeconds: 3
            periodSeconds: 20
            successThreshold: 1
            failureThreshold: 5
          volumeMounts:
            - name: glusterfs-backend-log-volume
              mountPath: /cmii/logs
              readOnly: false
              subPath: {{ .Namespace }}/{{ .AppName }}
      volumes:
        - name: glusterfs-backend-log-volume
          persistentVolumeClaim:
            claimName: glusterfs-backend-log-pvc
    `
