apiVersion: v1
kind: Namespace
metadata:
  labels:
    app: autoneg
    control-plane: controller-manager
  name: autoneg-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: autoneg
  name: autoneg-controller-manager
  namespace: autoneg-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  labels:
    app: autoneg
  name: autoneg-leader-election-role
  namespace: autoneg-system
rules:
  - apiGroups:
      - ""
    resources:
      - configmaps
    verbs:
      - get
      - list
      - watch
      - create
      - update
      - patch
      - delete
  - apiGroups:
      - coordination.k8s.io
    resources:
      - leases
    verbs:
      - get
      - list
      - watch
      - create
      - update
      - patch
      - delete
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      - create
      - patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: autoneg-manager-role
rules:
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      - create
      - patch
  - apiGroups:
      - ""
    resources:
      - services
    verbs:
      - get
      - list
      - patch
      - update
      - watch
  - apiGroups:
      - ""
    resources:
      - services/finalizers
    verbs:
      - update
  - apiGroups:
      - ""
    resources:
      - services/status
    verbs:
      - get
      - patch
      - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    app: autoneg
  name: autoneg-leader-election-rolebinding
  namespace: autoneg-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: autoneg-leader-election-role
subjects:
  - kind: ServiceAccount
    name: autoneg-controller-manager
    namespace: autoneg-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: autoneg-manager-rolebinding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: autoneg-manager-role
subjects:
  - kind: ServiceAccount
    name: autoneg-controller-manager
    namespace: idp
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: autoneg
    control-plane: controller-manager
  name: autoneg-controller-manager-metrics-service
  namespace: autoneg-system
spec:
  ports:
    - name: https
      port: 8443
      targetPort: https
  selector:
    app: autoneg
    control-plane: controller-manager
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: autoneg
    control-plane: controller-manager
  name: autoneg-controller-manager
  namespace: autoneg-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: autoneg
      control-plane: controller-manager
  template:
    metadata:
      labels:
        app: autoneg
        control-plane: controller-manager
    spec:
      containers:
        - args:
            - --secure-listen-address=0.0.0.0:8443
            - --upstream=http://127.0.0.1:8080/
            - --logtostderr=true
            - --v=10
          image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
          name: kube-rbac-proxy
          ports:
            - containerPort: 8443
              name: https
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - ALL
            privileged: false
            readOnlyRootFilesystem: true
            runAsGroup: 65532
            runAsNonRoot: true
            runAsUser: 65532
            seccompProfile:
              type: RuntimeDefault
        - args:
            - --health-probe-bind-address=:8081
            - --metrics-bind-address=127.0.0.1:8080
            - --leader-elect
            - --zap-encoder=json
            - --namespaces=autoneg-system
          command:
            - /manager
          image: ghcr.io/googlecloudplatform/gke-autoneg-controller/gke-autoneg-controller:v1.1.0
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8081
            initialDelaySeconds: 15
            periodSeconds: 20
          name: manager
          readinessProbe:
            httpGet:
              path: /readyz
              port: 8081
            initialDelaySeconds: 5
            periodSeconds: 10
          resources:
            limits:
              cpu: 100m
              memory: 30Mi
            requests:
              cpu: 100m
              memory: 20Mi
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
                - ALL
            privileged: false
            readOnlyRootFilesystem: true
            runAsGroup: 65532
            runAsNonRoot: true
            runAsUser: 65532
            seccompProfile:
              type: RuntimeDefault
      nodeSelector:
        iam.gke.io/gke-metadata-server-enabled: "true"
      securityContext:
        runAsGroup: 65532
        runAsNonRoot: true
        runAsUser: 65532
        seccompProfile:
          type: RuntimeDefault
      serviceAccountName: autoneg-controller-manager
      terminationGracePeriodSeconds: 10
