---
apiVersion: v1
kind: Service
metadata:
  name: kxinsights-hdb-da
  labels:
    app.kubernetes.io/name: hdb-da
    app.kubernetes.io/instance: kxinsights
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: 5080
      targetPort: hdb-da
      protocol: TCP
      name: hdb-da
  selector:
    app.kubernetes.io/name: hdb-da
    app.kubernetes.io/instance: kxinsights
---
apiVersion: v1
kind: Service
metadata:
  name: kxinsights-resource-coordinator
  labels:
    app.kubernetes.io/name: resource-coordinator
    app.kubernetes.io/instance: kxinsights
spec:
  type: ClusterIP
  ports:
    - port: 5060
      targetPort: resource-coordi
      protocol: TCP
      name: resource-coordi
  selector:
    app.kubernetes.io/name: resource-coordinator
    app.kubernetes.io/instance: kxinsights
---
apiVersion: v1
kind: Service
metadata:
  name: kxinsights-aggregator
  labels:
    app.kubernetes.io/name: aggregator
    app.kubernetes.io/instance: kxinsights
spec:
  type: ClusterIP
  ports:
    - port: 5070
      targetPort: aggregator
      protocol: TCP
      name: aggregator
  selector:
    app.kubernetes.io/name: aggregator
    app.kubernetes.io/instance: kxinsights
---
apiVersion: v1
kind: Service
metadata:
  name: kxinsights-sg-gateway
  labels:
    app.kubernetes.io/name: sg-gateway
    app.kubernetes.io/instance: kxinsights
spec:
  type: LoadBalancer
  ports:
  ports:
    - name: http-port
      protocol: TCP
      port: 8080
      targetPort: 8080
    - name: ipc-port
      protocol: TCP
      port: 5050
      targetPort: 5050
  selector:
    app.kubernetes.io/name: sg-gateway
    app.kubernetes.io/instance: kxinsights
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kxinsights-aggregator
  labels:
    app.kubernetes.io/name: aggregator
    app.kubernetes.io/instance: kxinsights
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: aggregator
      app.kubernetes.io/instance: kxinsights
  template:
    metadata:
      labels:
        app.kubernetes.io/name: aggregator
        app.kubernetes.io/instance: kxinsights
    spec:
      serviceAccountName: kxinsights-aggregator
      securityContext:
        {}
      containers:
        - name: aggregator
          args: [ -p, "5070" ]
          securityContext:
            {}
          image: registry.dl.kx.com/kxi-sg-agg:1.1.0
          imagePullPolicy: IfNotPresent
          env:
            - name: KDB_LICENSE_B64
              valueFrom:
                secretKeyRef:
                  name: kx-license-info
                  key: license
            - name: KXI_ASSEMBLY_FILE
              value: /opt/kx/config/assembly.yaml
            - name: KXI_SG_RC_ADDR
              value: kxinsights-resource-coordinator.default.svc:5060
          ports:
            - name: aggregator
              containerPort: 5070
              protocol: TCP
          resources:
            {}
          volumeMounts:
            - name: assemblyconfig
              mountPath: /opt/kx/config/assembly.yaml
              subPath: assembly.yaml
      imagePullSecrets:
        - name: kx-repo-access
      volumes:
      - name: assemblyconfig
        configMap:
          name: kxinsights-gw-assembly-configmap
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kxinsights-resource-coordinator
  labels:
    app.kubernetes.io/name: resource-coordinator
    app.kubernetes.io/instance: kxinsights
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: resource-coordinator
      app.kubernetes.io/instance: kxinsights
  template:
    metadata:
      labels:
        app.kubernetes.io/name: resource-coordinator
        app.kubernetes.io/instance: kxinsights
    spec:

      serviceAccountName: kxinsights-resource-coordinator
      securityContext:
        {}
      containers:
        - name: resource-coordinator
          securityContext:
            {}
          image: registry.dl.kx.com/kxi-sg-rc:1.1.0
          imagePullPolicy: IfNotPresent
          args: [ -p, "5060" ]
          env:
            - name: KDB_LICENSE_B64
              valueFrom:
                secretKeyRef:
                  name: kx-license-info
                  key: license
            - name: KXI_ASSEMBLY_FILE
              value: /opt/kx/config/assembly.yaml
          ports:
            - name: resource-coordi
              containerPort: 5060
              protocol: TCP
          resources:
            {}
          volumeMounts:
            - name: assemblyconfig
              mountPath: /opt/kx/config/assembly.yaml
              subPath: assembly.yaml
      imagePullSecrets:
        - name: kx-repo-access
      volumes:
      - name: assemblyconfig
        configMap:
          name: kxinsights-gw-assembly-configmap
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kxinsights-sg-gateway
  labels:
    app.kubernetes.io/name: sg-gateway
    app.kubernetes.io/instance: kxinsights
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: sg-gateway
      app.kubernetes.io/instance: kxinsights
  template:
    metadata:
      labels:
        app.kubernetes.io/name: sg-gateway
        app.kubernetes.io/instance: kxinsights
    spec:

      serviceAccountName: kxinsights-sg-gateway
      securityContext:
        {}
      containers:
        - name: sg-gateway
          securityContext:
            {}
          image: registry.dl.kx.com/kxi-sg-gw:1.1.0
          imagePullPolicy: IfNotPresent
          env:
            - name: KDB_LICENSE_B64
              valueFrom:
                secretKeyRef:
                  name: kx-license-info
                  key: license
            - name: KXI_ASSEMBLY_FILE
              value: /opt/kx/config/assembly.yaml
            - name: GATEWAY_QIPC_PORT
              value: "5050"
            - name: GATEWAY_HTTP_PORT
              value: "8080"
            - name: KXI_SG_RC_ADDR
              value: kxinsights-resource-coordinator.default.svc:5060
          ports:
            - name: http-port
              containerPort: 8080
            - name: ipc-port
              containerPort: 5050
          resources:
            {}
          volumeMounts:
            - name: assemblyconfig
              mountPath: /opt/kx/config/assembly.yaml
              subPath: assembly.yaml
      imagePullSecrets:
        - name: kx-repo-access
      volumes:
      - name: assemblyconfig
        configMap:
          name: kxinsights-gw-assembly-configmap
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kxinsights-hdb-da
  labels:
    app.kubernetes.io/name: hdb-da
    app.kubernetes.io/instance: kxinsights
spec:
  replicas: 3
  serviceName: kxinsights-hdb-da
  selector:
    matchLabels:
      app.kubernetes.io/name: hdb-da
      app.kubernetes.io/instance: kxinsights
  template:
    metadata:
      labels:
        app.kubernetes.io/name: hdb-da
        app.kubernetes.io/instance: kxinsights
    spec:
      serviceAccountName: kx-s3-read-access
      securityContext:
        {}
      containers:
        - name: hdb-da
          securityContext:
            {}
          image: registry.dl.kx.com/kxi-da:1.1.0
          imagePullPolicy: IfNotPresent
          args:
            - -p, 5080
            - "-namespace default -release kxinsights "
          env:
            - name: KDB_LICENSE_B64
              valueFrom:
                secretKeyRef:
                  name: kx-license-info
                  key: license
            - name: KX_TRACE_OBJSTR
              value: "1"
            - name: AWS_REGION
              value: "us-east-2"
            - name: AWS_DEFAULT_REGION
              value: "us-west-2"
            - name: ENABLE_IRP
              value: "true"
            - name: KXI_SC
              value: HDB
            - name: KXI_ASSEMBLY_FILE
              value: /opt/kx/config/assembly.yaml
          ports:
            - name: hdb-da
              containerPort: 5080
              protocol: TCP
          resources:
            {}
          volumeMounts:
            - name: assemblyconfig
              mountPath: /opt/kx/config/assembly.yaml
              subPath: assembly.yaml
            - name: s3config
              mountPath: /opt/kx/data/hdb/par.txt
              subPath: par.txt
            - name: s3config
              mountPath: /opt/kx/data/hdb/sym
              subPath: sym
      imagePullSecrets:
        - name: kx-repo-access
      volumes:
      - name: assemblyconfig
        configMap:
          name: kxinsights-da-assembly-configmap
      - name: s3config
        configMap:
          name: kxinsights-s3-configmap
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kxinsights-aggregator
  labels:
    app.kubernetes.io/name: aggregator
    app.kubernetes.io/instance: kxinsights
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kxinsights-resource-coordinator
  labels:
    app.kubernetes.io/name: resource-coordinator
    app.kubernetes.io/instance: kxinsights
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: kxinsights-sg-gateway
  labels:
    app.kubernetes.io/name: sg-gateway
    app.kubernetes.io/instance: kxinsights
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: kxinsights-gw-assembly-configmap
data:
  assembly.yaml: |-
    name: trade-assembly
    description: Assembly for Service Gateway. Defines set of all valid custom user labels
    labels:
      region: Canada,NotCanada
      assetClass: tick
    elements:
      rc:
        host: kxinsights-resource-coordinator.default.svc
        port: 5060
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: kxinsights-da-assembly-configmap
data:
  assembly.yaml: |-
    name: trade-assembly
    description: Assembly for Data Access processes. Defines labels that apply only to these DAs
    labels:
      region: Canada
      assetClass: tick
    tables:
      trade:
        description: Trade data
        type: partitioned
        blockSize: 10000
        prtnCol: time
        sortColsOrd: sym
        columns:
          - name: time
            description: Time
            type: timestamp
          - name: sym
            description: Symbol name
            type: symbol
            attrMem: grouped
            attrDisk: parted
            attrOrd: parted
          - name: price
            description: Trade price
            type: float
          - name: size
            description: Trade size
            type: long
    mounts:
      hdb:
        type: object
        baseURI: file:///opt/kx/data/hdb
        partition: none
    elements:
      rc:
        host: kxinsights-resource-coordinator.default.svc
        port: 5060
      dap:
        gwEndpoints: kxinsights-resource-coordinator.default.svc:5060
        instances:
          HDB:
            mountName: hdb
            sym: /opt/kx/data/hdb/sym
            par: /opt/kx/data/hdb/par.txt
