apiVersion: v1
data:
  key-service.yaml: |-
    Name: key.rpc
    ListenOn: 0.0.0.0:8083
    
    # 当前服务请求超时时间是 30s
    Timeout: 30000
    
    # 环境:dev、test、pre、prod
    Mode: prod
    
    Log:
      # 服务名称
      ServiceName: key-service
      # 日志输出到文件
      Mode: file
      # 日志输出文件路径
      Path: logs
      # 日志级别
      Level: info
      # 是否压缩日志
      Compress: true
      # 日志保留天数,只有在文件模式才会生效
      KeepDays: 30
      # 按天切割日志
      Rotation: daily
    
    # 监控,默认都是开启,主要调整端口和监控访问路由
    DevServer:
      Port: 6063
      HealthPath: "/health"
      MetricsPath: "/metrics"
    
    # grpc 通信服务端证书私钥
    GrpcConf:
      #CaCertFile: ./cert/ca/ca.pem
      #ServerCertFile: ./cert/key-service/server.pem
      #ServerKeyFile: ./cert/key-service/server.key
      
      CaCertFile: ""
      ServerCertFile: ""
      ServerKeyFile: ""
      # 接收、发送消息大小设置为 20 mb,根据服务实际场景调整
      MaxRecvMsgSize: 20971520
      MaxSendMsgSize: 20971520
    
    MysqlConf:
      DNS: root:root123456@tcp(mysql.public.svc.cluster.local:3306)/keyservice?charset=utf8&parseTime=true&loc=Asia%2FShanghai
      # 最大连接时间,防止使用无效的连接,单位:s
      MaxLifetime: 500
      # 空闲连接池中连接的最大数量
      MaxIdleConns: 10
      # 数据库连接的最大数量
      MaxOpenConns: 10
      # string 类型字段的默认长度
      DefaultStringSize: 256
      # 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
      DisableDatetimePrecision: true
      # 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
      DontSupportRenameIndex: true
      # 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
      DontSupportRenameColumn: true
      # 根据当前 MySQL 版本自动配置
      SkipInitializeWithVersion: false
    
    # 私钥证书等加密存储的 aes 秘钥,长度 16、24、32
    AESKey: GVQDSaJW5YKJHGDF
    
    # 地址格式
    AddressType: ethereum
    
    ContractName: ida
    
    # chain-service 服务通信配置
    ChainServiceConf:
      #ClientCertFile: ./cert/chain-service/client.pem
      #ClientKeyFile: ./cert/chain-service/client.key
      #CaCertFile: ./cert/ca/ca.pem
      ClientCertFile: ""
      ClientKeyFile: ""
      CaCertFile: ""
      DNS: localhost
      Endpoint: chain.public.svc.cluster.local:8081
kind: ConfigMap
metadata:
  name: key-cnf
  namespace: public

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: key
  namespace: public
spec:
  capacity:
    storage: 200Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: public-storage-sc
  local:
    path: /mnt/data/public/key/logs
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - k8s-node1

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: key
  namespace: public
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 200Mi
  storageClassName: public-storage-sc
  volumeName: key

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: key
  namespace: public
spec:
  replicas: 1
  selector:
    matchLabels:
      app: public
      deployment: key
  template:
    metadata:
      labels:
        app: public
        deployment: key
    spec:
      initContainers:
        - name: wait-for-mysql-service
          image: busybox:1.28
          command:
            - /bin/sh
            - -c
            - |
              until nslookup mysql.public.svc.cluster.local; do
                echo "waiting for mysql-service"
                sleep 2
              done
        - name: init-mysql
          image: mysql:8.0
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-root-pass
                  key: password
          command:
            - bash
            - "-c"
            - |
              echo "CREATE DATABASE /*!32312 IF NOT EXISTS*/ \`keyservice\` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;" > /init.sql
              until mysql -h mysql.public.svc.cluster.local -P 3306 -u root -p$MYSQL_ROOT_PASSWORD -e "source /init.sql"; do
                echo "waiting for mysql"
                sleep 2
              done
      containers:
        - name: key
          image: 192.168.1.181:5000/ida/assets-keyservice-8da5993:0.0.1
          ports:
            - containerPort: 8083
          volumeMounts:
            - name: logs-storage
              mountPath: /key-service/logs
            - name: cnf-storage
              mountPath: /key-service/etc
      volumes:
        - name: logs-storage
          persistentVolumeClaim:
            claimName: key
        - name: cnf-storage
          configMap:
            name: key-cnf

---

apiVersion: v1
kind: Service
metadata:
  name: key
  namespace: public
spec:
  selector:
    app: public
    deployment: key
  ports:
    - protocol: TCP
      port: 8083 # Dockerfile EXPOSE 8080
      targetPort: 8083 # Pod containerPort
  #      nodePort: 31083
  type: ClusterIP