From e533f2d0dd951da4c55dec812affe5b3ca110161 Mon Sep 17 00:00:00 2001 From: Jiahui <4543bxy@gmail.com> Date: Fri, 21 Jul 2023 20:17:07 +0800 Subject: [PATCH] fix e2e apply test with infra && fix wrong ssh.fetch interface method implementation (#3560) --- .github/workflows/e2e_test_apply.yml | 29 ++++++++++++++------------ pkg/ssh/scp.go | 2 +- test/e2e/suites/apply/apply.go | 18 ++++++++++++++++ test/e2e/suites/infra/check.go | 7 ++++--- test/e2e/suites/operators/image.go | 2 +- test/e2e/suites/operators/operators.go | 2 +- 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/.github/workflows/e2e_test_apply.yml b/.github/workflows/e2e_test_apply.yml index 5e03b8318..387d599e4 100644 --- a/.github/workflows/e2e_test_apply.yml +++ b/.github/workflows/e2e_test_apply.yml @@ -3,12 +3,12 @@ name: E2E Apply Test on: workflow_dispatch: pull_request_target: - types: [ opened, synchronize, reopened, labeled ] + types: [ labeled ] jobs: call_ci_workflow: uses: ./.github/workflows/import-patch-image.yml - if: ${{ contains(github.event.pull_request.labels.*.name, 'need-e2e-apply-test') }} + if: ${{ github.event.action == 'labeled' && github.event.label.name == 'need-e2e-apply-test' }} with: arch: amd64,arm64 e2e: true @@ -19,6 +19,7 @@ jobs: permissions: issues: write strategy: + fail-fast: false matrix: arch: [ arm64, amd64 ] outputs: @@ -43,26 +44,28 @@ jobs: - name: Install ginkgo && Run e2e apply test id: apply_test shell: bash + env: + SEALOS_E2E_TEST_IMAGE_NAME: hub.sealos.cn/labring/kubernetes:v1.25.6 + SEALOS_E2E_TEST_PATCH_IMAGE_TAR: /tmp/sealos/images/patch-${{ matrix.arch }}.tar.gz + SEALOS_E2E_TEST_PATCH_IMAGE_NAME: ghcr.io/labring/sealos-patch:${{ env.GIT_COMMIT_SHORT_SHA }}-${{ matrix.arch }} + SEALOS_E2E_TEST_SEALOS_BIN_PATH: /tmp/sealos/bin/sealos + ALIYUN_ACCESS_KEY_ID: ${{ secrets.E2E_ALIYUN_ACCESS_KEY_ID }} + ALIYUN_ACCESS_KEY_SECRET: ${{ secrets.E2E_ALIYUN_ACCESS_KEY_SECRET }} + ALIYUN_RESOURCE_GROUP_ID: ${{ secrets.E2E_ALIYUN_RESOURCE_GROUP_ID }} + ALIYUN_REGION_ID: ${{ secrets.E2E_ALIYUN_REGION_ID }} run: | set -ex - sudo chmod a+x /tmp/e2e.test + sudo su + chmod a+x /tmp/e2e.test gzip /tmp/sealos/images/patch-${{ matrix.arch }}.tar - sudo export SEALOS_E2E_TEST_IMAGE_NAME="hub.sealos.cn/labring/kubernetes:v1.25.6" \ - SEALOS_E2E_TEST_PATCH_IMAGE_TAR="/tmp/sealos/images/patch-${{ matrix.arch }}.tar.gz" \ - SEALOS_E2E_TEST_PATCH_IMAGE_NAME="ghcr.io/labring/sealos-patch:${{ env.GIT_COMMIT_SHORT_SHA }}-${{ matrix.arch }}" \ - SEALOS_E2E_TEST_SEALOS_BIN_PATH="/tmp/sealos/bin/sealos" \ - ALIYUN_ACCESS_KEY_ID="${{ secrets.E2E_ALIYUN_ACCESS_KEY_ID }}" \ - ALIYUN_ACCESS_KEY_SECRET="${{ secrets.E2E_ALIYUN_ACCESS_KEY_SECRET }}" \ - ALIYUN_RESOURCE_GROUP_ID="${{ secrets.E2E_ALIYUN_RESOURCE_GROUP_ID }}" \ - ALIYUN_REGION_ID="${{ secrets.E2E_ALIYUN_REGION_ID }}" - sudo /tmp/e2e.test --ginkgo.v --ginkgo.focus="E2E_sealos_apply_infra_test" + /tmp/e2e.test --ginkgo.v --ginkgo.focus="E2E_sealos_apply_infra_test" echo 'test_result=success' >> "$GITHUB_OUTPUT" issue_commit: needs: [ e2e_apply_test ] runs-on: ubuntu-latest permissions: issues: write - if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'need-e2e-apply-test') }} #success() || failure() + if: ${{ always() && github.event.label.name == 'need-e2e-apply-test' }} #success() || failure() steps: - name: Add comment to PR with test status uses: peter-evans/create-or-update-comment@v1 diff --git a/pkg/ssh/scp.go b/pkg/ssh/scp.go index 563ea3332..18a1ab706 100644 --- a/pkg/ssh/scp.go +++ b/pkg/ssh/scp.go @@ -183,7 +183,7 @@ func (c *Client) Fetch(host, src, dst string) error { return err } defer created.Close() - _, err = io.Copy(rfp, created) + _, err = io.Copy(created, rfp) return err } diff --git a/test/e2e/suites/apply/apply.go b/test/e2e/suites/apply/apply.go index 8a4a12465..645594c5d 100644 --- a/test/e2e/suites/apply/apply.go +++ b/test/e2e/suites/apply/apply.go @@ -22,6 +22,8 @@ import ( "strings" "time" + "github.com/labring/sealos/test/e2e/suites/operators" + "github.com/labring/sealos/test/e2e/testhelper/utils" "github.com/labring/sealos/pkg/types/v1beta1" @@ -121,6 +123,22 @@ func (a *Applier) initImage() { } err = a.RemoteSealosCmd.ImageLoad(a.Infra.PatchImageTar) utils.CheckErr(err) + images, err := operators.NewFakeImage(a.RemoteSealosCmd).ListImages(false) + utils.CheckErr(err) + logger.Info("images:", images) + patchImageName := "" + for _, image := range images { + for i := range image.Names { + if strings.Contains(image.Names[i], "sealos-patch") { + patchImageName = image.Names[i] + break + } + } + if patchImageName != "" { + a.Infra.PatchImageName = patchImageName + break + } + } } else { err = a.RemoteSealosCmd.ImagePull(&cmd2.PullOptions{ ImageRefs: []string{a.Infra.PatchImageName}, diff --git a/test/e2e/suites/infra/check.go b/test/e2e/suites/infra/check.go index e5d090d12..a6d141d11 100644 --- a/test/e2e/suites/infra/check.go +++ b/test/e2e/suites/infra/check.go @@ -18,6 +18,7 @@ package infra import ( "fmt" + "os" "github.com/labring/sealos/test/e2e/testhelper/utils" @@ -48,9 +49,9 @@ func NewFakeInfra() *FakeInfra { func (f *FakeInfra) PreSetEnv() { f.ImageName = settings.GetEnvWithDefault(settings.TestImageName, settings.DefaultTestImageName) - f.ImageTar = settings.GetEnvWithDefault(settings.TestImageTar, settings.DefaultTestImageTar) - f.PatchImageName = settings.GetEnvWithDefault(settings.TestPatchImageName, settings.DefaultPatchImageName) - f.PatchImageTar = settings.GetEnvWithDefault(settings.TestPatchImageTar, settings.DefaultPatchImageTar) + f.ImageTar = os.Getenv(settings.TestImageTar) + f.PatchImageTar = os.Getenv(settings.TestPatchImageTar) + f.PatchImageName = os.Getenv(settings.TestPatchImageName) f.InfraDriver = settings.GetEnvWithDefault(settings.TestInfra, settings.DefaultInfraDriver) f.TestDir = settings.GetEnvWithDefault(settings.TestDir, settings.DefaultTestDir) f.ClusterName = settings.GetEnvWithDefault(settings.TestClusterName, settings.DefaultTestClusterName) diff --git a/test/e2e/suites/operators/image.go b/test/e2e/suites/operators/image.go index 024073e86..7119cc60f 100644 --- a/test/e2e/suites/operators/image.go +++ b/test/e2e/suites/operators/image.go @@ -31,7 +31,7 @@ type fakeImageClient struct { *cmd.SealosCmd } -func newFakeImage(sealosCmd *cmd.SealosCmd) FakeImageInterface { +func NewFakeImage(sealosCmd *cmd.SealosCmd) FakeImageInterface { return &fakeImageClient{ SealosCmd: sealosCmd, } diff --git a/test/e2e/suites/operators/operators.go b/test/e2e/suites/operators/operators.go index 42e27e6d7..4a018cdc2 100644 --- a/test/e2e/suites/operators/operators.go +++ b/test/e2e/suites/operators/operators.go @@ -36,7 +36,7 @@ func NewFakeClient(clusterName string) *FakeClient { } localCmd := cmd.NewSealosCmd(settings.E2EConfig.SealosBinPath, &cmd.LocalCmd{}) return &FakeClient{ - Image: newFakeImage(localCmd), + Image: NewFakeImage(localCmd), CRI: newCRIClient(localCmd), Cluster: newClusterClient(localCmd, clusterName), Cert: newCertClient(localCmd, clusterName),