Skip to content

Commit 762c473

Browse files
authored
Merge pull request #27 from hakman/tests
Don't use Bazel for tests
2 parents 72094cb + 0cec522 commit 762c473

File tree

15 files changed

+274
-69
lines changed

15 files changed

+274
-69
lines changed

.github/workflows/bazel.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Bazel
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Install bazelisk
15+
run: |
16+
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
17+
mkdir -p "${GITHUB_WORKSPACE}/bin/"
18+
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
19+
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
20+
21+
- name: Build etcd-manager
22+
run: |
23+
./dev/build-assets.sh $(git describe --always 2>/dev/null)
24+
25+
test:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Install bazelisk
32+
run: |
33+
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
34+
mkdir -p "${GITHUB_WORKSPACE}/bin/"
35+
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
36+
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
37+
38+
- name: Test etcd-manager
39+
run: |
40+
"${GITHUB_WORKSPACE}/bin/bazel" test --test_output=streamed -- //... -//test/integration/upgradedowngrade:all -//test/integration/backuprestore:all
41+
42+
test-upgradedowngrade:
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Install bazelisk
49+
run: |
50+
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
51+
mkdir -p "${GITHUB_WORKSPACE}/bin/"
52+
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
53+
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
54+
55+
- name: Test etcd-manager
56+
run: |
57+
"${GITHUB_WORKSPACE}/bin/bazel" test --test_output=streamed -- //test/integration/upgradedowngrade:all
58+
59+
test-backuprestore:
60+
runs-on: ubuntu-latest
61+
62+
steps:
63+
- uses: actions/checkout@v4
64+
65+
- name: Install bazelisk
66+
run: |
67+
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
68+
mkdir -p "${GITHUB_WORKSPACE}/bin/"
69+
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
70+
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
71+
72+
- name: Test etcd-manager
73+
run: |
74+
"${GITHUB_WORKSPACE}/bin/bazel" test --test_output=streamed -- //test/integration/backuprestore:all

.github/workflows/ko.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Bazel
1+
name: CI
22

33
on:
44
- push
@@ -7,68 +7,42 @@ on:
77
jobs:
88
build:
99
runs-on: ubuntu-latest
10-
1110
steps:
1211
- uses: actions/checkout@v4
13-
14-
- name: Install bazelisk
12+
with:
13+
fetch-tags: 'true'
14+
- name: Build etcd-manager-slim
1515
run: |
16-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
17-
mkdir -p "${GITHUB_WORKSPACE}/bin/"
18-
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
19-
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
20-
21-
- name: Build etcd-manager
22-
run: |
23-
./dev/build-assets.sh $(git describe --always 2>/dev/null)
16+
make ko-dist
2417
2518
test:
2619
runs-on: ubuntu-latest
27-
2820
steps:
2921
- uses: actions/checkout@v4
30-
31-
- name: Install bazelisk
32-
run: |
33-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
34-
mkdir -p "${GITHUB_WORKSPACE}/bin/"
35-
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
36-
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
37-
38-
- name: Test etcd-manager
22+
- name: Run tests
3923
run: |
40-
"${GITHUB_WORKSPACE}/bin/bazel" test --test_output=streamed -- //... -//test/integration/upgradedowngrade:all -//test/integration/backuprestore:all
24+
make test-short
4125
4226
test-upgradedowngrade:
4327
runs-on: ubuntu-latest
44-
4528
steps:
4629
- uses: actions/checkout@v4
47-
48-
- name: Install bazelisk
49-
run: |
50-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
51-
mkdir -p "${GITHUB_WORKSPACE}/bin/"
52-
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
53-
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
54-
55-
- name: Test etcd-manager
30+
- name: Run upgradedowngrade tests
5631
run: |
57-
"${GITHUB_WORKSPACE}/bin/bazel" test --test_output=streamed -- //test/integration/upgradedowngrade:all
32+
make test-upgradedowngrade
5833
5934
test-backuprestore:
6035
runs-on: ubuntu-latest
61-
6236
steps:
6337
- uses: actions/checkout@v4
64-
65-
- name: Install bazelisk
38+
- name: Run backuprestore tests
6639
run: |
67-
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.20.0/bazelisk-linux-amd64"
68-
mkdir -p "${GITHUB_WORKSPACE}/bin/"
69-
mv bazelisk-linux-amd64 "${GITHUB_WORKSPACE}/bin/bazel"
70-
chmod +x "${GITHUB_WORKSPACE}/bin/bazel"
40+
make test-backuprestore
7141
72-
- name: Test etcd-manager
42+
test-integration:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- name: Run integration tests
7347
run: |
74-
"${GITHUB_WORKSPACE}/bin/bazel" test --test_output=streamed -- //test/integration/backuprestore:all
48+
make test-integration

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,37 @@ ko-export-etcd-manager-slim-amd64 ko-export-etcd-manager-slim-arm64: ko-export-e
176176
.PHONY: ko-push-etcd-manager-slim
177177
ko-push-etcd-manager-slim:
178178
KO_DEFAULTBASEIMAGE="debian:12-slim" KO_DOCKER_REPO="${IMAGE_BASE}etcd-manager-slim" ${KO} build --tags ${STABLE_DOCKER_TAG} --platform=linux/amd64,linux/arm64 --bare ./cmd/etcd-manager/
179+
180+
# Must match AllEtcdVersions in pkg/etcdversions/mappings.go
181+
.PHONY: download-etcd-versions
182+
download-etcd-versions:
183+
dev/download-etcd.sh 3.1.12
184+
dev/download-etcd.sh 3.2.18
185+
dev/download-etcd.sh 3.2.24
186+
dev/download-etcd.sh 3.3.10
187+
dev/download-etcd.sh 3.3.13
188+
dev/download-etcd.sh 3.3.17
189+
dev/download-etcd.sh 3.4.3
190+
dev/download-etcd.sh 3.4.13
191+
dev/download-etcd.sh 3.5.0
192+
dev/download-etcd.sh 3.5.1
193+
dev/download-etcd.sh 3.5.3
194+
dev/download-etcd.sh 3.5.4
195+
dev/download-etcd.sh 3.5.6
196+
dev/download-etcd.sh 3.5.7
197+
198+
.PHONY: test-short
199+
test-short:
200+
go test -v -short ./...
201+
202+
.PHONY: test-integration
203+
test-integration: download-etcd-versions
204+
go test -v ./test/integration/backuprestore
205+
206+
.PHONY: test-backuprestore
207+
test-backuprestore: download-etcd-versions
208+
go test -v ./test/integration/backuprestore
209+
210+
.PHONY: test-upgradedowngrade
211+
test-upgradedowngrade: download-etcd-versions
212+
go test -v ./test/integration/upgradedowngrade

dev/download-etcd.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
ETCD_VER="v$1"
21+
ETCD_DIR="/tmp/etcd-${ETCD_VER}"
22+
ETCD_URL="https://github.com/etcd-io/etcd/releases/download/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz"
23+
ETCD_TMP="/tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz"
24+
25+
if [ ! -f "${ETCD_DIR:-}/etcd" ]; then
26+
echo "Downloading etcd from ${ETCD_URL} to ${ETCD_DIR}"
27+
curl -Ls -o "${ETCD_TMP}" "${ETCD_URL}"
28+
mkdir -p "${ETCD_DIR}"
29+
tar xzf "${ETCD_TMP}" -C "${ETCD_DIR}" --strip-components=1 --exclude=Documentation
30+
rm -f "${ETCD_TMP}"
31+
fi

pkg/etcd/etcdprocess.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package etcd
1919
import (
2020
"crypto/tls"
2121
"crypto/x509"
22-
"flag"
2322
"fmt"
2423
"net"
2524
"net/url"
@@ -41,16 +40,10 @@ import (
4140
"sigs.k8s.io/etcd-manager/pkg/pki"
4241
)
4342

44-
var baseDirs = []string{"/opt"}
43+
var baseDirs = []string{"/opt", "/tmp"}
4544
var isTest = false
4645

4746
func init() {
48-
// For bazel
49-
// TODO: Use a flag?
50-
51-
// used to fix glog parse error.
52-
_ = flag.CommandLine.Parse([]string{})
53-
5447
if os.Getenv("TEST_SRCDIR") != "" && os.Getenv("TEST_WORKSPACE") != "" {
5548
d := filepath.Join(os.Getenv("TEST_SRCDIR"), os.Getenv("TEST_WORKSPACE"))
5649
klog.Infof("found bazel binary location: %s", d)

pkg/etcdversions/mappings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var AllEtcdVersions = []string{
5757
Version_3_5_3,
5858
Version_3_5_4,
5959
Version_3_5_6,
60+
Version_3_5_7,
6061
}
6162

6263
var LatestEtcdVersions = []string{

pkg/hostmount/nsenter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build linux
2+
// +build linux
3+
14
/*
25
Copyright 2019 The Kubernetes Authors.
36
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//go:build !linux
2+
// +build !linux
3+
4+
/*
5+
Copyright 2017 The Kubernetes Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package hostmount
21+
22+
import (
23+
"fmt"
24+
"k8s.io/mount-utils"
25+
"k8s.io/utils/nsenter"
26+
)
27+
28+
func New(ne *nsenter.Nsenter) *Mounter {
29+
return &Mounter{ne: ne}
30+
}
31+
32+
type Mounter struct {
33+
ne *nsenter.Nsenter
34+
mount.Interface
35+
}
36+
37+
var _ mount.Interface = &Mounter{}
38+
39+
func (*Mounter) List() ([]mount.MountPoint, error) {
40+
return nil, fmt.Errorf("List not implemented for containerized mounter")
41+
}
42+
43+
func (n *Mounter) Mount(source string, target string, fstype string, options []string) error {
44+
return fmt.Errorf("Mount not implemented for containerized mounter")
45+
}
46+
47+
func (n *Mounter) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
48+
return fmt.Errorf("MountSensitive not implemented for containerized mounter")
49+
}
50+
51+
func (n *Mounter) GetMountRefs(pathname string) ([]string, error) {
52+
return nil, fmt.Errorf("GetMountRefs not implemented for containerized mounter")
53+
}
54+
55+
func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
56+
return false, fmt.Errorf("IsLikelyNotMountPoint not implemented for containerized mounter")
57+
}
58+
59+
func (n *Mounter) Unmount(target string) error {
60+
return fmt.Errorf("Unmount not implemented for containerized mounter")
61+
}
62+
63+
func (n *Mounter) MountSensitiveWithoutSystemd(source string, target string, fstype string, options []string, sensitiveOptions []string) error {
64+
return fmt.Errorf("MountSensitiveWithoutSystemd not implemented for containerized mounter")
65+
}
66+
67+
func (n *Mounter) MountSensitiveWithoutSystemdWithMountFlags(source string, target string, fstype string, options []string, sensitiveOptions []string, mountFlags []string) error {
68+
return fmt.Errorf("MountSensitiveWithoutSystemdWithMountFlags not implemented for containerized mounter")
69+
}

test/integration/backuprestore/backuprestore_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import (
3030
)
3131

3232
func TestBackupRestore(t *testing.T) {
33+
if testing.Short() {
34+
t.Skip("skipping test in short mode")
35+
}
36+
3337
for _, backupEtcdVersion := range etcdversions.LatestEtcdVersions {
3438
restoreEtcdVersion := etcdversions.EtcdVersionForRestore(backupEtcdVersion)
3539
t.Run("backupEtcdVersion="+backupEtcdVersion+"/restoreEtcdVersion="+restoreEtcdVersion, func(t *testing.T) {

0 commit comments

Comments
 (0)