#######################################################################################
# Copyright ETSI Contributors and Others.
#
# 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.
#######################################################################################

---
apiVersion: container.gcp.upbound.io/v1beta1
kind: NodePool
metadata:
  annotations:
    meta.upbound.io/example-id: container/v1beta1/nodepool
  labels:
    testing.upbound.io/example-name: ${cluster_name}
  name: nodepool-${cluster_resource_name}
spec:
  forProvider:
    # Force K8s version
    # version: '1.27'
    clusterSelector:
      matchLabels:
        testing.upbound.io/example-name: ${cluster_name}
    nodeConfig:
    - machineType: ${vm_size}
      oauthScopes:
      - https://www.googleapis.com/auth/cloud-platform
      preemptible: ${preemptible_nodes}
      serviceAccountSelector:
        matchLabels:
          testing.upbound.io/example-name: ${cluster_name}
    nodeCount: 1
  # Use in case you wanted to use different credentials (i.e., ProviderConfig different than default)
  providerConfigRef:
    name: ${providerconfig_name}

---
apiVersion: container.gcp.upbound.io/v1beta1
kind: Cluster
metadata:
  annotations:
    meta.upbound.io/example-id: container/v1beta1/cluster
  labels:
    testing.upbound.io/example-name: ${cluster_name}
  name: ${cluster_resource_name}
spec:
  forProvider:
    initialNodeCount: 1
    location: ${cluster_location}
    # Force K8s version
    minMasterVersion: '1.27'
    removeDefaultNodePool: true
    # To enable client authentication in GKE:
    # See: <https://cloud.google.com/config-connector/docs/reference/resource-docs/container/containercluster>
    masterAuth:
    - clientCertificateConfig:
      - issueClientCertificate: true
  publishConnectionDetailsTo:
    name: kubeconfig-${cluster_resource_name}
  writeConnectionSecretToRef:
    name: kubeconfig-${cluster_resource_name}
    namespace: managed-resources
  # Use in case you wanted to use different credentials (i.e., ProviderConfig different than default)
  providerConfigRef:
    name: ${providerconfig_name}

---
apiVersion: cloudplatform.gcp.upbound.io/v1beta1
kind: ServiceAccount
metadata:
  annotations:
    meta.upbound.io/example-id: container/v1beta1/nodepool
  labels:
    testing.upbound.io/example-name: ${cluster_name}
  name: ${cluster_resource_name}
spec:
  forProvider:
    displayName: Service Account for Cluster ${cluster_name}
  # Use in case you wanted to use different credentials (i.e., ProviderConfig different than default)
  providerConfigRef:
    name: ${providerconfig_name}
