# Copyright 2020 Google LLC
#
# Licensed 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
#
#     https://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.
#
apiVersion: v1
kind: ServiceAccount
metadata:
  name: managed-certificate-account
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: managed-certificate-role
rules:
- apiGroups: ["coordination.k8s.io"]
  resources: ["leases"]
  verbs: ["*"]
- apiGroups: ["networking.gke.io"]
  resources: ["managedcertificates"]
  verbs: ["*"]
- apiGroups: ["networking.k8s.io"]
  resources: ["ingresses"]
  verbs: ["*"]
- apiGroups: [""]
  resources: ["configmaps", "events"]
  verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: managed-certificate-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: managed-certificate-role
subjects:
- kind: ServiceAccount
  name: managed-certificate-account
  namespace: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: managed-certificate-controller
spec:
  replicas: 1
  selector:
    matchLabels:
      app: managed-certificate-controller
  template:
    metadata:
      labels:
        app: managed-certificate-controller
    spec:
      serviceAccountName: managed-certificate-account
      containers:
      - name: managed-certificate-controller
        image: gcr.io/gke-release/managed-certificate-controller:v1.2.11
        imagePullPolicy: Always
        volumeMounts:
        - name: ssl-certs
          mountPath: "/etc/ssl/certs"
          readOnly: true
        - name: usrsharecacerts
          mountPath: "/usr/share/ca-certificates"
          readOnly: true
        args:
        - --health-check-address=:8089
        livenessProbe:
          httpGet:
            path: /health-check
            port: 8089
          initialDelaySecond: 600
          periodSeconds: 60
      volumes:
      - name: ssl-certs
        hostPath:
          path: "/etc/ssl/certs"
          type: Directory
      - name: usrsharecacerts
        hostPath:
          path: "/usr/share/ca-certificates"
          type: Directory
