This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
196 lines (175 loc) · 7.42 KB
/
google-k8s-autopilot-cluster.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: "google-administer-autopilot-kubernetes-engine"
on:
workflow_call:
inputs:
cluster-name:
description: "Name of the GKE cluster"
required: true
type: string
region:
description: "The Google Cloud region where the GKE cluster will be available"
required: true
type: string
k8s-version:
description: "A supported and available Kubernetes (major.minor.patch) version"
required: true
type: string
vpc-network-name:
description: "Name of an existing Google Cloud VPC network"
required: true
type: string
master_ipv4_cidr_block_28:
description: "The IP range in CIDR notation to use for the hosted master network. This range will be used for assigning private IP addresses to the cluster master(s) and the ILB VIP. This range must not overlap with any other ranges in use within the cluster's network, and it must be a /28 subnet. This field only applies to private clusters, when enable_private_nodes is true."
required: false
type: string
default: "10.1.0.0/28"
action:
required: true
type: string
secrets:
GOOGLE_PROJECT_ID:
required: true
GOOGLE_SERVICE_ACCOUNT_KEY:
required: true
TF_BACKEND_GCS_BUCKET_NAME:
required: true
GOOGLE_KMS_KEYRING:
required: true
TANZU_NETWORK_API_TOKEN:
required: true
TANZU_NETWORK_USERNAME:
required: true
TANZU_NETWORK_PASSWORD:
required: true
CSP_API_TOKEN:
required: true
PA_TOKEN:
required: true
outputs:
cluster_name:
description: "The name of the GKE cluster"
value: ${{ jobs.terraform.outputs.cluster_name }}
jobs:
terraform:
env:
GOOGLE_APPLICATION_CREDENTIALS: "/tmp/gcloud/sa.json"
TF_VAR_project: ${{ secrets.GOOGLE_PROJECT_ID }}
TF_VAR_cluster_name: ${{ inputs.cluster-name }}
TF_VAR_cluster_version_prefix: "${{ inputs.k8s-version }}"
TF_VAR_vpc_network_name: "${{ inputs.vpc-network-name }}"
TF_VAR_region: ${{ inputs.region }}
# Setup for public endpoint
TF_VAR_enable_private_endpoint: false
TF_VAR_master_ipv4_cidr_block_28: ${{ inputs.master_ipv4_cidr_block_28 }}
TF_VAR_vpc_subnetwork_name: "pub-10-0-91-0"
runs-on: ubuntu-22.04
outputs:
cluster_name: ${{ steps.set_outputs.outputs.cluster_name }}
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-22.04, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: terraform/google/cluster/autopilot
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v4
# Install the latest version of Terraform CLI
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
terraform_version: 1.5.7
- name: Generate backend configuration
run: |
cp ../../backend/backend.tf .
echo "bucket = \"${{ secrets.TF_BACKEND_GCS_BUCKET_NAME }}\"" > config.gcs.tfbackend
echo "prefix = \"${{ inputs.cluster-name }}-cluster\"" >> config.gcs.tfbackend
- name: Decrypt service account keyfile contents and write to /tmp/gcloud/sa.json
env:
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
run: |
mkdir -p /tmp/gcloud
echo "$GOOGLE_SERVICE_ACCOUNT_KEY" | base64 -d > /tmp/gcloud/sa.json
chmod 600 /tmp/gcloud/sa.json
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init -upgrade -backend-config=./config.gcs.tfbackend
# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
run: terraform fmt -check
# Generates an execution plan for Terraform
- name: Terraform Plan
if: inputs.action == 'create'
run: terraform plan
- name: Terraform Apply
if: inputs.action == 'create'
run: terraform apply -auto-approve
- name: Terraform Destroy
if: inputs.action == 'destroy'
run: terraform destroy -auto-approve
- name: Set Outputs
id: set_outputs
if: inputs.action == 'create'
run: |
cluster_name=$(terraform output --raw cluster_name)
echo "cluster_name=${cluster_name}" >> $GITHUB_OUTPUT
obtain-base64-encoded-kubeconfig-from-cluster:
if: inputs.action == 'create'
needs: terraform
uses: ./.github/workflows/google-obtain-base64-encoded-kubeconfig-for-cluster.yml
with:
cluster-name: ${{ needs.terraform.outputs.cluster_name }}
is-regional-cluster: true
region: ${{ inputs.region }}
zone: ${{ inputs.zone }}
secrets:
GOOGLE_PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID }}
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
CSP_API_TOKEN: ${{ secrets.CSP_API_TOKEN }}
install-tanzu-cluster-essentials:
if: inputs.action == 'create'
needs: obtain-base64-encoded-kubeconfig-from-cluster
uses: ./.github/workflows/install-tanzu-cluster-essentials.yml
with:
cluster-provider: "gke"
secrets:
GOOGLE_PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID }}
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
TANZU_NETWORK_API_TOKEN: ${{ secrets.TANZU_NETWORK_API_TOKEN }}
TANZU_NETWORK_USERNAME: ${{ secrets.TANZU_NETWORK_USERNAME }}
TANZU_NETWORK_PASSWORD: ${{ secrets.TANZU_NETWORK_PASSWORD }}
CSP_API_TOKEN: ${{ secrets.CSP_API_TOKEN }}
KUBECONFIG_CONTENTS: ${{ needs.obtain-base64-encoded-kubeconfig-from-cluster.outputs.b64kubeconfig }}
install-tanzu-standard-repo:
if: inputs.action == 'create'
needs: [obtain-base64-encoded-kubeconfig-from-cluster,install-tanzu-cluster-essentials]
uses: ./.github/workflows/install-tanzu-standard-repo.yml
with:
cluster-provider: "gke"
tkg-version: "v2023.9.19"
secrets:
GOOGLE_PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID }}
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
TANZU_NETWORK_API_TOKEN: ${{ secrets.TANZU_NETWORK_API_TOKEN }}
TANZU_NETWORK_USERNAME: ${{ secrets.TANZU_NETWORK_USERNAME }}
TANZU_NETWORK_PASSWORD: ${{ secrets.TANZU_NETWORK_PASSWORD }}
CSP_API_TOKEN: ${{ secrets.CSP_API_TOKEN }}
PA_TOKEN: ${{ secrets.PA_TOKEN }}
KUBECONFIG_CONTENTS: ${{ needs.obtain-base64-encoded-kubeconfig-from-cluster.outputs.b64kubeconfig }}
install-tanzu-data-services-repo:
if: inputs.action == 'create'
needs: [obtain-base64-encoded-kubeconfig-from-cluster,install-tanzu-cluster-essentials]
uses: ./.github/workflows/install-tanzu-data-services-repo.yml
with:
cluster-provider: "gke"
tds-version: "1.12.1"
secrets:
GOOGLE_PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID }}
GOOGLE_SERVICE_ACCOUNT_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}
TANZU_NETWORK_API_TOKEN: ${{ secrets.TANZU_NETWORK_API_TOKEN }}
TANZU_NETWORK_USERNAME: ${{ secrets.TANZU_NETWORK_USERNAME }}
TANZU_NETWORK_PASSWORD: ${{ secrets.TANZU_NETWORK_PASSWORD }}
CSP_API_TOKEN: ${{ secrets.CSP_API_TOKEN }}
PA_TOKEN: ${{ secrets.PA_TOKEN }}
KUBECONFIG_CONTENTS: ${{ needs.obtain-base64-encoded-kubeconfig-from-cluster.outputs.b64kubeconfig }}