#
# Optional: reduces repetition.
#
apiVersion: v1
kind: ConfigMap
metadata:
  name: common
data:
  METRICS_CONFIG_DIR: cfg/
  LOG_DIR: /opt/kx/logs
  KXI_LOG_FORMAT: text
  KXI_LOG_LEVELS: default:trace
  KDB_LICENSE_B64: ${kdb-licence}
---
apiVersion: v1
kind: Service
metadata:
  name: sggw
spec:
  type: NodePort
  ports:
  - name: qipc
    protocol: TCP
    port: 30000
    nodePort: 30000
  - name: http
    protocol: TCP
    port: 30010
    nodePort: 30010
  selector:
    app: sggw
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sggw
  namespace: default
  labels:
    app: sggw
  creationTimestamp: null
spec:
  replicas: 5
  selector:
    matchLabels:
      app: sggw
  template:
    metadata:
      labels:
        app: sggw
    spec:
      containers:
      - name: sggw
        image: ${registry}/kxi-sg-gw:${sg_version}
        imagePullPolicy: IfNotPresent
        tty: true
        stdin: true
        envFrom:
        - configMapRef:
            name: common
        env:
        - name: GATEWAY_QIPC_PORT
          value: "30000"
        - name: GATEWAY_HTTP_PORT
          value: "30010"
        - name: KXI_ASSEMBLY_FILE
          value: /opt/kx/cfg/${assembly_file_yaml}
        volumeMounts:
        - mountPath: /opt/kx/cfg
          name: cfg-mount
      volumes:
      - name: cfg-mount
        hostPath:
          path: ${cfg_dir}
---
apiVersion: v1
kind: Service
metadata:
  name: sgrc
spec:
  ports:
  - protocol: TCP
    port: 5050
    targetPort: 5050
  selector:
    app: sgrc
---
apiVersion: v1
kind: Pod
metadata:
  name: sgrc
  namespace: default
  labels:
    app: sgrc
  creationTimestamp: null
  #
  # Optional: To register with multi-RC Kubernetes discovery.
  #
  annotations:
    kxi-kdisc: "sgrc: sc=KXI-SG-RC port=5050"
spec:
  containers:
  - name: sgrc
    image: ${registry}/kxi-sg-rc:${sg_version}
    imagePullPolicy: IfNotPresent
    tty: true
    stdin: true
    args: [ "-p", "5050" ]
    envFrom:
    - configMapRef:
        name: common
    env:
    - name: KXI_NAME
      value: sg_rc
    - name: KXI_PORT
      value: "5050"
    - name: KXI_ASSEMBLY_FILE
      value: /opt/kx/cfg/assembly/{assembly_file_yaml}
    - name: KXI_SG_DISC
      value: kubernetes
    ports:
    - name: sgrc
      containerPort: 5050
      protocol: TCP
    volumeMounts:
    - mountPath: /opt/kx/cfg
      name: cfg-mount
  volumes:
  - name: cfg-mount
    hostPath:
      path: ${cfg_dir}
  #
  # Optional: RC sidecar, if using discovery.
  #
  - name: rcsidecar
    image: ${registry}/kxi_sidecar:${sidecar_version}
    imagePullPolicy: IfNotPresent
    tty: true
    stdin: true
    args: [ "-p", "8080" ]
    envFrom:
    - configMapRef:
        name: common
    env:
    - name: KXI_CONFIG_FILE
      value: /opt/kx/cfg/{rc_sidecar_config_json}
    ports:
    - name: rcsidecar
      containerPort: 8080
      protocol: TCP
    volumeMounts:
    - mountPath: /opt/kx/cfg
      name: cfg-mount
  volumes:
  - name: cfg-mount
    hostPath:
      path: ${cfg_dir}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sgagg
  namespace: default
  creationTimestamp: null
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sgagg
  template:
    metadata:
      labels:
        app: sgagg
    spec:
      containers:
      - name: sgagg
        image: ${registry}/kxi-sg-agg:${sg_version}
        imagePullPolicy: IfNotPresent
        tty: true
        stdin: true
        args: [ "-p", "5060" ]
        envFrom:
        - configMapRef:
            name: common
        env:
        - name: KXI_NAME
          value: sg_agg
        - name: KXI_PORT
          value: "5060"
        - name: KXI_ASSEMBLY_FILE
          value: /opt/kx/cfg/assembly/${assembly_file_yaml}
        - name: KXI_SG_RC_ADDR
          value: sgrc:5050
        #
        # Optional: if loading custom aggregation functions.
        #
        - name: KXI_CUSTOM_FILE
          value: /opt/kx/custom/{custom_agg_code}.q
        volumeMounts:
        - mountPath: /opt/kx/cfg
          name: cfg-mount
        #
        # Optional: if loading custom aggregation functions.
        #
        - mountPath: /opt/kx/custom
          name: custom-mount
      volumes:
      - name: cfg-mount
        hostPath:
          path: ${cfg_dir}
      #
      # Optional: if loading custom aggregation functions.
      #
      - name: custom-mount
        hostPath:
          path: ${custom_dir}
---
#
# Optional: Discovery + proxy. Can be omitted if not using discovery.
#
apiVersion: v1
kind: Service
metadata:
  name: eureka
spec:
  ports:
  - protocol: TCP
    port: 9000
    targetPort: 8761
  selector:
    app: eureka
---
apiVersion: v1
kind: Pod
metadata:
  name: eureka
  namespace: default
  labels:
    app: eureka
  creationTimestamp: null
spec:
  containers:
  - name: eureka
    image: ${registry}/kxi-eureka-discovery:${discovery_version}
    imagePullPolicy: IfNotPresent
    ports:
    - name: eureka
      containerPort: 8761
      protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: proxy
spec:
  ports:
  - protocol: TCP
    port: 4000
    targetPort: 4000
  selector:
    app: proxy
---
apiVersion: v1
kind: Pod
metadata:
  name: proxy
  namespace: default
  labels:
    app: proxy
  creationTimestamp: null
spec:
  containers:
  - name: eureka
    image: ${registry}/kxi-discovery-proxy:${discovery_version}
    imagePullPolicy: IfNotPresent
    args: [ "-p", "4000" ]
    ports:
    - name: proxy
      containerPort: 4000
      protocol: TCP
    envFrom:
    - configMapRef:
        name: common
    env:
    - name: KXI_CONFIG_FILE
      value: /opt/kx/cfg/${proxy_config_json}
    - name: KDB_LICENSE_B64=${kdb-licence}
    volumeMounts:
    - mountPath: /opt/kx/cfg
      name: cfg-mount
  volumes:
  - name: cfg-mount
    hostPath:
      path: ${cfg_dir}
