# Copyright 2021 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
#
#      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.
# Service Account for GKE nodes
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMServiceAccount
metadata: # kpt-merge: config-control/gke-example-us-east4-primary
  name: gke-example-us-east4-primary # kpt-set: gke-${cluster-name}-${nodepool-name}
  namespace: config-control # kpt-set: ${platform-namespace}
  annotations:
    cnrm.cloud.google.com/blueprint: cnrm/gke:gke-nodepool/v0.4.0
    cnrm.cloud.google.com/project-id: project-id # kpt-set: ${project-id}
spec:
  displayName: gke-example-us-east4-primary # kpt-set: gke-${cluster-name}-${nodepool-name}
---
# Allow fluentd to send logs to StackDriver
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata: # kpt-merge: config-control/logwriter-gke-example-us-east4-primary
  name: logwriter-gke-example-us-east4-primary # kpt-set: logwriter-gke-${cluster-name}-${nodepool-name}
  namespace: config-control # kpt-set: ${platform-namespace}
  annotations:
    cnrm.cloud.google.com/blueprint: cnrm/gke:gke-nodepool/v0.4.0
spec:
  memberFrom:
    serviceAccountRef:
      name: gke-example-us-east4-primary # kpt-set: gke-${cluster-name}-${nodepool-name}
      namespace: config-control # kpt-set: ${platform-namespace}
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: project-id # kpt-set: ${project-id}
  role: roles/logging.logWriter
---
# Allow fluentd to send metrics to StackDriver
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata: # kpt-merge: config-control/metricwriter-gke-example-us-east4-primary
  name: metricwriter-gke-example-us-east4-primary # kpt-set: metricwriter-gke-${cluster-name}-${nodepool-name}
  namespace: config-control # kpt-set: ${platform-namespace}
  annotations:
    cnrm.cloud.google.com/blueprint: cnrm/gke:gke-nodepool/v0.4.0
spec:
  memberFrom:
    serviceAccountRef:
      name: gke-example-us-east4-primary # kpt-set: gke-${cluster-name}-${nodepool-name}
      namespace: config-control # kpt-set: ${platform-namespace}
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: project-id # kpt-set: ${project-id}
  role: roles/monitoring.metricWriter
---
# Allow kubelet/docker/containerd to read all artifacts/images in the project-id project
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata: # kpt-merge: config-control/artifactreader-gke-example-us-east4-primary
  name: artifactreader-gke-example-us-east4-primary # kpt-set: artifactreader-gke-${cluster-name}-${nodepool-name}
  namespace: config-control # kpt-set: ${platform-namespace}
  annotations:
    cnrm.cloud.google.com/blueprint: cnrm/gke:gke-nodepool/v0.4.0
spec:
  memberFrom:
    serviceAccountRef:
      name: gke-example-us-east4-primary # kpt-set: gke-${cluster-name}-${nodepool-name}
      namespace: config-control # kpt-set: ${platform-namespace}
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: project-id # kpt-set: ${project-id}
  role: roles/artifactregistry.reader
