{{! ========================================================== }}
{{! ========================================================== }}
{{! =======================ClusterPool======================== }}
{{! ========================================================== }}
{{! ========================================================== }}

apiVersion: hive.openshift.io/v1
kind: ClusterPool
metadata:
  name: '{{{name}}}' ##name
  namespace: '{{{namespace}}}'  ##namespace
  labels:
    cloud: '{{infrastructure}}'
{{#if region}}
    region: '{{{region}}}'  ##region
{{/if}}
    vendor: '{{distribution}}'
{{#if clusterSet}}
    cluster.open-cluster-management.io/clusterset: '{{{clusterSet}}}'
{{/if}}
spec:
  size: {{{size}}} ##size
  baseDomain: {{{baseDomain}}}  ##baseDomain
  installConfigSecretTemplateRef:
    name: {{{name}}}-install-config
{{#if releaseImageReference}}
  imageSetRef:
     #{{{clusterImageSetComment}}}
    name: {{{releaseImageReference}}}
{{/if}}
{{#if clusterReleaseImage}}
  imageSetRef:
    name: {{{clusterImageSetName}}}
{{/if}}
  pullSecretRef:
    name: {{{name}}}-pull-secret
  platform:
{{! ==================platform======================= }}
{{#switch infrastructure}}
  {{#case 'AWS'}}
    aws:
      credentialsSecretRef:
        name: {{{../../name}}}-aws-creds
      region: {{{../../region}}}
  {{/case}}

  {{#case 'GCP'}}
    gcp:
      credentialsSecretRef:
        name: {{{../../name}}}-gcp-creds
      region: {{{../../region}}}
  {{/case}}

  {{#case 'Azure'}}
    azure:
      baseDomainResourceGroupName: {{{../../baseDomainResourceGroupName}}} ##resourceGroupName
      credentialsSecretRef:
        name: {{{../../name}}}-azure-creds
      region: {{{../../region}}}
  {{/case}}
{{/switch}}

{{! ========================================================== }}
{{! ========================================================== }}
{{! ==================ClusterImageSet========================= }}
{{! ========================================================== }}
{{! ========================================================== }}


{{#if clusterReleaseImage}}
---
apiVersion: hive.openshift.io/v1
kind: ClusterImageSet
metadata:
  name: {{{clusterImageSetName}}}
spec:
  releaseImage: {{{clusterReleaseImage}}}
{{/if}}

{{! ========================================================== }}
{{! ========================================================== }}
{{! ==================Secrets ================================ }}
{{! ========================================================== }}
{{! ========================================================== }}

{{#if pullSecret}}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{{name}}}-pull-secret
  namespace: '{{{namespace}}}'
stringData:
{{#if showSecrets}}
  .dockerconfigjson: |-
    {{{pullSecret}}}
{{else}}
  .dockerconfigjson: # injected on create
{{/if}}
type: kubernetes.io/dockerconfigjson
{{/if}}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{{name}}}-install-config
  namespace: '{{{namespace}}}'
type: Opaque
data:
  # Base64 encoding of install-config yaml
  install-config.yaml: {{{install-config}}}
{{#if ssh-privatekey}}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{{name}}}-ssh-private-key
  namespace: '{{{namespace}}}'
stringData:
{{#if showSecrets}}
  ssh-privatekey: |-
{{#each ssh-privatekey}}
    {{{.}}}
{{/each}}
{{else}}
  ssh-privatekey: # injected on create
{{/if}}
type: Opaque
{{/if}}

{{#if_ne infrastructure 'BMC'}}
---
apiVersion: v1
kind: Secret
type: Opaque
{{/if_ne}}

{{#switch infrastructure}}

{{#case 'AWS'}}
metadata:
  name: {{{../../name}}}-aws-creds
  namespace: '{{{../../namespace}}}'
stringData:
  aws_access_key_id: {{{../../aws_access_key_id}}}
{{#if ../../showSecrets}}
  aws_secret_access_key: {{{../../aws_secret_access_key}}}
{{else}}
  aws_secret_access_key: # injected on create
{{/if}}
{{/case}}

{{#case 'GCP'}}
metadata:
  name: {{{../../name}}}-gcp-creds
  namespace: '{{{../../namespace}}}'
stringData:
{{#if ../../showSecrets}}
  osServiceAccount.json: |-
{{! handlebars does not like periods in ids, so we will use a replacement to map to the correct osServiceAccount.json - See ControlDataHelpers.js replacements[] }}
{{#each ../../osServiceAccountJson}}
    {{{.}}}
{{/each}}
{{else}}
  osServiceAccount.json: # injected on create
{{/if}}
{{/case}}

{{#case 'Azure'}}
metadata:
  name: {{{../../name}}}-azure-creds
  namespace: '{{{../../namespace}}}'
stringData:
{{#if ../../showSecrets}}
  osServicePrincipal.json: |-
{{! handlebars does not like periods in ids, so we will use a replacement to map to the correct osServicePrincipal.json - See ControlDataHelpers.js replacements[] }}
{{#each ../../osServicePrincipalJson}}
    {{{.}}}
{{/each}}
{{else}}
  osServicePrincipal.json: # injected on create
{{/if}}
{{/case}}

{{#case 'vSphere'}}
metadata:
  name: {{{../../name}}}-vsphere-creds
  namespace: '{{{../../namespace}}}'
stringData:
  username: {{{../../username}}}
  password: {{{../../password}}}

---

apiVersion: v1
kind: Secret
type: Opaque
metadata:
  name: {{{../../name}}}-vsphere-certs
  namespace: '{{{../../namespace}}}'
data:

{{#if ../../showSecrets}}
  .cacert: {{{../../cacertificate}}}
{{else}}
  .cacert: # injected on create
{{/if}}

{{/case}}

{{#case 'OpenStack'}}
metadata:
  name: {{{../../name}}}-openstack-creds
  namespace: '{{{../../namespace}}}'
stringData:
  cloud: '{{{../../cloud}}}'
{{#if ../../showSecrets}}
  clouds.yaml: |- 
    {{{../../clouds.yaml}}}
{{else}}
  clouds.yaml: # injected on create
{{/if}}
{{/case}}

{{/switch}}
