-
Notifications
You must be signed in to change notification settings - Fork 12
140 lines (121 loc) · 5.96 KB
/
integration.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
# Copyright 2023 The Atlas Operator Authors.
#
# 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.
name: Integration Tests
on:
push:
branches:
- master
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Create SSH dir in Runner's home
run: |
# Fixed a BC change that rolling out in GitHub-hosted runners
mkdir -p ~/.ssh/
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Install Atlas CLI
run: |
curl -sSf https://atlasgo.sh | ATLAS_DEBUG=true sh
- name: Generate
run: make cli-gen
shell: bash
- name: Run Go mod tidy
run: go mod tidy
- name: Verify generated files are checked in properly
run: |
status=$(git status --porcelain)
if [ -n "$status" ]; then
echo "you need to run 'make cli-gen' and commit the changes"
echo "$status"
exit 1
fi
shell: bash
- name: Run tests
run: go test ./... -race
shell: bash
- uses: azure/setup-kubectl@v3
- name: Start minikube
id: minikube
uses: medyagh/setup-minikube@master
- name: Install Skaffold
run: |
curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/v2.3.1/skaffold-linux-amd64 && \
sudo install skaffold /usr/local/bin/
- name: Start environment
run: |
make install # Install CRDs into the cluster
kubectl apply -f config/integration/databases
skaffold run --wait-for-connection=true
- name: Integration test
run: |
# Wait for mysql ready
kubectl wait --for condition=ready pods -l app=mysql --timeout=60s
POD_MYSQL=$(kubectl get pods -l app=mysql -o jsonpath='{.items[0].metadata.name}')
# Create a table not described in the desired schema but excluded from it.
kubectl exec $POD_MYSQL -- mysql -uroot -h 127.0.0.1 -ppass -e "create table myapp.ignore_me (c int);"
# Apply the desired schema and wait for it to be ready.
kubectl apply -f config/integration/schema
kubectl wait --for=condition=ready --timeout=120s atlasschemas --all
# Expect the excluded table to be present.
kubectl exec $POD_MYSQL -- mysql -uroot -h 127.0.0.1 -ppass -e "describe myapp.ignore_me"
# Update sql schema configmap
kubectl create configmap mysql-schema --from-file=./config/integration/schema/mysql \
--dry-run=client -o yaml | kubectl apply -f -
sleep 1s # Wait for the migration to be applied.
kubectl wait --for=condition=ready --timeout=120s atlasschemas --all
# Expect the new column to be present.
kubectl exec $POD_MYSQL -- mysql -uroot -h 127.0.0.1 -ppass -e "SHOW COLUMNS FROM myapp.users LIKE 'phone';"
# Expect the devdb deployment is scaled to 1.
kubectl get deployment atlasschema-mysql-atlas-dev-db -o=jsonpath='{.spec.replicas}' | grep -q '1'
# SET PREWARM_DEVDB to true
kubectl set env -n atlas-operator-system deployment/atlas-operator-controller-manager PREWARM_DEVDB=false
# Reset database resources
kubectl delete pods -l app=mysql
kubectl wait --for condition=ready pods -l app=mysql --timeout=60s
# Apply the desired schema and wait for it to be ready.
kubectl delete -f config/integration/schema
kubectl apply -f config/integration/schema
kubectl wait --for=condition=ready --timeout=120s atlasschemas --all
# Expect the devdb deployment is scaled to 0.
kubectl get deployment atlasschema-mysql-atlas-dev-db -o=jsonpath='{.spec.replicas}' | grep -q '0'
- name: Reset database resources
run: |
kubectl delete pods -l app=mysql
kubectl delete pods -l app=postgres
- name: Integration test (versioned migration)
run: |
# Wait for mysql ready
kubectl wait --for condition=ready pods -l app=mysql --timeout=60s
POD_MYSQL=$(kubectl get pods -l app=mysql -o jsonpath='{.items[0].metadata.name}')
# Create migration directory configmap
kubectl create configmap migration-dir --from-file=./config/integration/migration/mysql-migrations
# Create migration directory resources and wait for it to be ready.
kubectl apply -f ./config/integration/migration/mysql_migration.yaml
kubectl wait --for=condition=ready --timeout=120s atlasmigrations --all
# Expect existed atlas_schema_revisions table
kubectl exec $POD_MYSQL -- mysql -uroot -h 127.0.0.1 -ppass -e "describe myapp.atlas_schema_revisions"
# Add a new column to the table
EDITOR="echo 'ALTER TABLE posts ADD COLUMN created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP;' >" \
atlas migrate new --dir=file://./config/integration/mysql-migrations --edit
# Update migration directory configmap, and expect the new migration to be applied.
kubectl create configmap migration-dir --from-file=./config/integration/migration/mysql-migrations \
--dry-run=client -o yaml | kubectl apply -f -
kubectl wait --for=condition=ready --timeout=120s atlasmigrations --all
# Expect the new column to be present.
kubectl exec $POD_MYSQL -- mysql -uroot -h 127.0.0.1 -ppass -e "SHOW COLUMNS FROM myapp.posts LIKE 'created_at';"