Skip to content

Commit 3f3cd7e

Browse files
authored
ci: Run e2e in CI (#54)
* fix: make sure we fetch go version from go.mod for CI
1 parent 9c8bd47 commit 3f3cd7e

File tree

5 files changed

+142
-73
lines changed

5 files changed

+142
-73
lines changed

.github/workflows/e2e-tests.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
e2e:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
22+
- name: Determine Architecture
23+
id: arch
24+
run: |
25+
ARCH=$(uname -m)
26+
echo "ARCH=$ARCH" >> $GITHUB_OUTPUT
27+
28+
- name: Download kind CLI
29+
run: |
30+
ARCH="${{ steps.arch.outputs.ARCH }}"
31+
KIND_VERSION="v0.27.0"
32+
KIND_BINARY="kind-$ARCH"
33+
if [[ "$ARCH" == "x86_64" ]]; then
34+
KIND_BINARY="kind-linux-amd64"
35+
elif [[ "$ARCH" == "aarch64" ]]; then
36+
KIND_BINARY="kind-linux-arm64"
37+
fi
38+
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/${KIND_BINARY}"
39+
chmod +x ./kind
40+
sudo mv ./kind /usr/local/bin/kind
41+
42+
- name: Install kubectl
43+
uses: azure/setup-kubectl@v4
44+
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version-file: 'go.mod'
49+
50+
- name: Cache Go dependencies
51+
uses: actions/cache@v3
52+
with:
53+
path: |
54+
~/go/pkg/mod
55+
~/.cache/go-build
56+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
57+
restore-keys: |
58+
${{ runner.os }}-go-
59+
60+
- name: Install dependencies
61+
run: |
62+
go mod download
63+
go mod verify
64+
65+
- name: Run tests
66+
run: |
67+
make test-e2e

.github/workflows/manifest.yaml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,45 @@ name: Check Manifests
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
check-manifests:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v3
1414

15-
- name: Set up Go
16-
uses: actions/setup-go@v4
17-
with:
18-
go-version: '1.24'
19-
20-
- name: Cache Go dependencies
21-
uses: actions/cache@v3
22-
with:
23-
path: |
24-
~/go/pkg/mod
25-
~/.cache/go-build
26-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27-
restore-keys: |
28-
${{ runner.os }}-go-
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: "go.mod"
2919

30-
- name: Install dependencies
31-
run: |
32-
go mod download
33-
go mod verify
20+
- name: Cache Go dependencies
21+
uses: actions/cache@v3
22+
with:
23+
path: |
24+
~/go/pkg/mod
25+
~/.cache/go-build
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
3429
35-
- name: Generate manifests and deepcopy
36-
run: make manifests && make generate
30+
- name: Install dependencies
31+
run: |
32+
go mod download
33+
go mod verify
3734
38-
- name: Check for uncommitted changes
39-
run: |
40-
if [[ $(git status --porcelain) ]]; then
41-
echo "There are uncommitted changes in the repository after generating manifests."
42-
echo "Please run 'make manifests' and/or 'make generate' locally and commit the changes."
43-
git status
44-
git diff
45-
exit 1
46-
fi
35+
- name: Generate manifests and deepcopy
36+
run: make manifests && make generate
37+
38+
- name: Check for uncommitted changes
39+
run: |
40+
if [[ $(git status --porcelain) ]]; then
41+
echo "There are uncommitted changes in the repository after generating manifests."
42+
echo "Please run 'make manifests' and/or 'make generate' locally and commit the changes."
43+
git status
44+
git diff
45+
exit 1
46+
fi

.github/workflows/test.yaml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ name: Run Tests
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v3
1414

15-
- name: Set up Go
16-
uses: actions/setup-go@v4
17-
with:
18-
go-version: '1.24'
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: "go.mod"
1919

20-
- name: Cache Go dependencies
21-
uses: actions/cache@v3
22-
with:
23-
path: |
24-
~/go/pkg/mod
25-
~/.cache/go-build
26-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27-
restore-keys: |
28-
${{ runner.os }}-go-
20+
- name: Cache Go dependencies
21+
uses: actions/cache@v3
22+
with:
23+
path: |
24+
~/go/pkg/mod
25+
~/.cache/go-build
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
2929
30-
- name: Install dependencies
31-
run: |
32-
go mod download
33-
go mod verify
30+
- name: Install dependencies
31+
run: |
32+
go mod download
33+
go mod verify
3434
35-
- name: Run tests
36-
run: make test
35+
- name: Run tests
36+
run: make test

test/e2e/e2e_suite_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestMain(m *testing.M) {
3737
// Setup test environment
3838
testEnv.Setup(
3939
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
40-
log.Println("Creating kind cluster...")
40+
log.Println("Creating kind cluster...", kindClusterName)
4141
return envfuncs.CreateClusterWithOpts(
4242
kindCluster,
4343
kindClusterName,
@@ -71,8 +71,17 @@ func TestMain(m *testing.M) {
7171
return ctx, nil
7272
},
7373
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
74-
log.Println("Building and installing the operator...")
75-
err := utils.BuildingAndInstallingOperator(projectimage, kindClusterName)
74+
log.Println("Building the operator image...")
75+
err := utils.BuildingOperatorImage(projectimage)
76+
if err != nil {
77+
return ctx, fmt.Errorf("failed to build operator image: %w", err)
78+
}
79+
return ctx, nil
80+
},
81+
envfuncs.LoadImageToCluster(kindClusterName, projectimage),
82+
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
83+
log.Println("Installing the operator...")
84+
err := utils.InstallingOperator(projectimage, kindClusterName, kindCluster)
7685
if err != nil {
7786
return ctx, fmt.Errorf("failed to build and install operator: %w", err)
7887
}

test/utils/utils.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"os/exec"
2323
"path/filepath"
2424
"strings"
25+
26+
"sigs.k8s.io/e2e-framework/support"
2527
)
2628

2729
const (
@@ -163,23 +165,22 @@ func SetupEtcdCluster(namespace string) error {
163165
return nil
164166
}
165167

166-
func BuildingAndInstallingOperator(projectimage string, kindClusterName string) error {
168+
func BuildingOperatorImage(projectimage string) error {
167169
fmt.Println("building the manager(Operator) image")
168170
cmd := exec.Command("make", "docker-build", fmt.Sprintf("IMG=%s", projectimage))
169171
_, err := Run(cmd)
170172
if err != nil {
171173
return err
172174
}
173175

174-
fmt.Println("loading the manager(Operator) image on Kind")
175-
err = LoadImageToKindClusterWithName(projectimage, kindClusterName)
176-
if err != nil {
177-
return err
178-
}
176+
return nil
177+
}
178+
179+
func InstallingOperator(projectimage string, kindClusterName string, kindCluster support.E2EClusterProvider) error {
179180

180181
fmt.Println("installing the Operator CRD")
181-
cmd = exec.Command("make", "install")
182-
_, err = Run(cmd)
182+
cmd := exec.Command("make", "install")
183+
_, err := Run(cmd)
183184
if err != nil {
184185
return err
185186
}
@@ -232,14 +233,6 @@ func VerifyControllerUp(namespace string) error {
232233
return nil
233234
}
234235

235-
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
236-
func LoadImageToKindClusterWithName(name string, clusterName string) error {
237-
kindOptions := []string{"load", "docker-image", name, "--name", clusterName}
238-
cmd := exec.Command("kind", kindOptions...)
239-
_, err := Run(cmd)
240-
return err
241-
}
242-
243236
// GetNonEmptyLines converts given command output string into individual objects
244237
// according to line breakers, and ignores the empty elements in it.
245238
func GetNonEmptyLines(output string) []string {

0 commit comments

Comments
 (0)