-
Notifications
You must be signed in to change notification settings - Fork 3
217 lines (189 loc) · 7.45 KB
/
test-cloud-k3d-self.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Test Cloud On K3D Self Runner
on:
workflow_dispatch:
inputs:
cloud-version:
description: 'kb-cloud version (e.g. 0.29.0-alpha.110)'
type: string
required: false
default: '0.29.0-alpha.110'
k3s-version:
description: 'k3s cluster version (e.g. 1.30)'
type: string
required: false
default: '1.30'
workflow_call:
inputs:
cloud-version:
description: 'kb-cloud version (e.g. 0.29.0-alpha.110)'
type: string
required: false
default: '0.29.0-alpha.110'
k3s-version:
description: 'k3s cluster version (e.g. 1.30)'
type: string
required: false
default: '1.30'
outputs:
test-result:
description: "e2e test result"
value: "${{ jobs.cloud-test-k3d.outputs.test-result }}"
run-name: Test Cloud Version:${{ inputs.cloud-version }} K3s Version:${{ inputs.k3s-version }}
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
K3D_NAME: kbcloud
CLOUD_LICENSE: ${{ secrets.CLOUD_LICENSE }}
permissions:
id-token: write
contents: read
jobs:
cloud-test-k3d:
runs-on: [ self-hosted, k3s-runner ]
outputs:
deploy-result: ${{ steps.deploy_cloud.outputs.deploy-result }}
test-result: ${{ steps.test_result.outputs.test-result }}
test-type: ${{ steps.test_result.outputs.test-type }}
runner-name: ${{ steps.get_runner_name.outputs.runner-name }}
steps:
- name: Checkout apecloud-cd Code
uses: actions/checkout@v4
with:
repository: apecloud/apecloud-cd
path: apecloud-cd
- name: setup k3d k3s
uses: nolar/setup-k3d-k3s@v1
with:
k3d-name: "${{ env.K3D_NAME }}"
version: "v${{ inputs.k3s-version }}"
github-token: ${{ env.GITHUB_TOKEN }}
k3d-args: -p 443:443@loadbalancer -p 80:80@loadbalancer --agents 2
- name: update k3d coredns cm
run: |
bash ${{ github.workspace }}/apecloud-cd/.github/utils/utils.sh --type 37
- name: install cert-manager
run: |
helm repo add jetstack https://charts.jetstack.io --force-update
helm install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.16.0 \
--set crds.enabled=true
- name: install kb cloud
run: |
helm repo add kb-chart https://apecloud.github.io/helm-charts
helm install installer kb-chart/kb-cloud-installer \
--version ${{ inputs.cloud-version }} \
--set image.registry="docker.io" \
--set version=${{ inputs.cloud-version }} \
--set kubernetesProvider=k3d \
--set fqdn.domain=mytest.kubeblocks.com \
--set tls.enabled=true
- name: check kb-cloud-installer pod Completed
run: |
for i in {1..360}; do
if kubectl get pods | grep "kb-cloud-installer" | grep Completed ; then
kubectl get pods -n kb-cloud | grep Running
echo "KB Cloud is ready"
break
fi
echo "Waiting for KB Cloud to be ready..."
kubectl get pods -n kb-cloud
echo ""
sleep 5
done
- name: deploy kubeblocks
run: |
echo "get k8s config"
k8s_cluster_name=$(kubectl config get-clusters | sed '1d')
kubectl config set-cluster ${k8s_cluster_name} --insecure-skip-tls-verify=true
k8s_kubeconfig_yaml=$(kubectl config view --minify -o yaml --raw)
kubeconfig_file_name="k8s_kubeconfig_file.yaml"
touch ${kubeconfig_file_name}
echo "${k8s_kubeconfig_yaml}" > ${kubeconfig_file_name}
yq e -i '.clusters[0].cluster.server = "https://kubernetes.default:443"' ${kubeconfig_file_name}
k8s_kubeconfig=$(cat ${kubeconfig_file_name})
echo "------------------------------------------------------------"
echo "${k8s_kubeconfig}"
echo "------------------------------------------------------------"
K8S_KUBECONFIG="$(echo "${k8s_kubeconfig}" | base64)"
CLOUD_LICENSE="${{ env.CLOUD_LICENSE }}"
echo "deploy kubeblocks"
helm install deployer kb-chart/kb-cloud-deployer \
--version 0.0.1 \
--set image.registry="docker.io" \
--set license="${CLOUD_LICENSE}" \
--set kubeconfig="${K8S_KUBECONFIG}"
- name: check kb-cloud-deployer pod Completed
run: |
for i in {1..360}; do
if kubectl get pods | grep "kb-cloud-deployer" | grep Completed ; then
kubectl get pods -n kb-system | grep Running
echo "KubeBlocks is ready"
break
fi
echo "Waiting for KubeBlocks to be ready..."
kubectl get pods -n kb-system
echo ""
sleep 5
done
- name: get runner name
id: get_runner_name
if: ${{ always() }}
run: |
echo runner-name=${RUNNER_NAME} >> $GITHUB_OUTPUT
remove-runner:
needs: [ cloud-test-k3d ]
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Checkout apecloud-cd Code
uses: actions/checkout@v4
with:
repository: apecloud/apecloud-cd
path: ./
- name: remove runner
run: |
bash .github/utils/utils.sh --type 25 \
--github-token "${{ env.GITHUB_TOKEN }}" \
--github-repo "${{ github.repository }}" \
--runner-name ${{ needs.cloud-test-k3d.outputs.runner-name }}
- uses: azure/setup-kubectl@v3
with:
version: "v1.28.3"
- uses: aws-actions/setup-sam@v2
if: ${{ inputs.cloud-provider == 'eks' }}
with:
use-installer: true
- uses: aws-actions/configure-aws-credentials@v4
if: ${{ inputs.cloud-provider == 'eks' && env.AWS_ACCESS_KEY_ID != '' && env.AWS_SECRET_ACCESS_KEY != '' }}
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: "${{ env.AWS_REGION }}"
- if: ${{ inputs.cloud-provider == 'eks' }}
run: |
aws eks --region ${{ env.AWS_REGION }} update-kubeconfig --name ${{ env.AWS_CLUSTER }} \
--role-arn $(aws iam get-role --role-name ${{ env.AWS_CLUSTER }}-admin-role --query 'Role.Arn' --output text)
- if: ${{ inputs.cloud-provider == 'gke' && env.GOOGLE_CREDENTIALS != '' }}
id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ env.GOOGLE_CREDENTIALS }}'
- name: setup gke-gcloud-auth-plugin
if: ${{ inputs.cloud-provider == 'gke' }}
uses: simenandre/setup-gke-gcloud-auth-plugin@v1
- uses: google-github-actions/get-gke-credentials@v1
if: ${{ inputs.cloud-provider == 'gke' }}
with:
cluster_name: ${{ env.CLUSTER_NAME }}
location: ${{ env.GCP_REGION }}
- name: delete runner pod
env:
RUNNER_NAME: ${{ needs.cloud-test-k3d.outputs.runner-name }}
run: |
runner_pod_exists=$(kubectl get pod | (grep "${{ env.RUNNER_NAME }}"||true))
if [[ -n "${runner_pod_exists}" ]]; then
kubectl delete pod "${{ env.RUNNER_NAME }}" --force
fi