apiVersion: v1
kind: ServiceAccount
metadata:
  name: load-watcher
  namespace: freeleaps-infra-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: load-watcher-role
rules:
  - apiGroups: [""]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]
  - apiGroups: ["metrics.k8s.io"]
    resources: ["nodes"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: load-watcher-binding
subjects:
  - kind: ServiceAccount
    name: load-watcher
    namespace: freeleaps-infra-system
roleRef:
  kind: ClusterRole
  name: load-watcher-role
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: Secret
metadata:
  name: load-watcher-config
  namespace: freeleaps-infra-system
type: Opaque
data:
  METRICS_PROVIDER_NAME: UHJvbWV0aGV1cw==
  METRICS_PROVIDER_ADDRESS: aHR0cDovL2t1YmUtcHJvbWV0aGV1cy1zdGFjay1wcm9tZXRoZXVzLmZyZWVsZWFwcy1tb25pdG9yaW5nLXN5c3RlbS5zdmMuZnJlZWxlYXBzLmNsdXN0ZXI6OTA5MA==
  INSECURE_SKIP_VERIFY: dHJ1ZQ==
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: load-watcher
  namespace: freeleaps-infra-system
  labels:
    app: load-watcher
spec:
  replicas: 1
  selector:
    matchLabels:
      app: load-watcher
  template:
    metadata:
      labels:
        app: load-watcher
    spec:
      serviceAccountName: load-watcher
      containers:
      - name: load-watcher
        image: freeleaps/load-watcher:latest
        env:
        - name: METRICS_PROVIDER_NAME
          valueFrom:
            secretKeyRef:
              name: load-watcher-config
              key: METRICS_PROVIDER_NAME
        - name: METRICS_PROVIDER_ADDRESS
          valueFrom:
            secretKeyRef:
              name: load-watcher-config
              key: METRICS_PROVIDER_ADDRESS
        - name: INSECURE_SKIP_VERIFY
          valueFrom:
            secretKeyRef:
              name: load-watcher-config
              key: INSECURE_SKIP_VERIFY
        resources:
          limits:
            cpu: "500m"
            memory: "256Mi"
          requests:
            cpu: "250m"
            memory: "128Mi"
        ports:
        - containerPort: 2020
---
apiVersion: v1
kind: Service
metadata:
  namespace: freeleaps-infra-system
  name: load-watcher
  labels:
    app: load-watcher
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 2020
    targetPort: 2020
    protocol: TCP
  selector:
    app: load-watcher