Skip to content

Commit 9943131

Browse files
committed
Merge remote-tracking branch 'origin/main' into k0s-1-29
2 parents 1e689bb + 57e5dc8 commit 9943131

File tree

14 files changed

+1052
-762
lines changed

14 files changed

+1052
-762
lines changed

.github/actions/e2e/action.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ inputs:
2525
version-specifier:
2626
description: 'the git sha or tag used to generate application version strings'
2727
required: true
28+
github-token:
29+
description: 'the ci github token used to install the replicated cli'
30+
required: false # this is only needed for cmx-based tests
31+
cmx-api-token:
32+
description: 'the token used to access the replicated api for cmx'
33+
required: false # this is only needed for cmx-based tests
34+
cmx-ssh-private-key:
35+
description: 'the private key used to access the cmx nodes'
36+
required: false # this is only needed for cmx-based tests
2837
upgrade-target-ec-version:
2938
description: 'the embedded cluster version to expect after upgrades complete'
3039
required: false # this is only set by post-release testing
@@ -73,11 +82,28 @@ runs:
7382
with:
7483
go-version-file: go.mod
7584
cache-dependency-path: "**/*.sum"
85+
- name: Install replicated CLI for CMX
86+
if: ${{ inputs.cmx-api-token != '' }}
87+
shell: bash
88+
env:
89+
GH_TOKEN: ${{ inputs.github-token }}
90+
run: |
91+
gh release download --repo replicatedhq/replicated --pattern '*_linux_amd64.tar.gz' --output /tmp/replicated.tar.gz --clobber
92+
tar -xzf /tmp/replicated.tar.gz -C /tmp
93+
mv /tmp/replicated /usr/local/bin/replicated
94+
- name: Setup SSH for CMX
95+
if: ${{ inputs.cmx-ssh-private-key != '' }}
96+
shell: bash
97+
run: |
98+
mkdir -p ~/.ssh
99+
echo "${{ inputs.cmx-ssh-private-key }}" > ~/.ssh/id_ed25519
100+
chmod 600 ~/.ssh/id_ed25519
76101
- name: E2E
77102
shell: bash
78103
run: |
79104
export SHORT_SHA=${{ inputs.version-specifier }}
80105
echo "${SHORT_SHA}"
106+
export REPLICATED_API_TOKEN=${{ inputs.cmx-api-token }}
81107
export DR_AWS_S3_ENDPOINT=https://s3.amazonaws.com
82108
export DR_AWS_S3_REGION=us-east-1
83109
export DR_AWS_S3_BUCKET=kots-testim-snapshots

.github/workflows/ci.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -734,19 +734,15 @@ jobs:
734734
- TestProxiedCustomCIDR
735735
- TestInstallWithPrivateCAs
736736
- TestInstallWithMITMProxy
737+
- TestMultiNodeAirgapUpgrade
738+
- TestMultiNodeAirgapUpgradeSameK0s
739+
- TestMultiNodeAirgapUpgradePreviousStable
740+
- TestMultiNodeAirgapHAInstallation
737741
include:
738-
- test: TestMultiNodeAirgapUpgrade
739-
runner: embedded-cluster-2
740-
- test: TestMultiNodeAirgapUpgradeSameK0s
741-
runner: embedded-cluster-2
742-
- test: TestMultiNodeAirgapUpgradePreviousStable
743-
runner: embedded-cluster-2
744742
- test: TestAirgapUpgradeFromEC18
745743
runner: embedded-cluster-2
746744
- test: TestSingleNodeAirgapDisasterRecovery
747745
runner: embedded-cluster-2
748-
- test: TestMultiNodeAirgapHAInstallation
749-
runner: embedded-cluster-2
750746
- test: TestMultiNodeAirgapHADisasterRecovery
751747
runner: embedded-cluster-2
752748
steps:
@@ -768,6 +764,9 @@ jobs:
768764
k0s-version-previous: ${{ needs.build-previous-k0s.outputs.k0s_version }}
769765
k0s-version-previous-stable: ${{ needs.find-previous-stable.outputs.k0s_version }}
770766
version-specifier: ${{ needs.export-version-specifier.outputs.version_specifier }}
767+
github-token: ${{ secrets.GITHUB_TOKEN }}
768+
cmx-api-token: ${{ secrets.CMX_REPLICATED_API_TOKEN }}
769+
cmx-ssh-private-key: ${{ secrets.CMX_SSH_PRIVATE_KEY }}
771770

772771
e2e-main:
773772
name: E2E (on merge)

.github/workflows/release-prod.yaml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,23 +563,17 @@ jobs:
563563
- TestProxiedCustomCIDR
564564
- TestInstallWithPrivateCAs
565565
- TestInstallWithMITMProxy
566+
- TestMultiNodeAirgapUpgrade
567+
- TestMultiNodeAirgapUpgradeSameK0s
568+
- TestMultiNodeAirgapUpgradePreviousStable
569+
- TestMultiNodeAirgapHAInstallation
566570
include:
567-
- test: TestMultiNodeAirgapUpgrade
568-
runner: embedded-cluster-2
569-
- test: TestMultiNodeAirgapUpgradeSameK0s
570-
runner: embedded-cluster-2
571-
- test: TestMultiNodeAirgapUpgradePreviousStable
572-
runner: embedded-cluster-2
573571
- test: TestAirgapUpgradeFromEC18
574572
runner: embedded-cluster-2
575573
- test: TestSingleNodeAirgapDisasterRecovery
576574
runner: embedded-cluster-2
577-
- test: TestMultiNodeAirgapHAInstallation
578-
runner: embedded-cluster-2
579575
- test: TestMultiNodeAirgapHADisasterRecovery
580576
runner: embedded-cluster-2
581-
- test: TestFiveNodesAirgapUpgrade
582-
runner: embedded-cluster-2
583577
steps:
584578
- name: Checkout
585579
uses: actions/checkout@v4

e2e/README.md

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
1-
## E2E tests
1+
## E2E Tests
2+
3+
### Buildting the release for E2E tests
4+
5+
```bash
6+
export ARCH=amd64
7+
export APP_VERSION="appver-dev-local-$USER"
8+
./scripts/build-and-release.sh
9+
```
10+
11+
### Running individual CMX tests locally
12+
13+
You can run a single test with:
14+
15+
```bash
16+
export SHORT_SHA="dev-local-$USER"
17+
export LICENSE_ID="$EC_SMOKE_TEST_LICENSE_ID"
18+
make e2e-test TEST_NAME=TestSomething
19+
```
20+
21+
TestSomething is the name of the test function you want to run.
22+
23+
### Running individual Docker tests locally
24+
25+
You can run a single test with:
26+
27+
```bash
28+
export SHORT_SHA="dev-local-$USER"
29+
export LICENSE_ID="$EC_SMOKE_TEST_LICENSE_ID"
30+
make e2e-test TEST_NAME=TestSomething
31+
```
32+
33+
TestSomething is the name of the test function you want to run.
34+
35+
### Adding more tests
36+
37+
Tests are added as Go tests in the e2e/ directory.
38+
Tests must be added to the ci.yaml and release-prod.yaml GitHub workflows to be run in CI.
39+
40+
### Kots test application
41+
42+
During end to end tests we embed a license for a smoke test kots app.
43+
This app can be found under the 'Replicated, Inc.' team on staging:
44+
45+
https://vendor.staging.replicated.com/apps/embedded-cluster-smoke-test-staging-app
46+
47+
New releases are created using the corresponding YAML files in the e2e/kots-release-* directories.
48+
49+
### Playwright
50+
51+
We use [Playwright](https://playwright.dev/) to run end to end tests on the UI.
52+
The tests live in the `playwright` directory.
53+
54+
For more details on how to write tests with Playwright, refer to the [Playwright documentation](https://playwright.dev/docs/writing-tests).
55+
56+
## DEPRECATED: E2E tests
257

358
Integration tests depends on LXD. The following procedure shows
459
how to get everything installed on Ubuntu 22.04.
@@ -31,45 +86,3 @@ Scripts inside the `scripts` directory are copied to all nodes.
3186
If you have a new test you want to add then start by creating a
3287
shell script to execute it and save it under the `scripts` dir.
3388
You can then call the script from your Go code.
34-
35-
### Running all the tests
36-
37-
You can run the tests from within this directory:
38-
39-
```
40-
$ make e2e-tests
41-
```
42-
43-
### Running individual tests
44-
45-
You can run a single test with:
46-
47-
```
48-
$ make e2e-test TEST_NAME=TestSomething
49-
```
50-
51-
TestSomething is the name of the test function you want to run.
52-
53-
### Adding more tests
54-
55-
To add more tests you just need to create one inside this directory
56-
and then add it to the `.github/workflows/e2e.yaml` file.
57-
58-
59-
### Kots test application
60-
61-
During end to end tests we embed a license for a smoke test kots app,
62-
this app can be found under the 'Replicated, Inc.' team on staging:
63-
64-
https://vendor.staging.replicated.com/apps/embedded-cluster-smoke-test-staging-app
65-
66-
Make sure to update the application yaml files under kots-release-onmerge
67-
and kots-release-onpr directories if you create a new release of the remote
68-
application.
69-
70-
### Playwright
71-
72-
We use [Playwright](https://playwright.dev/) to run end to end tests on the UI.
73-
The tests live in the `playwright` directory.
74-
75-
For more details on how to write tests with Playwright, refer to the [Playwright documentation](https://playwright.dev/docs/writing-tests).

e2e/airgap.go

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ import (
44
"fmt"
55
"net/http"
66
"os"
7+
"regexp"
8+
"strconv"
9+
"strings"
710
"testing"
811
"time"
12+
13+
"github.com/replicatedhq/embedded-cluster/e2e/cluster"
14+
)
15+
16+
const (
17+
AirgapInstallBundlePath = "/assets/ec-release.tgz"
18+
AirgapUpgradeBundlePath = "/assets/ec-release-upgrade.tgz"
19+
AirgapUpgrade2BundlePath = "/assets/ec-release-upgrade2.tgz"
920
)
1021

1122
// downloadAirgapBundle downloads the airgap bundle for the given version to the destination path.
@@ -30,7 +41,7 @@ func downloadAirgapBundle(t *testing.T, versionLabel string, destPath string, li
3041
}
3142
time.Sleep(1 * time.Minute)
3243
}
33-
return fmt.Errorf("failed to download airgap bundle for version %s after 5 attempts", versionLabel)
44+
return fmt.Errorf("failed to download airgap bundle for version %s after 20 attempts", versionLabel)
3445
}
3546

3647
func maybeDownloadAirgapBundle(versionLabel string, destPath string, licenseID string) (int64, error) {
@@ -68,3 +79,52 @@ func maybeDownloadAirgapBundle(versionLabel string, destPath string, licenseID s
6879

6980
return size, nil
7081
}
82+
83+
func downloadAirgapBundleOnNode(t *testing.T, tc cluster.Cluster, node int, versionLabel string, destPath string, licenseID string) error {
84+
for range 20 {
85+
size, err := maybeDownloadAirgapBundleOnNode(tc, node, versionLabel, destPath, licenseID)
86+
if err != nil {
87+
// when we deploy the api to staging it interrupts the download
88+
t.Logf("failed to download airgap bundle for version %s on node %d with error %q, retrying", versionLabel, node, err)
89+
} else {
90+
if size > 1 { // more than a GB
91+
t.Logf("downloaded airgap bundle on node %d to %s (%.1f GB)", node, destPath, size)
92+
return nil
93+
}
94+
t.Logf("downloaded airgap bundle on node %d to %s (%.1f GB), retrying as it is less than 1GB", node, destPath, size)
95+
}
96+
time.Sleep(1 * time.Minute)
97+
}
98+
return fmt.Errorf("failed to download airgap bundle for version %s on node %d after 20 attempts", versionLabel, node)
99+
}
100+
101+
func maybeDownloadAirgapBundleOnNode(tc cluster.Cluster, node int, versionLabel string, destPath string, licenseID string) (float64, error) {
102+
// download airgap bundle
103+
airgapURL := fmt.Sprintf("https://staging.replicated.app/embedded/embedded-cluster-smoke-test-staging-app/ci-airgap/%s?airgap=true", versionLabel)
104+
105+
stdout, stderr, err := tc.RunCommandOnNode(node, []string{"curl", "-f", "-H", fmt.Sprintf("'Authorization: %s'", licenseID), "-L", airgapURL, "-o", destPath})
106+
if err != nil {
107+
return 0, fmt.Errorf("failed to download airgap bundle: %v: %s: %s", err, stdout, stderr)
108+
}
109+
110+
// get the size of the file on the node
111+
stdout, stderr, err = tc.RunCommandOnNode(node, []string{"du", "-h", destPath, "|", "awk", "'{print $1}'"})
112+
if err != nil {
113+
return 0, fmt.Errorf("failed to check file size: %v: %s: %s", err, stdout, stderr)
114+
}
115+
116+
sizeStr := strings.TrimSpace(stdout)
117+
118+
// match only if the size is in gigabytes
119+
re := regexp.MustCompile(`(?i)^([\d.]+)G$`)
120+
matches := re.FindStringSubmatch(sizeStr)
121+
if matches == nil {
122+
return 0, fmt.Errorf("file size is not in gigabytes: %s", sizeStr)
123+
}
124+
125+
size, err := strconv.ParseFloat(matches[1], 64)
126+
if err != nil {
127+
return 0, fmt.Errorf("failed to parse numeric value: %w", err)
128+
}
129+
return size, nil
130+
}

0 commit comments

Comments
 (0)