
# 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.

# [START gke_manifests_adapter_new_resource_model_namespace_custom_metrics]
# [START container_workload_metrics_namespace_custom_metrics]
apiVersion: v1
kind: Namespace
metadata:
  name: custom-metrics
# [END container_workload_metrics_namespace_custom_metrics]
# [END gke_manifests_adapter_new_resource_model_namespace_custom_metrics]
---
# [START gke_manifests_adapter_new_resource_model_serviceaccount_custom_metrics_stackdriver_adapter]
# [START container_workload_metrics_service_account_custom_metrics_stackdriver_adapter]
apiVersion: v1
kind: ServiceAccount
metadata:
  name: custom-metrics-stackdriver-adapter
  namespace: custom-metrics
# [END container_workload_metrics_service_account_custom_metrics_stackdriver_adapter]
# [END gke_manifests_adapter_new_resource_model_serviceaccount_custom_metrics_stackdriver_adapter]
---
# [START gke_manifests_adapter_new_resource_model_clusterrolebinding_custom_metrics_system_auth_delegator]
# [START container_workload_metrics_cluster_role_binding_custom_metrics_system_auth_delegator]
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: custom-metrics:system:auth-delegator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:auth-delegator
subjects:
- kind: ServiceAccount
  name: custom-metrics-stackdriver-adapter
  namespace: custom-metrics
# [END container_workload_metrics_cluster_role_binding_custom_metrics_system_auth_delegator]
# [END gke_manifests_adapter_new_resource_model_clusterrolebinding_custom_metrics_system_auth_delegator]
---
# [START gke_manifests_adapter_new_resource_model_rolebinding_custom_metrics_auth_reader]
# [START container_workload_metrics_role_binding_custom_metrics_auth_reader]
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: custom-metrics-auth-reader
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
  name: custom-metrics-stackdriver-adapter
  namespace: custom-metrics
# [END container_workload_metrics_role_binding_custom_metrics_auth_reader]
# [END gke_manifests_adapter_new_resource_model_rolebinding_custom_metrics_auth_reader]
---
# [START gke_manifests_adapter_new_resource_model_clusterrolebinding_custom_metrics_resource_reader]
# [START container_workload_metrics_cluster_role_binding_custom_metrics_resource_reader]
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: custom-metrics-resource-reader
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
- kind: ServiceAccount
  name: custom-metrics-stackdriver-adapter
  namespace: custom-metrics
# [END container_workload_metrics_cluster_role_binding_custom_metrics_resource_reader]
# [END gke_manifests_adapter_new_resource_model_clusterrolebinding_custom_metrics_resource_reader]
---
# [START gke_manifests_adapter_new_resource_model_deployment_custom_metrics_stackdriver_adapter]
# [START container_workload_metrics_deployment_custom_metrics_stackdriver_adapter]
apiVersion: apps/v1
kind: Deployment
metadata:
  name: custom-metrics-stackdriver-adapter
  namespace: custom-metrics
  labels:
    run: custom-metrics-stackdriver-adapter
    k8s-app: custom-metrics-stackdriver-adapter
spec:
  replicas: 1
  selector:
    matchLabels:
      run: custom-metrics-stackdriver-adapter
      k8s-app: custom-metrics-stackdriver-adapter
  template:
    metadata:
      labels:
        run: custom-metrics-stackdriver-adapter
        k8s-app: custom-metrics-stackdriver-adapter
        kubernetes.io/cluster-service: "true"
    spec:
      serviceAccountName: custom-metrics-stackdriver-adapter
      containers:
      - image: gcr.io/gke-release/custom-metrics-stackdriver-adapter:v0.12.0-gke.0
        imagePullPolicy: Always
        name: pod-custom-metrics-stackdriver-adapter
        command:
        - /adapter
        - --use-new-resource-model=true
        - --fallback-for-container-metrics=true
        resources:
          limits:
            cpu: 250m
            memory: 200Mi
          requests:
            cpu: 250m
            memory: 200Mi
# [END container_workload_metrics_deployment_custom_metrics_stackdriver_adapter]
# [END gke_manifests_adapter_new_resource_model_deployment_custom_metrics_stackdriver_adapter]
---
# [START gke_manifests_adapter_new_resource_model_service_custom_metrics_stackdriver_adapter]
# [START container_workload_metrics_service_custom_metrics_stackdriver_adapter]
apiVersion: v1
kind: Service
metadata:
  labels:
    run: custom-metrics-stackdriver-adapter
    k8s-app: custom-metrics-stackdriver-adapter
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: Adapter
  name: custom-metrics-stackdriver-adapter
  namespace: custom-metrics
spec:
  ports:
  - port: 443
    protocol: TCP
    targetPort: 443
  selector:
    run: custom-metrics-stackdriver-adapter
    k8s-app: custom-metrics-stackdriver-adapter
  type: ClusterIP
# [END container_workload_metrics_service_custom_metrics_stackdriver_adapter]
# [END gke_manifests_adapter_new_resource_model_service_custom_metrics_stackdriver_adapter]
---
# [START gke_manifests_adapter_new_resource_model_apiservice_v1beta1_custom_metrics_k8s_io]
# [START container_workload_metrics_apiservice_v1beta1]
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  name: v1beta1.custom.metrics.k8s.io
spec:
  insecureSkipTLSVerify: true
  group: custom.metrics.k8s.io
  groupPriorityMinimum: 100
  versionPriority: 100
  service:
    name: custom-metrics-stackdriver-adapter
    namespace: custom-metrics
  version: v1beta1
# [END container_workload_metrics_apiservice_v1beta1]
# [END gke_manifests_adapter_new_resource_model_apiservice_v1beta1_custom_metrics_k8s_io]
---
# [START gke_manifests_adapter_new_resource_model_apiservice_v1beta2_custom_metrics_k8s_io]
# [START container_workload_metrics_apiservice_v1beta2]
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  name: v1beta2.custom.metrics.k8s.io
spec:
  insecureSkipTLSVerify: true
  group: custom.metrics.k8s.io
  groupPriorityMinimum: 100
  versionPriority: 200
  service:
    name: custom-metrics-stackdriver-adapter
    namespace: custom-metrics
  version: v1beta2
  # [END container_workload_metrics_apiservice_v1beta2]
# [END gke_manifests_adapter_new_resource_model_apiservice_v1beta2_custom_metrics_k8s_io]
---
# [START gke_manifests_adapter_new_resource_model_apiservice_v1beta1_external_metrics_k8s_io]
# [START container_workload_metrics_apiservice_v1beta1_external]
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
  name: v1beta1.external.metrics.k8s.io
spec:
  insecureSkipTLSVerify: true
  group: external.metrics.k8s.io
  groupPriorityMinimum: 100
  versionPriority: 100
  service:
    name: custom-metrics-stackdriver-adapter
    namespace: custom-metrics
  version: v1beta1
# [END container_workload_metrics_apiservice_v1beta1_external]
# [END gke_manifests_adapter_new_resource_model_apiservice_v1beta1_external_metrics_k8s_io]
---
# [START gke_manifests_adapter_new_resource_model_clusterrole_external_metrics_reader]
# [START container_workload_metrics_cluster_role_external_metrics_reader]
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: external-metrics-reader
rules:
- apiGroups:
  - "external.metrics.k8s.io"
  resources:
  - "*"
  verbs:
  - list
  - get
  - watch
# [END container_workload_metrics_cluster_role_external_metrics_reader]
# [END gke_manifests_adapter_new_resource_model_clusterrole_external_metrics_reader]
---
# [START gke_manifests_adapter_new_resource_model_clusterrolebinding_external_metrics_reader]
# [START container_workload_metrics_cluster_role_binding_external_metrics_reader]
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: external-metrics-reader
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: external-metrics-reader
subjects:
- kind: ServiceAccount
  name: horizontal-pod-autoscaler
  namespace: kube-system
# [END container_workload_metrics_cluster_role_binding_external_metrics_reader]
# [END gke_manifests_adapter_new_resource_model_clusterrolebinding_external_metrics_reader]
---
