Skip to content

Commit

Permalink
feature:add sealer e2e workflow using PR comment (#245)
Browse files Browse the repository at this point in the history
* add e2e work flow

add test base file
  • Loading branch information
kakaZhou719 authored and wb-zl958011 committed Jun 3, 2021
1 parent a871284 commit 5d2d075
Show file tree
Hide file tree
Showing 27 changed files with 376 additions and 75 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/auto-invite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ jobs:
permissions:
issues: write
steps:
- name: Dump event context
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
run: |
env

- name: Invite user to join our group
uses: peter-evans/create-or-update-comment@v1
Expand Down
41 changes: 25 additions & 16 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
name: Sealer-Test

on:
pull_request:
types: [ labeled ]
branches:
- main
paths-ignore:
- 'docs/**'
- 'vendor/**'

issue_comment:
types:
- created
jobs:
build:
name: Test
name: test
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }} && contains(github.event.comment.body, '/test')
env:
GO111MODULE: on
steps:
Expand All @@ -21,7 +17,6 @@ jobs:
with:
go-version: 1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
Expand All @@ -37,23 +32,23 @@ jobs:
go get github.com/onsi/ginkgo/ginkgo
go get github.com/onsi/gomega/...
GOPATH=`go env GOPATH`
export GOPATHBIN=$GOPATH/bin
echo "$GOPATHBIN" >> $GITHUB_PATH
echo "$GOPATH/bin" >> $GITHUB_PATH
working-directory: src/github.com/alibaba/sealer

- name: Run e2e test
- name: Run all e2e test
shell: bash
working-directory: src/github.com/alibaba/sealer
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
ACCESSKEYID: ${{ secrets.ACCESSKEYID }}
ACCESSKEYSECRET: ${{ secrets.ACCESSKEYSECRET }}
RegionID: ${{ secrets.RegionID }}
if: ${{ github.event.label.name == 'e2e-test' }}
if: ${{ github.event.comment.body == '/test all' }}
run: |
ginkgo -v test
working-directory: src/github.com/alibaba/sealer

- name: Run apply test
shell: bash
working-directory: src/github.com/alibaba/sealer
Expand All @@ -64,6 +59,20 @@ jobs:
ACCESSKEYID: ${{ secrets.ACCESSKEYID }}
ACCESSKEYSECRET: ${{ secrets.ACCESSKEYSECRET }}
RegionID: ${{ secrets.RegionID }}
if: ${{ github.event.label.name == 'apply-test' }}
if: ${{ github.event.comment.body == '/test apply' }}
run: |
ginkgo -v --focus="sealer apply" test
- name: Run build test
shell: bash
working-directory: src/github.com/alibaba/sealer
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
ACCESSKEYID: ${{ secrets.ACCESSKEYID }}
ACCESSKEYSECRET: ${{ secrets.ACCESSKEYSECRET }}
RegionID: ${{ secrets.RegionID }}
if: ${{ github.event.comment.body == '/test build' }}
run: |
ginkgo -v --focus="sealer build" test
1 change: 1 addition & 0 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
output, err := exec.LookPath("sealer")
Expect(err).NotTo(HaveOccurred(), output)
SetDefaultEventuallyTimeout(settings.DefaultWaiteTime)
settings.DefaultSealerBin = output
return nil
}, func(data []byte) {
SetDefaultEventuallyTimeout(settings.DefaultWaiteTime)
Expand Down
4 changes: 2 additions & 2 deletions test/sealer_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package test

import (
/*import (
"fmt"
"github.com/alibaba/sealer/test/suites/apply"
Expand Down Expand Up @@ -48,4 +48,4 @@ var _ = Describe("sealer apply", func() {
})
})
})*/
4 changes: 2 additions & 2 deletions test/sealer_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package test

import (
/*import (
"fmt"
"os"
Expand Down Expand Up @@ -78,4 +78,4 @@ var _ = Describe("sealer build", func() {
})
})
})
})*/
4 changes: 2 additions & 2 deletions test/sealer_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package test

import (
/*import (
"fmt"
"github.com/alibaba/sealer/test/suites/registry"
Expand All @@ -40,4 +40,4 @@ var _ = Describe("sealer login", func() {
Eventually(sess).Should(Exit(0))
})
})
})
})*/
55 changes: 41 additions & 14 deletions test/suites/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
"fmt"
"path/filepath"

"github.com/alibaba/sealer/logger"
"github.com/alibaba/sealer/test/testhelper"
"github.com/alibaba/sealer/test/testhelper/settings"

"github.com/onsi/gomega"

"github.com/alibaba/sealer/test/testhelper"
v1 "github.com/alibaba/sealer/types/api/v1"
"github.com/alibaba/sealer/utils"
)
Expand All @@ -30,21 +32,46 @@ func getFixtures() string {
return filepath.Join(pwd, "suites", "apply", "fixtures")
}

func GetClusterFilePathOfRootfs() string {
func GetRawClusterFilePath() string {
fixtures := getFixtures()
return filepath.Join(fixtures, "cluster_file_rootfs.yaml")
return filepath.Join(fixtures, "cluster_file_for_test.yaml")
}

func GetClusterFileData(clusterFile string) *v1.Cluster {
cluster := &v1.Cluster{}
if err := utils.UnmarshalYamlFile(clusterFile, cluster); err != nil {
logger.Error("failed to unmarshal yamlFile to get clusterFile data")
return nil
}
return cluster
func DeleteCluster(clusterFile string) {
cmd := fmt.Sprintf("%s delete -f %s", settings.DefaultSealerBin, clusterFile)
testhelper.RunCmdAndCheckResult(cmd, 0)
}

func DeleteCluster(clusterName string) {
cmd := "sealer delete -f " + fmt.Sprintf(settings.DefaultClusterFileNeedToBeCleaned, clusterName)
testhelper.RunCmdAndCheckResult(cmd, 0)
func WriteClusterFileToDisk(cluster *v1.Cluster, clusterFilePath string) {
gomega.Expect(cluster).NotTo(gomega.BeNil())
err := utils.MarshalYamlToFile(clusterFilePath, cluster)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func LoadClusterFileFromDisk(clusterFilePath string) *v1.Cluster {
var cluster v1.Cluster
err := utils.UnmarshalYamlFile(clusterFilePath, &cluster)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(cluster).NotTo(gomega.BeNil())
return &cluster
}

func GetClusterNodes() int {
client, err := testhelper.NewClientSet()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
nodes, err := testhelper.ListNodes(client)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(nodes.Items)
}

func CheckClusterPods() int {
client, err := testhelper.NewClientSet()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
pods, err := testhelper.ListNodes(client)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return len(pods.Items)
}

func SealerApplyCmd(clusterFile string) string {
return fmt.Sprintf("%s apply -f %s", settings.DefaultSealerBin, clusterFile)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ kind: Cluster
metadata:
name: my-test-cluster
spec:
image: seadent/rootfs:latest
image: sealer-io/kubernetes:v1.19.9
provider: ALI_CLOUD
ssh:
passwd: Seadent123
passwd: Sealer123
pk: xxx
pkPasswd: xxx
user: root
Expand All @@ -37,14 +37,14 @@ spec:
masters:
cpu: 4
memory: 4
count: 3
count: 1
systemDisk: 100
dataDisks:
- 100
nodes:
cpu: 4
memory: 4
count: 3
count: 1
systemDisk: 100
dataDisks:
- 100
95 changes: 86 additions & 9 deletions test/suites/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,99 @@
package build

import (
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/alibaba/sealer/test/testhelper"
"github.com/alibaba/sealer/test/testhelper/settings"
"github.com/alibaba/sealer/utils"
"github.com/onsi/gomega"
)

func getFixtures() string {
pwd := testhelper.GetPwd()
return filepath.Join(pwd, "suites", "build", "fixtures")
func GetFixtures() string {
return filepath.Join(testhelper.GetPwd(), "suites", "build", "fixtures")
}

func GetOnlyCopyDir() string {
fixtures := getFixtures()
return filepath.Join(fixtures, "only_copy")
func GetLocalBuildDir() string {
return "local_build"
}

func GetBuildTestDir() string {
fixtures := getFixtures()
return filepath.Join(fixtures, "build_test")
func GetCloudBuildDir() string {
return "cloud_build"
}

func GetTestKubeKile() string {
// only copy
return ""
}

func GetTestContext() string {
return ""
}
func GetTestBuildType() string {
return ""
}

func GetTestImageName() string {
return fmt.Sprintf("sealer-io/%s%d:%s", settings.ImageName, 719, "v1")
}

func GetTestClusterFilePath() string {
return ""
}

type ArgsOfBuild struct {
KubeFile, ImageName, Context, BuildType string
}

func (a *ArgsOfBuild) SetKubeFile(kubeFile string) *ArgsOfBuild {
a.KubeFile = kubeFile
return a
}

func (a *ArgsOfBuild) SetImageName(imageName string) *ArgsOfBuild {
a.ImageName = imageName
return a
}

func (a *ArgsOfBuild) SetContext(context string) *ArgsOfBuild {
a.Context = context
return a
}

func (a *ArgsOfBuild) SetBuildType(buildType string) *ArgsOfBuild {
a.BuildType = buildType
return a
}

func (a *ArgsOfBuild) ToString() string {
return fmt.Sprintf("%s build -f %s -t %s -c %s -b %s", settings.DefaultSealerBin, a.KubeFile, a.ImageName, a.Context, a.BuildType)
}

func NewArgsOfBuild() *ArgsOfBuild {
return &ArgsOfBuild{}
}

func CheckIsImageExist(imageName string) bool {
cmd := fmt.Sprintf("%s images | grep %s | wc -l", settings.DefaultSealerBin, imageName)
result, err := utils.RunSimpleCmd(cmd)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
num, err := strconv.Atoi(strings.Replace(result, "\n", "", -1))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return num == 1
}

func CheckClusterFile(imageName string) bool {
cmd := fmt.Sprintf("%s images | grep %s | awk '{print $4}'", settings.DefaultSealerBin, imageName)
result, err := utils.RunSimpleCmd(cmd)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
cmd = fmt.Sprintf("%s inspect -c %s | grep Cluster | wc -l", settings.DefaultSealerBin,
strings.Replace(result, "\n", "", -1))
result, err = utils.RunSimpleCmd(cmd)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
num, err := strconv.Atoi(strings.Replace(result, "\n", "", -1))
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return num == 1
}
36 changes: 36 additions & 0 deletions test/suites/build/fixtures/cloud_build/Clusterfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: zlink.aliyun.com/v1alpha1
kind: Cluster
metadata:
name: my-test-cluster
spec:
image: sealer-io/kubernetes:v1.19.9
provider: ALI_CLOUD
ssh:
passwd: Sealer123
pk: xxx
pkPasswd: xxx
user: root
network:
interface: eth0
cniName: calico
podCIDR: 100.64.0.0/10
svcCIDR: 10.96.0.0/22
withoutCNI: false
certSANS:
- aliyun-inc.com
- 10.0.0.2

masters:
cpu: 4
memory: 4
count: 1
systemDisk: 100
dataDisks:
- 100
nodes:
cpu: 4
memory: 4
count: 1
systemDisk: 100
dataDisks:
- 100
Loading

0 comments on commit 5d2d075

Please sign in to comment.