-
Notifications
You must be signed in to change notification settings - Fork 1
/
Taskfile.yaml
238 lines (209 loc) · 9.7 KB
/
Taskfile.yaml
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
version: "3"
# Load environment variables from the specified dotenv files
dotenv:
- .env
# Define variables used throughout the Taskfile
vars:
cluster_name: "konductor" # Default cluster name
deployment: "{{.DEPLOYMENT | default `dev`}}" # Deployment environment (default: dev)
project: "{{.PROJECT | default `konductor`}}" # Project name (default: konductor)
organization: "{{.ORGANIZATION | default .GITHUB_USER}}" # Organization name (default: GitHub user)
pulumi_dir: "{{.PWD}}/.pulumi" # Directory for Pulumi configuration
kube_dir: "{{.PWD}}/.kube" # Directory for Kubernetes configuration
kube_config_file: "{{.kube_dir}}/config" # Path to the Kubernetes config file
pulumi_stack_identifier: "{{.organization}}/{{.project}}/{{.deployment}}" # Identifier for the Pulumi stack
talos_dir: "{{.PWD}}/.talos" # Directory for Talos configuration
talos_patch: "{{.talos_dir}}/patch/cluster.yaml" # Path to the Talos patch file
talos_config_file: "{{.talos_dir}}/manifest/talosconfig" # Path to the Talos config file
exposed_ports: "30590:30590/tcp" # Ports to expose for the Kubernetes cluster
memory: "8192" # Memory allocation for the Kubernetes cluster (in MB)
arch: # Architecture detection (amd64 or arm64)
sh: |
arch=$(uname -m)
if [ "$arch" = "x86_64" ]; then
echo "amd64"
elif [ "$arch" = "aarch64" ] || [ "$arch" = "arm64" ]; then
echo "arm64"
else
echo "unknown"
fi
tasks:
##################################################################################
# Meta & Utility Tasks
##################################################################################
# Default task that runs all the necessary steps to set up and configure the Kargo Kubevirt Kubernetes Platform
default:
desc: "Run all tasks to set up and configure a Kargo Kubevirt Kubernetes Platform."
cmds:
- task: deploy
# Task to print environment variables, useful for debugging
printenv:
desc: "Print environment variables."
cmds:
- /usr/bin/echo "{{.kube_dir}}"
# Task to initialize necessary directories and configuration files
init:
desc: "Initialize directories and configuration files."
cmds:
- mkdir -p .kube .pulumi .talos/{manifest,patch,secrets}
- touch {{.kube_config_file}} {{.talos_config_file}}
- chmod 600 {{.kube_config_file}} {{.talos_config_file}}
# Task to authenticate with Pulumi and install required plugins
login:
desc: "Authenticate with Pulumi."
cmds:
- task: init
- source .envrc && pulumi login
- source .envrc && pulumi install
# Task to deploy the Kubernetes and Kargo Kubevirt PaaS Infrastructure as Code (IaC)
deploy:
desc: "Deploy Kubernetes + Kargo Kubevirt PaaS IaC."
deps:
- iac-cancel
cmds:
- task: iac-deploy
# Task to wait until all Kubernetes pods in the cluster are ready
all-pods-ready:
desc: "Wait for all Kubernetes pods in the cluster to be ready."
cmds:
- bash -c 'until [ "$(kubectl get pods --all-namespaces --no-headers | grep -v "Running\\|Completed\\|Succeeded" | wc -l)" -eq 0 ]; do echo "Waiting for pods..."; sleep 5; done'
- kubectl get pods --all-namespaces --show-labels --kubeconfig {{.kube_config_file}}
# Task to clean up and destroy all Pulumi and Kubernetes resources
destroy:
desc: "Clean up and destroy all Pulumi and Kubernetes resources."
cmds:
- task: destroy
# Task to test GitHub Actions locally using the 'act' tool
act:
desc: "Test GitHub Actions locally using 'act'."
cmds:
- act --container-options "--privileged" --rm --var GITHUB_TOKEN=${GITHUB_TOKEN} --var PULUMI_ACCESS_TOKEN=${PULUMI_ACCESS_TOKEN}
# Task to clean up all local Kargo resources
clean:
desc: "Clean up all local Kargo resources."
cmds:
- task: iac-cancel
- task: iac-clean
# Task to clean up all local Kargo resources and additional files
clean-all:
desc: "Clean up all local Kargo resources."
deps:
- kubernetes-clean
- clean
cmds:
- ssh-keygen -f "/home/vscode/.ssh/known_hosts" -R "[127.0.0.1]:30590" 2>/dev/null || true
- rm -rf .talos/manifest/* .kube/config .ssh/known_hosts 2>/dev/null || true
- rm ${HOME}/.pulumi ${HOME}/.kube ${HOME}/.talos 2>/dev/null || true
# Task to stop the GitHub Codespace
stop:
desc: "Stop the GitHub Codespace."
cmds:
- task: clean-all
- gh codespace --codespace ${CODESPACE_NAME} stop
##################################################################################
# Demo VM Tasks
##################################################################################
# Task to deploy an Ubuntu VM using Pulumi
vm-deploy:
desc: "Enable the built-in Pulumi Ubuntu VM IaC feature."
cmds:
- source .envrc && pulumi config set --path vm.enabled true
- source .envrc && pulumi up --yes --skip-preview --refresh --stack {{.pulumi_stack_identifier}}
# Task to destroy the deployed Ubuntu VM using Pulumi
vm-destroy:
desc: "Disable the built-in Pulumi Ubuntu VM IaC feature."
cmds:
- source .envrc && pulumi config set --path vm.enabled false
- source .envrc && pulumi up --yes --skip-preview --refresh --stack {{.pulumi_stack_identifier}}
##################################################################################
# Pulumi Tasks
##################################################################################
# Task to configure Pulumi stack settings
configure:
desc: "Configure Pulumi stack settings."
cmds:
- source .envrc && pulumi stack select --create {{.pulumi_stack_identifier}}
- source .envrc && pulumi config set --path kubernetes.context admin@{{.cluster_name}}
- source .envrc && pulumi config set --path kubernetes.kubeconfig {{.kube_config_file}}
- source .envrc && pulumi config set --path kubernetes.distribution talos
- source .envrc && pulumi config set --path cilium.enabled false
- source .envrc && pulumi config set --path vm.enabled false
# Task to deploy Pulumi infrastructure
iac-deploy:
desc: "Deploy Pulumi infrastructure."
cmds:
- task: iac-cancel
- source .envrc && pulumi up --yes --skip-preview --refresh --continue-on-error --stack {{.pulumi_stack_identifier}} || true
- task: all-pods-ready
- source .envrc && pulumi up --yes --skip-preview --refresh --stack {{.pulumi_stack_identifier}}
- task: all-pods-ready
# Task to destroy Pulumi infrastructure
iac-destroy:
desc: "Destroy Pulumi infrastructure."
cmds:
- task: iac-cancel
- |
source .envrc
pulumi down --yes --skip-preview --refresh --stack {{.pulumi_stack_identifier}} || true
pulumi down --yes --skip-preview --refresh --stack {{.pulumi_stack_identifier}}
# Task to cancel the Pulumi update process
iac-cancel:
desc: "Cancel the Pulumi update."
cmds:
- source .envrc && pulumi cancel --yes --stack {{.pulumi_stack_identifier}} 2>/dev/null || true
# Task to clean up all Pulumi resources
iac-clean:
desc: "Clean up all Pulumi resources."
cmds:
- task: iac-cancel
- source .envrc && pulumi down --yes --skip-preview --refresh --stack {{.pulumi_stack_identifier}} 2>/dev/null || true
##################################################################################
# Talos Tasks
##################################################################################
# Task to generate Talos cluster configuration
kubernetes-gen-config:
desc: "Generate Talos cluster configuration."
cmds:
- talosctl gen config {{.project}} https://10.0.5.2:6443 --config-patch @{{.talos_patch}} --force --output .talos/manifest --context {{.cluster_name}}
# Task to deploy a Kubernetes cluster using Talos
kubernetes-deploy:
desc: "Deploy Kubernetes cluster."
cmds:
- task: init
- |
talosctl cluster create \
--arch={{.arch}} \
--provisioner docker \
--init-node-as-endpoint \
--config-patch @{{.talos_patch}} \
--controlplanes 1 \
--memory {{.memory}} \
--exposed-ports {{.exposed_ports}} \
--context {{.cluster_name}} \
--name {{.cluster_name}} \
--workers 0 --crashdump
# Task to wait until the Talos cluster control plane components are ready
kubernetes-ready:
desc: "Wait for the Talos cluster control plane components to be ready."
cmds:
- bash -c 'until kubectl --kubeconfig {{.kube_config_file}} wait --for=condition=Ready pod -l k8s-app=kube-scheduler --namespace=kube-system --timeout=180s; do echo "Waiting for kube-scheduler..."; sleep 5; done' || true
- bash -c 'until kubectl --kubeconfig {{.kube_config_file}} wait --for=condition=Ready pod -l k8s-app=kube-controller-manager --namespace=kube-system --timeout=180s; do echo "Waiting for kube-controller-manager..."; sleep 5; done' || true
- bash -c 'until kubectl --kubeconfig {{.kube_config_file}} wait --for=condition=Ready pod -l k8s-app=kube-apiserver --namespace=kube-system --timeout=180s; do echo "Waiting for kube-apiserver..."; sleep 5; done' || true
# Task to clean up all Kubernetes resources deployed by Talos
kubernetes-clean:
desc: "Clean up all Kubernetes resources."
cmds:
- talosctl cluster destroy --name {{.cluster_name}} 2>/dev/null || true
- docker rm --force {{.cluster_name}}-controlplane-1 2>/dev/null || true
# Task to complete setup and configuration of a Kubernetes cluster
kubernetes:
desc: "Complete setup and configuration of a Kubernetes cluster."
deps:
- clean
- kubernetes-clean
cmds:
- task: init
- task: kubernetes-gen-config
- task: kubernetes-deploy
- task: kubernetes-ready
- task: all-pods-ready