diff --git a/.github/workflows/e2e_test_apply.yml b/.github/workflows/e2e_test_apply.yml index 1f3aab14b33..5e03b8318a0 100644 --- a/.github/workflows/e2e_test_apply.yml +++ b/.github/workflows/e2e_test_apply.yml @@ -47,14 +47,15 @@ jobs: set -ex sudo chmod a+x /tmp/e2e.test gzip /tmp/sealos/images/patch-${{ matrix.arch }}.tar - sudo SEALOS_E2E_TEST_IMAGE_NAME="hub.sealos.cn/labring/kubernetes:v1.25.6" \ + 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 }}" /tmp/e2e.test --ginkgo.v --ginkgo.focus="E2E_sealos_apply_test" + ALIYUN_REGION_ID="${{ secrets.E2E_ALIYUN_REGION_ID }}" + sudo /tmp/e2e.test --ginkgo.v --ginkgo.focus="E2E_sealos_apply_infra_test" echo 'test_result=success' >> "$GITHUB_OUTPUT" issue_commit: needs: [ e2e_apply_test ] diff --git a/.github/workflows/e2e_test_core.yml b/.github/workflows/e2e_test_core.yml index 9636d8acec7..a13b16041d7 100644 --- a/.github/workflows/e2e_test_core.yml +++ b/.github/workflows/e2e_test_core.yml @@ -30,7 +30,7 @@ jobs: strategy: fail-fast: false matrix: - unit: [ 'E2E_sealos_images_test','E2E_sealos_cert_test','E2E_sealos_run_test','E2E_sealos_inspect_test' ] + unit: [ 'E2E_sealos_images_test','E2E_sealos_cert_test','E2E_sealos_run_test','E2E_sealos_inspect_test','E2E_sealos_apply_test' ] runs-on: ubuntu-latest steps: - name: Download sealos diff --git a/.github/workflows/test_run.yml b/.github/workflows/test_run.yml deleted file mode 100644 index 99a5401fde9..00000000000 --- a/.github/workflows/test_run.yml +++ /dev/null @@ -1,911 +0,0 @@ -name: Test Sealos Run Command - -on: - workflow_dispatch: - push: - branches: ["main"] - paths: - - ".github/workflows/**" - - "cmd/**" - - "pkg/**" - pull_request: - branches: ["*"] - paths: - - ".github/workflows/**" - - "cmd/**" - - "pkg/**" - -jobs: - call_ci_workflow: - uses: ./.github/workflows/import-patch-image.yml - with: - arch: amd64 - download-sealos: - needs: [call_ci_workflow] - runs-on: ubuntu-latest - steps: - - name: Download sealos binary - uses: actions/download-artifact@v3 - with: - name: sealos-amd64 - path: /tmp/sealos/bin/ - - - name: Download patch image tar - uses: actions/download-artifact@v3 - with: - name: patch-image-amd64.tar - path: /tmp/sealos/images/ - - - name: Save Binaries - uses: actions/upload-artifact@v3 - with: - name: sealos - path: /tmp/sealos/bin/sealos - - name: Save Tars - uses: actions/upload-artifact@v3 - with: - name: patch-amd64.tar - path: /tmp/sealos/images/patch-amd64.tar - verify-run-single: - needs: [download-sealos] - runs-on: ubuntu-latest - steps: - - name: Download sealos - uses: actions/download-artifact@v3 - with: - name: sealos - path: /tmp/ - - name: Verify sealos - run: | - sudo chmod a+x /tmp/sealos - sudo mv /tmp/sealos /usr/bin/ - sudo sealos version - - name: Remove containerd && docker - uses: labring/sealos-action@v0.0.7 - with: - type: prune - - name: Auto install k8s using sealos - run: | - sudo sealos run labring/kubernetes:v1.25.0 --single --debug - mkdir -p "$HOME/.kube" - sudo cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config" - sudo chown "$(whoami)" "$HOME/.kube/config" - kubectl get svc - kubectl get pod -A - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml - sudo cat /root/.sealos/default/Clusterfile - - name: Verify Single Node Cluster Status - run: | - echo "Verify Cluster" - echo "Current system info" - sudo /var/lib/sealos/data/default/rootfs/opt/sealctl cri socket - sudo /var/lib/sealos/data/default/rootfs/opt/sealctl cri cgroup-driver --short - echo "Check Single Node Taints" - taints=$(kubectl get nodes -o json | jq ".items[].spec.taints") - echo "$taints" - if echo "$taints" | grep -q "control-plane"; then - printf "should not have control-plane Taint\n" && false - fi - echo "Current Cluster info" - set -e - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep /run/containerd/containerd.sock - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep systemd - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep 100.64.0.0/10 - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep 10.96.0.0/22 - - verify-run-containerd: - needs: [download-sealos] - runs-on: ubuntu-latest - steps: - - name: Download sealos - uses: actions/download-artifact@v3 - with: - name: sealos - path: /tmp/ - - name: Verify sealos - run: | - sudo chmod a+x /tmp/sealos - sudo mv /tmp/sealos /usr/bin/ - sudo sealos version - - name: Remove containerd && docker - uses: labring/sealos-action@v0.0.7 - with: - type: prune - - name: Auto install k8s using sealos - run: | - sudo sealos run labring/kubernetes:v1.25.0 --single --debug - mkdir -p "$HOME/.kube" - sudo cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config" - sudo chown "$(whoami)" "$HOME/.kube/config" - kubectl get svc - kubectl get pod -A - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml - sudo cat /root/.sealos/default/Clusterfile - - name: Verify Cluster Status - run: | - echo "Verify Cluster" - echo "Current system info" - sudo /var/lib/sealos/data/default/rootfs/opt/sealctl cri socket - sudo /var/lib/sealos/data/default/rootfs/opt/sealctl cri cgroup-driver --short - echo "Current Cluster info" - set -e - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep /run/containerd/containerd.sock - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep systemd - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep 100.64.0.0/10 - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep 10.96.0.0/22 - - verify-run-docker: - needs: [download-sealos] - runs-on: ubuntu-latest - steps: - - name: Download sealos - uses: actions/download-artifact@v3 - with: - name: sealos - path: /tmp/ - - name: Verify sealos - run: | - sudo chmod a+x /tmp/sealos - sudo mv /tmp/sealos /usr/bin/ - sudo sealos version - - name: Remove containerd && docker - uses: labring/sealos-action@v0.0.7 - with: - type: prune - - - name: Auto install k8s using sealos - run: | - sudo sealos run labring/kubernetes-docker:v1.25.0 --single --debug - mkdir -p "$HOME/.kube" - sudo cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config" - sudo chown "$(whoami)" "$HOME/.kube/config" - kubectl get svc - kubectl get pod -A - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml - sudo cat /root/.sealos/default/Clusterfile - - name: Verify Cluster Status - run: | - echo "Verify Cluster" - echo "Current system info" - sudo /var/lib/sealos/data/default/rootfs/opt/sealctl cri socket - sudo /var/lib/sealos/data/default/rootfs/opt/sealctl cri cgroup-driver --short - echo "Current Cluster info" - set -e - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep /var/run/cri-dockerd.sock - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep systemd - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep 100.64.0.0/10 - sudo cat /root/.sealos/default/etc/kubeadm-init.yaml | grep 10.96.0.0/22 - - - verify-run-containerd-buildimage: - needs: [download-sealos] - runs-on: ubuntu-latest - steps: - - name: Download sealos - uses: actions/download-artifact@v3 - with: - name: sealos - path: /tmp/ - - name: Verify sealos - run: | - sudo chmod a+x /tmp/sealos - sudo mv /tmp/sealos /usr/bin/ - sudo sealos version - - name: Remove containerd && docker - uses: labring/sealos-action@v0.0.7 - with: - type: prune - - name: Build new image - run: | - mkdir -p /tmp/buildimage - cat > /tmp/buildimage/kubeadm.yml < /tmp/buildimage/Kubefile < /tmp/buildimage/kubeadm.yml < /tmp/buildimage/Kubefile < /tmp/apply/Clusterfile < /tmp/apply/Clusterfile < output.file 2>&1 & - - name: Generator clusterfile - run: | - local_ip=`ip addr | grep inet | grep -Ev 'inet6|docker|host|br-' | awk '{print $2}' | awk -F '/' '{print $1}'` - echo "local ip is : ${local_ip}" - - mkdir -p /tmp/apply - cat > /tmp/apply/Clusterfile < /tmp/buildimage/kubeadm.yml < /tmp/buildimage/Kubefile < /tmp/apply/Clusterfile < /tmp/buildimage/kubeadm.yml < /tmp/buildimage/Kubefile < /tmp/apply/Clusterfile < /tmp/apply/Clusterfile < output.file 2>&1 & +` + +func (e *Etcd) Install() error { + err := os.WriteFile("/tmp/install_etcd.sh", []byte(installScript), 0755) + if err != nil { + return err + } + return e.AsyncExec("bash", "-c", "/tmp/install_etcd.sh") +} diff --git a/test/e2e/testhelper/settings/common.go b/test/e2e/testhelper/settings/common.go index 0cba2707b04..faaa1b3b359 100644 --- a/test/e2e/testhelper/settings/common.go +++ b/test/e2e/testhelper/settings/common.go @@ -39,14 +39,17 @@ const ( const GzSuffix = ".gz" const ( - DefaultTestImageName = "hub.sealos.cn/labring/kubernetes:v1.25.0" - HelmImageName = "hub.sealos.cn/labring/helm:v3.8.2" - CalicoImageName = "hub.sealos.cn/labring/calico:v3.25.0" - DefaultImageRepo = "hub.sealos.cn/labring" - DockerIoRepo = "docker.io" - DefaultInfraDriver = AliyunInfraDriver - AliyunInfraDriver = "aliyun" - AWSInfraDriver = "aws" + DefaultTestImageName = "hub.sealos.cn/labring/kubernetes:v1.25.0" + DefaultTestImageTar = "/tmp/kubernetes-v1.25.0.tar.gz" + DefaultPatchImageName = "hub.sealos.cn/labring/kubernetes:v1.25.0-patch" + DefaultPatchImageTar = "/tmp/kubernetes-v1.25.0-patch.tar.gz" + HelmImageName = "hub.sealos.cn/labring/helm:v3.8.2" + CalicoImageName = "hub.sealos.cn/labring/calico:v3.25.0" + DefaultImageRepo = "hub.sealos.cn/labring" + DockerIoRepo = "docker.io" + DefaultInfraDriver = AliyunInfraDriver + AliyunInfraDriver = "aliyun" + AWSInfraDriver = "aws" ) func GetWorkDir() string { diff --git a/test/e2e/testhelper/settings/env.go b/test/e2e/testhelper/settings/env.go index dc20fb73c4a..38fcf8ae031 100644 --- a/test/e2e/testhelper/settings/env.go +++ b/test/e2e/testhelper/settings/env.go @@ -22,9 +22,9 @@ const ( TestSealosBinPath = Prefix + "SEALOS_BIN_PATH" ) -func getEnvWithDefault(key, defaultValue string) string { - value := os.Getenv(key) - if value == "" { +func GetEnvWithDefault(key, defaultValue string) string { + value, ok := os.LookupEnv(key) + if !ok || value == "" { return defaultValue } return value diff --git a/test/e2e/testhelper/settings/settings.go b/test/e2e/testhelper/settings/settings.go index 7d2e581bd87..6efb16fc90f 100644 --- a/test/e2e/testhelper/settings/settings.go +++ b/test/e2e/testhelper/settings/settings.go @@ -15,34 +15,13 @@ package settings import ( - "os" "time" - - "github.com/labring/sealos/test/e2e/testhelper/cmd" - - "github.com/labring/sealos/pkg/types/v1beta1" ) type Config struct { WaitTime time.Duration MaxWaiteTime time.Duration - SSH *v1beta1.SSH - InfraDriver string SealosBinPath string - SealosCmd *cmd.SealosCmd - TestDir string - /* - if baseImageName ond baseImageTar both not set, use default ImageName (hub.sealos.cn/labring/kubernetes:v1.25.6) . - if ImageTar is set, will use tar to load image; else if baseImageName is set, will pull image with baseImageName. - if patchImageTar is set, will use tar to load patch image; else if patchImageName is set, will pull image with patchImageName. - if patchImageTar and patchImageName are both set, will use patchImageTar to load image. - if patchImageTar or patchImageName is set, merge patch image with base image. - */ - ClusterName string - ImageName string - ImageTar string - PatchImageName string - PatchImageTar string } var E2EConfig *Config @@ -50,28 +29,9 @@ var E2EConfig *Config // init test params and settings func init() { E2EConfig = &Config{} - E2EConfig.loadFromEnv() - defaultWaiteTime := os.Getenv(DefaultWaiteTime) - if defaultWaiteTime == "" { - E2EConfig.WaitTime = 300 * time.Second - } else { - E2EConfig.WaitTime, _ = time.ParseDuration(defaultWaiteTime) - } - maxWaiteTime := os.Getenv(MaxWaiteTime) - if maxWaiteTime == "" { - E2EConfig.MaxWaiteTime = 2400 * time.Second - } else { - E2EConfig.MaxWaiteTime, _ = time.ParseDuration(maxWaiteTime) - } -} - -func (c *Config) loadFromEnv() { - c.ImageName = os.Getenv(TestImageName) - c.ImageTar = os.Getenv(TestImageTar) - c.ClusterName = getEnvWithDefault(TestClusterName, DefaultTestClusterName) - c.TestDir = getEnvWithDefault(TestDir, DefaultTestDir) - c.PatchImageName = os.Getenv(TestPatchImageName) - c.PatchImageTar = os.Getenv(TestPatchImageTar) - c.InfraDriver = getEnvWithDefault(TestInfra, DefaultInfraDriver) - c.SealosBinPath = getEnvWithDefault(TestSealosBinPath, DefaultSealosBinPath) + defaultWaiteTime := GetEnvWithDefault(DefaultWaiteTime, "300s") + E2EConfig.WaitTime, _ = time.ParseDuration(defaultWaiteTime) + maxWaiteTime := GetEnvWithDefault(MaxWaiteTime, "2400s") + E2EConfig.MaxWaiteTime, _ = time.ParseDuration(maxWaiteTime) + E2EConfig.SealosBinPath = GetEnvWithDefault(TestSealosBinPath, DefaultSealosBinPath) } diff --git a/test/e2e/testhelper/utils.go b/test/e2e/testhelper/utils.go index d325bf70901..5b21e36714d 100644 --- a/test/e2e/testhelper/utils.go +++ b/test/e2e/testhelper/utils.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "io" + "net" "os" exec2 "os/exec" "path/filepath" @@ -139,7 +140,7 @@ func DeleteFileLocally(filePath string) { func CheckEnvSetting(keys []string) { for _, key := range keys { - if os.Getenv(key) == "" { + if val, ok := os.LookupEnv(key); !ok || val == "" { CheckErr(fmt.Errorf("env %s not set", key)) } } @@ -230,3 +231,49 @@ func GetAllSubDirs(rootPath string) ([]string, error) { }) return dirs, err } + +func ListLocalHostAddrs() (*[]net.Addr, error) { + netInterfaces, err := net.Interfaces() + if err != nil { + logger.Warn("net.Interfaces failed, err:", err.Error()) + return nil, err + } + var allAddrs []net.Addr + for i := 0; i < len(netInterfaces); i++ { + if (netInterfaces[i].Flags & net.FlagUp) == 0 { + continue + } + addrs, err := netInterfaces[i].Addrs() + if err != nil { + logger.Warn("failed to get Addrs, %s", err.Error()) + } + for j := 0; j < len(addrs); j++ { + allAddrs = append(allAddrs, addrs[j]) + } + } + return &allAddrs, nil +} + +func LocalIP(addrs *[]net.Addr) string { + for _, address := range *addrs { + if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil { + return ipnet.IP.String() + } + } + return "" +} + +func GetLocalIpv4() string { + addr, _ := ListLocalHostAddrs() + Ipv4 := LocalIP(addr) + return Ipv4 +} + +// MkTmpdir creates a temporary directory. +func MkTmpdir(dir string) (string, error) { + tempDir, err := os.MkdirTemp(dir, "DTmp-") + if err != nil { + return "", err + } + return tempDir, os.MkdirAll(tempDir, 0755) +}