Skip to content

Commit d373c05

Browse files
chore: adding end to end tests (#31)
* chore: adding end to end tests start adding end to end tests to be run as part of gh actions. * bug: run post apply directly on localhost we don't need to use the remote connection when running the post apply in the current node. * feat: create no-prompt on token action two things were implemented here: - if --no-prompt then dump the installation failure log. - added --no-prompt on the `token` command. * bug: setting hostname overwrite on local install * bug: bring back the ssh implementation localhost option of k0sctl seems to be buggy, judging by the types of errors we are seeing in our end to end tests. this commit brings back the old ssh based implementation, if you are reading this then it means that it solved the instabilities. * tests: added token based installation test added and end to end test to validate the token based cluster creation. * chore: fixed e2e documentation * chore: remove dangling sleep call * chore: using github matrix * chore: removing unused scripts * chore: using pipefail
1 parent b45136c commit d373c05

24 files changed

+1398
-127
lines changed

.github/workflows/e2e.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: End to End
2+
on:
3+
- pull_request
4+
jobs:
5+
run:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
tests:
10+
- TestBuildBundle
11+
- TestEmbedAndInstall
12+
- TestInstallSingleNodeAndUpgradeToEmbed
13+
- TestMultiNodeInstallation
14+
- TestSingleNodeInstallation
15+
- TestTokenBasedMultiNodeInstallation
16+
steps:
17+
- name: Move Docker aside
18+
run: |
19+
sudo systemctl stop docker
20+
sudo iptables -F
21+
sudo iptables -P FORWARD ACCEPT
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
- name: Install and Configure LXD
25+
run: |
26+
sudo lxd init --auto
27+
sudo snap set lxd daemon.group=adm
28+
sudo snap restart lxd
29+
sudo lxd waitready
30+
- name: Install and configure OVN
31+
run: |
32+
sudo apt install ovn-host ovn-central -y
33+
sudo ovs-vsctl set open_vswitch . \
34+
external_ids:ovn-remote=unix:/var/run/ovn/ovnsb_db.sock \
35+
external_ids:ovn-encap-type=geneve \
36+
external_ids:ovn-encap-ip=127.0.0.1
37+
- name: Setup Go
38+
uses: actions/setup-go@v4
39+
with:
40+
go-version: "1.21.0"
41+
- name: E2E
42+
run: |
43+
make e2e-test TEST_NAME=${{ matrix.tests }}

.github/workflows/pull-request.yaml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,55 @@
11
name: Pull request
22
on:
33
- pull_request
4-
54
jobs:
5+
sanitize:
6+
name: Sanitize
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
- name: Setup Go
12+
uses: actions/setup-go@v4
13+
with:
14+
go-version: "1.21.0"
15+
- name: Go vet
16+
run: |
17+
make vet
618
tests:
7-
name: Test
19+
name: Unit tests
820
runs-on: ubuntu-latest
921
steps:
1022
- name: Checkout
1123
uses: actions/checkout@v3
12-
1324
- name: Setup Go
1425
uses: actions/setup-go@v4
1526
with:
1627
go-version: "1.21.0"
17-
1828
- name: Go vet
1929
run: |
2030
make vet
21-
2231
- name: Unit tests
2332
run: |
2433
make unit-tests
25-
26-
- name: E2E tests
27-
run: |
28-
make e2e-tests
29-
3034
build:
3135
name: Build
3236
runs-on: ubuntu-latest
33-
needs:
34-
- tests
3537
steps:
3638
- name: Checkout
3739
uses: actions/checkout@v3
38-
3940
- name: Setup Go
4041
uses: actions/setup-go@v4
4142
with:
4243
go-version: "1.21.0"
43-
4444
- name: Build Linux AMD64
4545
run: |
4646
make helmvm-linux-amd64
47-
4847
- name: Build Darwin AMD64
4948
run: |
5049
make helmvm-darwin-amd64
51-
5250
- name: Build Darwin ARM64
5351
run: |
5452
make helmvm-darwin-arm64
55-
5653
- name: Build HelmVM Builder Server Image
5754
uses: docker/build-push-action@v4
5855
with:

.github/workflows/release-dev.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name: Release
2-
32
on:
43
push:
54
branches:
65
- main
7-
86
permissions:
97
contents: write
10-
118
jobs:
129
releaser:
1310
runs-on: ubuntu-latest
@@ -16,30 +13,25 @@ jobs:
1613
uses: actions/checkout@v3
1714
with:
1815
fetch-depth: 0
19-
2016
- name: Set up Go
2117
uses: actions/setup-go@v4
2218
with:
2319
go-version: "1.20"
24-
2520
- name: Build linux-amd64
2621
run: |
2722
make helmvm-linux-amd64
2823
tar -C output/bin -czvf helmvm-linux-amd64.tgz helmvm
2924
make clean
30-
3125
- name: Build darwin-amd64
3226
run: |
3327
make helmvm-darwin-amd64
3428
tar -C output/bin -czvf helmvm-darwin-amd64.tgz helmvm
3529
make clean
36-
3730
- name: Build darwin-arm64
3831
run: |
3932
make helmvm-darwin-arm64
4033
tar -C output/bin -czvf helmvm-darwin-arm64.tgz helmvm
4134
make clean
42-
4335
- name: Publish development release
4436
uses: marvinpinto/action-automatic-releases@latest
4537
with:
@@ -49,7 +41,6 @@ jobs:
4941
title: Development Release Build
5042
files: |
5143
*.tgz
52-
5344
- name: Build HelmVM Builder Server image
5445
uses: docker/build-push-action@v4
5546
with:

.github/workflows/release-prod.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name: Release
2-
32
on:
43
push:
54
tags:
65
- "v*.*.*"
7-
86
permissions:
97
contents: write
10-
118
jobs:
129
releaser:
1310
runs-on: ubuntu-latest
@@ -24,43 +21,36 @@ jobs:
2421
uses: actions/setup-go@v4
2522
with:
2623
go-version: "1.20"
27-
2824
- name: Build linux-amd64
2925
run: |
3026
make helmvm-linux-amd64
3127
tar -C output/bin -czvf helmvm-linux-amd64.tgz helmvm
3228
make clean
33-
3429
- name: Build darwin-amd64
3530
run: |
3631
make helmvm-darwin-amd64
3732
tar -C output/bin -czvf helmvm-darwin-amd64.tgz helmvm
3833
make clean
39-
4034
- name: Build darwin-arm64
4135
run: |
4236
make helmvm-darwin-arm64
4337
tar -C output/bin -czvf helmvm-darwin-arm64.tgz helmvm
4438
make clean
45-
4639
- name: Publish release
4740
uses: marvinpinto/action-automatic-releases@latest
4841
with:
4942
repo_token: ${{ secrets.GITHUB_TOKEN }}
5043
prerelease: false
5144
files: |
5245
*.tgz
53-
5446
- name: Set up Docker Buildx
5547
uses: docker/setup-buildx-action@v2
56-
5748
- name: Login to GitHub Container Registry
5849
uses: docker/login-action@v2
5950
with:
6051
registry: ghcr.io
6152
username: ${{ github.actor }}
6253
password: ${{ secrets.GITHUB_TOKEN }}
63-
6454
- name: Build and Publish HelmVM Builder Server image.
6555
uses: docker/build-push-action@v4
6656
with:

Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,29 @@ builder: static static-linux-amd64
125125

126126
.PHONY: unit-tests
127127
unit-tests:
128-
go test -v ./...
128+
go test -v $(shell go list ./... | grep -v /e2e)
129129

130130
.PHONY: vet
131131
vet: static-linux-amd64 static
132132
go vet ./...
133133

134134
.PHONY: e2e-tests
135-
e2e-tests:
136-
echo to be implemented
135+
e2e-tests: helmvm-linux-amd64
136+
mkdir -p output/tmp
137+
rm -rf output/tmp/id_rsa*
138+
ssh-keygen -t rsa -N "" -C "Integration Test Key" -f output/tmp/id_rsa
139+
go test -timeout 45m -parallel 1 -failfast -v ./e2e
140+
141+
.PHONY: e2e-test
142+
e2e-test: helmvm-linux-amd64
143+
mkdir -p output/tmp
144+
rm -rf output/tmp/id_rsa*
145+
ssh-keygen -t rsa -N "" -C "Integration Test Key" -f output/tmp/id_rsa
146+
go test -timeout 10m -v ./e2e -run $(TEST_NAME)
147+
148+
.PHONY: create-e2e-workflows
149+
create-e2e-workflows:
150+
./e2e/hack/create-e2e-workflows.sh
137151

138152
.PHONY: clean
139153
clean:

cmd/helmvm/install.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func runPostApply(ctx context.Context) error {
4545
return fmt.Errorf("unable to read cluster config: %w", err)
4646
}
4747
for _, host := range cfg.Spec.Hosts {
48-
if err := runPostApplyOnHost(ctx, host, logger); err != nil {
48+
if err := runPostApplyOnHost(ctx, host); err != nil {
4949
return err
5050
}
5151
}
@@ -55,7 +55,7 @@ func runPostApply(ctx context.Context) error {
5555
// runPostApply runs the post-apply script on a host. XXX I don't think this
5656
// belongs here and needs to be refactored in a more generic way. It's here
5757
// because I have other things to do and this is a prototype.
58-
func runPostApplyOnHost(ctx context.Context, host *cluster.Host, logger pb.MessageWriter) error {
58+
func runPostApplyOnHost(ctx context.Context, host *cluster.Host) error {
5959
if err := host.Connect(); err != nil {
6060
return fmt.Errorf("failed to connect to host: %w", err)
6161
}
@@ -280,6 +280,10 @@ func applyK0sctl(c *cli.Context, prompt bool, nodes []infra.Node) error {
280280
logrus.Infof("Applying cluster configuration")
281281
if err := runK0sctlApply(c.Context); err != nil {
282282
logrus.Errorf("Installation or upgrade failed.")
283+
if !prompt {
284+
dumpApplyLogs()
285+
return fmt.Errorf("unable to apply cluster: %w", err)
286+
}
283287
var useCurrent = &survey.Confirm{
284288
Message: "Do you wish to visualize the logs?",
285289
Default: true,

cmd/helmvm/token.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ var tokenCreateCommand = &cli.Command{
3636
Usage: "For how long the token should be valid",
3737
Value: 24 * time.Hour,
3838
},
39+
&cli.BoolFlag{
40+
Name: "no-prompt",
41+
Usage: "Do not prompt user when it is not necessary",
42+
Value: false,
43+
},
3944
},
4045
Action: func(c *cli.Context) error {
4146
if runtime.GOOS != "linux" {
@@ -48,6 +53,7 @@ var tokenCreateCommand = &cli.Command{
4853
if role != "worker" && role != "controller" {
4954
return fmt.Errorf("invalid role %q", role)
5055
}
56+
prompt := !c.Bool("no-prompt")
5157
cfgpath := defaults.PathToConfig("k0sctl.yaml")
5258
if _, err := os.Stat(cfgpath); err != nil {
5359
if os.IsNotExist(err) {
@@ -63,14 +69,17 @@ var tokenCreateCommand = &cli.Command{
6369
logrus.Warn("Through the centralized management you can manage all your")
6470
logrus.Warn("cluster nodes from a single location. If you decide to move")
6571
logrus.Warn("on the centralized management won't be available anymore")
66-
question := &survey.Confirm{
67-
Message: "Do you want to use continue ?", Default: true,
68-
}
69-
var moveOn bool
70-
if err := survey.AskOne(question, &moveOn); err != nil {
71-
return fmt.Errorf("unable to ask for user confirmation: %w", err)
72-
} else if !moveOn {
73-
return nil
72+
if prompt {
73+
question := &survey.Confirm{
74+
Message: "Do you want to use continue ?",
75+
Default: true,
76+
}
77+
var moveOn bool
78+
if err := survey.AskOne(question, &moveOn); err != nil {
79+
return fmt.Errorf("unable to ask for confirmation: %w", err)
80+
} else if !moveOn {
81+
return nil
82+
}
7483
}
7584
}
7685
dur := c.Duration("expiry").String()
@@ -90,7 +99,7 @@ var tokenCreateCommand = &cli.Command{
9099
logrus.Infof("This token is valid for %s hours.", dur)
91100
logrus.Infof("You can now run the following command in a remote node to add it")
92101
logrus.Infof("to the cluster as a %q node:", role)
93-
fmt.Printf("%s node join --role %q %s", defaults.BinaryName(), role, buf.String())
102+
fmt.Printf("%s node join --role %s %s", defaults.BinaryName(), role, buf.String())
94103
return nil
95104
},
96105
}

0 commit comments

Comments
 (0)