Skip to content

Commit 51aa80a

Browse files
authoredDec 27, 2024
Add compatibility tests, first iteration (#276)
1 parent bd1d256 commit 51aa80a

39 files changed

+1346
-495
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Added
2+
body: compatibility tests running automatically on each new tag
3+
time: 2024-12-04T15:35:50.352507104+01:00
+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: compatibility-tests
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
test-compatibility:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Maximize build space
14+
uses: AdityaGarg8/remove-unwanted-software@v4.1
15+
with:
16+
remove-android: 'true'
17+
remove-haskell: 'true'
18+
remove-codeql: 'true'
19+
remove-dotnet: 'true'
20+
remove-swapfile: 'true'
21+
22+
- name: checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # we need to know about previous tags
26+
27+
- name: print the latest version without "v"
28+
id: latest-no-v
29+
uses: miniscruff/changie-action@v2
30+
with:
31+
version: latest
32+
args: latest --remove-prefix
33+
34+
- name: determine-versions
35+
run: |
36+
NEW_VERSION=${{ steps.latest-no-v.outputs.output }}
37+
38+
# Extract the major and minor parts of the version
39+
MAJOR=$(echo $NEW_VERSION | cut -d. -f1)
40+
MINOR=$(echo $NEW_VERSION | cut -d. -f2)
41+
PREV_MINOR=$((MINOR - 1))
42+
43+
# Find the previous version tag in the format "<MAJOR>.<MINOR-1>.<LATEST_PATCH>"
44+
PREVIOUS_VERSION=$(git tag -l "${MAJOR}.${PREV_MINOR}.*" | sort --version-sort | tail -1)
45+
46+
# If no previous version is found, fallback to a default or handle the error somehow
47+
if [ -z "$PREVIOUS_VERSION" ]; then
48+
echo "No previous version found, ensure your repository has proper tags."
49+
exit 1
50+
fi
51+
52+
# remove after creating 0.6.0 tag.
53+
# Basically, we are incompatible with 0.4, and while there is no 0.6 (and prev minor being 0.5),
54+
# we will run compat tests from previous patch version
55+
if [ "$PREVIOUS_VERSION" = "0.4.42" ]; then
56+
PREVIOUS_VERSION="0.5.30"
57+
fi
58+
59+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
60+
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV
61+
62+
- name: Setup Go
63+
uses: actions/setup-go@v3
64+
with:
65+
go-version: '1.22'
66+
67+
- name: Install dependencies
68+
run: |
69+
sudo apt-get update
70+
sudo apt-get install -y build-essential
71+
72+
curl -LO https://dl.k8s.io/release/v1.25.3/bin/linux/amd64/kubectl
73+
chmod +x ./kubectl && sudo mv ./kubectl /usr/local/bin
74+
75+
HELM_VERSION="v3.10.3"
76+
curl -sSL https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar -zxvf - --strip-components=1 linux-amd64/helm
77+
chmod +x ./helm && sudo mv ./helm /usr/local/bin
78+
79+
go install sigs.k8s.io/kind@v0.25.0
80+
81+
curl -sSL https://storage.yandexcloud.net/yandexcloud-ydb/install.sh | bash
82+
83+
echo "$(pwd)" >> $GITHUB_PATH
84+
echo "$HOME/ydb/bin" >> $GITHUB_PATH
85+
echo "$HOME/go/bin" >> $GITHUB_PATH
86+
87+
- name: Check dependencies
88+
run: |
89+
gcc --version
90+
go version
91+
kind version
92+
kubectl version --client=true
93+
helm version
94+
ydb version
95+
96+
- name: Setup k8s cluster
97+
run: |
98+
kind create cluster \
99+
--image=kindest/node:v1.31.2@sha256:18fbefc20a7113353c7b75b5c869d7145a6abd6269154825872dc59c1329912e \
100+
--config=./tests/cfg/kind-cluster-config.yaml
101+
102+
kubectl wait --timeout=5m --for=condition=ready node -l worker=true
103+
104+
- name: Run compatibility tests
105+
env:
106+
NEW_VERSION: ${{ env.NEW_VERSION }}
107+
PREVIOUS_VERSION: ${{ env.PREVIOUS_VERSION }}
108+
run: |
109+
go install gotest.tools/gotestsum@v1.12.0
110+
gotestsum --format pkgname --jsonfile log.json -- -v -timeout 3600s -p 1 ./tests/compatibility/... -ginkgo.vv -coverprofile cover.out
111+
112+
- name: convert-to-human-readable
113+
run: jq -r '.Output| gsub("[\\n]"; "")' log.json 2>/dev/null 1>log.txt || true
114+
115+
- name: artifact-upload-step
116+
uses: actions/upload-artifact@v4
117+
id: artifact-upload-step
118+
if: always()
119+
with:
120+
name: compat-tests-log
121+
path: log.txt
122+
if-no-files-found: error
123+
124+
- name: echo-tests-log-url
125+
run: echo 'Unit tests log URL is ${{ steps.artifact-upload-step.outputs.artifact-url }}'
126+
127+
- name: Teardown k8s cluster
128+
run: |
129+
kind delete cluster

‎.github/workflows/run-tests.yml

+5-10
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
sudo apt-get update
8383
sudo apt-get install -y build-essential
8484
85-
go install sigs.k8s.io/kind@v0.17.0
85+
go install sigs.k8s.io/kind@v0.25.0
8686
8787
curl -LO https://dl.k8s.io/release/v1.25.3/bin/linux/amd64/kubectl
8888
chmod +x ./kubectl
@@ -108,14 +108,10 @@ jobs:
108108
run: |
109109
kind delete cluster
110110
kind create cluster \
111-
--image=kindest/node:v1.25.3@sha256:cd248d1438192f7814fbca8fede13cfe5b9918746dfa12583976158a834fd5c5 \
112-
--config=./e2e/kind-cluster-config.yaml
111+
--image=kindest/node:v1.31.2@sha256:18fbefc20a7113353c7b75b5c869d7145a6abd6269154825872dc59c1329912e \
112+
--config=./tests/cfg/kind-cluster-config.yaml
113113
114114
kubectl wait --timeout=5m --for=condition=ready node -l worker=true
115-
116-
kubectl label --overwrite node kind-worker topology.kubernetes.io/zone=fakeZone1
117-
kubectl label --overwrite node kind-worker2 topology.kubernetes.io/zone=fakeZone2
118-
kubectl label --overwrite node kind-worker3 topology.kubernetes.io/zone=fakeZone3
119115
- name: build-operator-image
120116
uses: docker/build-push-action@v3
121117
with:
@@ -138,7 +134,7 @@ jobs:
138134
kind load docker-image k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.0 --nodes kind-worker,kind-worker2,kind-worker3
139135
- name: pull-and-load-ydb-image
140136
run: |
141-
YDB_IMAGE=$(grep "anchor_for_fetching_image_from_workflow" ./e2e/tests/**/*.go | grep -o -E '"cr\.yandex.*"')
137+
YDB_IMAGE=$(grep "anchor_for_fetching_image_from_workflow" ./tests/**/*.go | grep -o -E '"cr\.yandex.*"')
142138
YDB_IMAGE=${YDB_IMAGE:1:-1} # strip ""
143139
docker pull $YDB_IMAGE
144140
kind load docker-image $YDB_IMAGE --nodes kind-worker,kind-worker2,kind-worker3
@@ -148,7 +144,7 @@ jobs:
148144
- name: run-e2e-tests
149145
id: run-e2e-tests
150146
run: |
151-
gotestsum --format pkgname --jsonfile log.json -- -v -timeout 3600s -p 1 ./e2e/... -ginkgo.vv
147+
gotestsum --format pkgname --jsonfile log.json -- -v -timeout 3600s -p 1 ./tests/e2e/... -ginkgo.vv
152148
- name: convert-json-log-to-human-readable
153149
run: jq -r '.Output| gsub("[\\n]"; "")' log.json 2>/dev/null 1>log.txt || true
154150
- name: artifact-upload-step
@@ -164,4 +160,3 @@ jobs:
164160
- name: teardown-k8s-cluster
165161
run: |
166162
kind delete cluster
167-

‎.golangci.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,22 @@ output:
3737
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
3838
format: colored-line-number
3939

40-
# print lines of code with issue, default is true
4140
print-issued-lines: true
4241

43-
# print linter name in the end of issue text, default is true
4442
print-linter-name: true
4543

4644

4745
# all available settings of specific linters
4846
linters-settings:
47+
stylecheck:
48+
dot-import-whitelist:
49+
# used in tests only
50+
- "github.com/onsi/ginkgo/v2"
51+
# used in tests only
52+
- "github.com/onsi/gomega"
53+
# it's nice having string constants in a separate package, but without boilerplate
54+
- "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants"
55+
4956
errcheck:
5057
# report about not checking of errors in types assetions: `a := b.(MyStruct)`;
5158
# default is false: such cases aren't reported by default.
@@ -77,6 +84,7 @@ linters-settings:
7784
excludes:
7885
- G101
7986
- G115
87+
- G601 # no longer actual since 1.22
8088
fieldalignment:
8189
# print struct with more effective memory layout or not, false by default
8290
suggest-new: true

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[![run-tests](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/run-tests.yml/badge.svg)](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/run-tests.yml)
21
[![upload-artifacts](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/upload-artifacts.yml/badge.svg)](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/upload-artifacts.yml)
2+
[![compatibility-tests](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/compatibility-tests.yaml/badge.svg)](https://github.com/ydb-platform/ydb-kubernetes-operator/actions/workflows/compatibility-tests.yaml)
33

44
# YDB Kubernetes Operator
55

‎docs/tests.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ containers on a single machine. This allows for full-blown smoke tests - apply t
4343
`Storage` manifests, wait until the `Pod`s become available, run `SELECT 1` inside
4444
one of those pods to check that YDB is actually up and running!
4545

46-
E2E tests are located in [e2e](../e2e) folder.
46+
E2E tests are located in [tests/e2e](../tests/e2e) folder.
4747

4848
## Running tests
4949

@@ -81,7 +81,7 @@ kind delete cluster --name=local-kind
8181
kind create cluster \
8282
--image=kindest/node:v1.21.14@sha256:9d9eb5fb26b4fbc0c6d95fa8c790414f9750dd583f5d7cee45d92e8c26670aa1 \
8383
--name=local-kind \
84-
--config=./e2e/kind-cluster-config.yaml \
84+
--config=./tests/cfg/kind-cluster-config.yaml \
8585
--wait 5m
8686

8787
# Switch your local kubeconfig to the newly created cluster:
@@ -92,7 +92,7 @@ kubectl config use-context kind-local-kind
9292
# kind/ydb-operator:current
9393

9494
# You have to download the ydb image and build the operator image yourself. Then, explicitly
95-
# upload them into the kind cluster. Refer to `./github/e2e.yaml` github workflow which essentially
95+
# upload them into the kind cluster. Refer to `./github/workflows/run-tests.yaml` github workflow which essentially
9696
# does the same thing.
9797
kind --name local-kind load docker-image kind/ydb-operator:current
9898
kind --name local-kind load docker-image ydb:<version>

‎e2e/operator-values.yaml

-10
This file was deleted.

‎e2e/tests/data/ca.crt

-19
This file was deleted.

‎e2e/tests/data/tls.crt

-21
This file was deleted.

‎e2e/tests/data/tls.key

-27
This file was deleted.

‎internal/controllers/database/controller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
"sigs.k8s.io/controller-runtime/pkg/manager"
2222

2323
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
24-
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
2524
. "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants"
2625
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/database"
2726
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
2827
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
28+
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/tests/test-k8s-objects"
2929
)
3030

3131
var (
@@ -65,7 +65,7 @@ var _ = Describe("Database controller medium tests", func() {
6565
},
6666
}
6767
Expect(k8sClient.Create(ctx, &namespace)).Should(Succeed())
68-
storageSample = *testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-mirror-3-dc-config.yaml"))
68+
storageSample = *testobjects.DefaultStorage(filepath.Join("..", "..", "..", "tests", "data", "storage-mirror-3-dc-config.yaml"))
6969
Expect(k8sClient.Create(ctx, &storageSample)).Should(Succeed())
7070

7171
By("checking that Storage created on local cluster...")

‎internal/controllers/databasenodeset/controller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/manager"
1717

1818
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
19-
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
2019
. "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants"
2120
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/database"
2221
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/databasenodeset"
2322
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
2423
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
24+
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/tests/test-k8s-objects"
2525
)
2626

2727
const (
@@ -71,7 +71,7 @@ var _ = Describe("DatabaseNodeSet controller medium tests", func() {
7171
}
7272
Expect(k8sClient.Create(ctx, &namespace)).Should(Succeed())
7373

74-
storageSample = *testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-mirror-3-dc-config.yaml"))
74+
storageSample = *testobjects.DefaultStorage(filepath.Join("..", "..", "..", "tests", "data", "storage-mirror-3-dc-config.yaml"))
7575
Expect(k8sClient.Create(ctx, &storageSample)).Should(Succeed())
7676

7777
By("checking that Storage created on local cluster...")

‎internal/controllers/monitoring/monitoring_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/manager"
1717

1818
api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
19-
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
2019
. "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants" //nolint:revive,stylecheck
2120
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/monitoring"
2221
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
2322
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
23+
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/tests/test-k8s-objects"
2424
)
2525

2626
var (
@@ -119,7 +119,7 @@ func createMockDBAndSvc() {
119119
func createMockStorageAndSvc() {
120120
GinkgoHelper()
121121

122-
stor := testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-mirror-3-dc-config.yaml"))
122+
stor := testobjects.DefaultStorage(filepath.Join("..", "..", "..", "tests", "data", "storage-mirror-3-dc-config.yaml"))
123123
Expect(k8sClient.Create(ctx, stor)).Should(Succeed())
124124

125125
stor.Status.State = StorageReady

0 commit comments

Comments
 (0)