package c_middle

const CmiiNacosTemplate = `
apiVersion: v1
kind: ConfigMap
metadata:
  name: helm-nacos-cm
  namespace: {{ .Namespace }}
  labels:
    cmii.app: helm-nacos
    cmii.type: middleware
    octopus.control: nacos-wdd
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "{{ .TagVersion }}"
data:
  mysql.db.name: "cmii_nacos_config"
  mysql.db.host: "helm-mysql"
  mysql.port: "3306"
  mysql.user: "k8s_admin"
  mysql.password: "{{ .MySQLK8sAdminPassword }}"
---
apiVersion: v1
kind: Service
metadata:
  name: helm-nacos
  namespace: {{ .Namespace }}
  labels:
    cmii.app: helm-nacos
    cmii.type: middleware
    octopus.control: nacos-wdd
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "{{ .TagVersion }}"
spec:
  type: NodePort
  selector:
    cmii.app: helm-nacos
    cmii.type: middleware
  ports:
    - port: 8848
      name: server
      targetPort: 8848
      nodePort: {{ .NacosNodePort }}
    - port: 9848
      name: server12
      targetPort: 9848
    - port: 9849
      name: server23
      targetPort: 9849
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: helm-nacos
  namespace: {{ .Namespace }}
  labels:
    cmii.app: helm-nacos
    cmii.type: middleware
    octopus.control: nacos-wdd
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: "{{ .TagVersion }}"
spec:
  serviceName: helm-nacos
  replicas: 1
  selector:
    matchLabels:
      cmii.app: helm-nacos
      cmii.type: middleware
  template:
    metadata:
      labels:
        cmii.app: helm-nacos
        cmii.type: middleware
        octopus.control: nacos-wdd
        app.kubernetes.io/managed-by: octopus
        app.kubernetes.io/version: "{{ .TagVersion }}"
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      imagePullSecrets:
        - name: harborsecret
      affinity: {}
      containers:
        - name: nacos-server
          {{- if .HarborPort }}
          image: {{ .HarborIPOrCustomImagePrefix }}:{{ .HarborPort }}/cmii/nacos-server:v2.1.2
          {{- else }}
          image: {{ .HarborIPOrCustomImagePrefix }}nacos-server:v2.1.2
          {{- end }}
          ports:
            - containerPort: 8848
              name: dashboard
            - containerPort: 9848
              name: tcp-9848
            - containerPort: 9849
              name: tcp-9849
          env:
            - name: NACOS_AUTH_ENABLE
              value: "false"
            - name: NACOS_REPLICAS
              value: "1"
            - name: MYSQL_SERVICE_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: helm-nacos-cm
                  key: mysql.db.name
            - name: MYSQL_SERVICE_PORT
              valueFrom:
                configMapKeyRef:
                  name: helm-nacos-cm
                  key: mysql.port
            - name: MYSQL_SERVICE_USER
              valueFrom:
                configMapKeyRef:
                  name: helm-nacos-cm
                  key: mysql.user
            - name: MYSQL_SERVICE_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: helm-nacos-cm
                  key: mysql.password
            - name: MYSQL_SERVICE_HOST
              valueFrom:
                configMapKeyRef:
                  name: helm-nacos-cm
                  key: mysql.db.host
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: NACOS_APPLICATION_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: MODE
              value: standalone
            - name: SPRING_DATASOURCE_PLATFORM
              value: mysql
---
`
