# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

{{- if .Values.features.flinkMonitor.enabled }}

apiVersion: v1
kind: Service
metadata:
  name: jobmanager
spec:
  ports:
    - name: ui
      protocol: TCP
      port: 8081
      targetPort: 8081
    - name: metrics
      protocol: TCP
      port: 9260
      targetPort: 9260
    - name: rpc
      protocol: TCP
      port: 6123
      targetPort: 6123
    - name: blob
      protocol: TCP
      port: 6124
      targetPort: 6124
  selector:
    app: jobmanager

---
apiVersion: v1
kind: Service
metadata:
  name: taskmanager
spec:
  type: ClusterIP
  ports:
    - protocol: TCP
      port: 9261
      targetPort: 9261
  selector:
    app: taskmanager

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: jobmanager
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jobmanager
  template:
    metadata:
      labels:
        app: jobmanager
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      containers:
        - name: jobmanager
          image: flink:2.0-preview1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8081
            - containerPort: 9260
              name: metrics
            - containerPort: 6123
          env:
            - name: FLINK_PROPERTIES
              value: |
                jobmanager.rpc.address: jobmanager
                metrics.reporter.prom.factory.class: org.apache.flink.metrics.prometheus.PrometheusReporterFactory
                metrics.reporter.prom.port: 9260
          args: ["jobmanager"]

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: taskmanager
spec:
  replicas: 1
  selector:
    matchLabels:
      app: taskmanager
  template:
    metadata:
      labels:
        app: taskmanager
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      containers:
        - name: taskmanager
          image: flink:2.0-preview1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9261
              name: metrics
          env:
            - name: FLINK_PROPERTIES
              value: |
                jobmanager.rpc.address: jobmanager
                metrics.reporter.prom.factory.class: org.apache.flink.metrics.prometheus.PrometheusReporterFactory
                metrics.reporter.prom.port: 9261
          args: ["taskmanager"]

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: execute-flink-job
spec:
  replicas: 1
  selector:
    matchLabels:
      app: execute-flink-job
  template:
    metadata:
      labels:
        app: execute-flink-job
      annotations:
        sidecar.istio.io/inject: "false"
    spec:
      containers:
        - name: execute-flink-job
          image: flink:2.0-preview1
          imagePullPolicy: IfNotPresent
          command:
            - bash
            - -c
            - "./bin/flink run -m jobmanager:8081 examples/streaming/WindowJoin.jar"

{{- end }}