You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by zh...@apache.org on 2021/03/21 13:46:42 UTC

[skywalking-infra-e2e] branch refactor/setup created (now a312b68)

This is an automated email from the ASF dual-hosted git repository.

zhangke pushed a change to branch refactor/setup
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git.


      at a312b68  refactor setup part

This branch includes the following new commits:

     new a312b68  refactor setup part

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[skywalking-infra-e2e] 01/01: refactor setup part

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zhangke pushed a commit to branch refactor/setup
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git

commit a312b6859d35c229b21c4b9f3096e1f7b6137796
Author: HumbertZhang <50...@qq.com>
AuthorDate: Sun Mar 21 21:46:22 2021 +0800

    refactor setup part
---
 commands/cleanup/cleanup.go         |  4 +-
 commands/run/run.go                 | 22 +++++++++
 commands/verify/verify.go           |  6 +--
 examples/simple/e2e.yaml            | 44 ++++++++---------
 internal/components/setup/common.go | 17 +++----
 internal/components/setup/kind.go   | 97 ++++++++++++++++++++-----------------
 internal/config/e2eConfig.go        | 20 ++++----
 internal/constant/kind.go           |  2 +
 8 files changed, 120 insertions(+), 92 deletions(-)

diff --git a/commands/cleanup/cleanup.go b/commands/cleanup/cleanup.go
index d5d2024..dd87482 100644
--- a/commands/cleanup/cleanup.go
+++ b/commands/cleanup/cleanup.go
@@ -34,7 +34,7 @@ var Cleanup = &cobra.Command{
 	Use:   "cleanup",
 	Short: "",
 	RunE: func(cmd *cobra.Command, args []string) error {
-		err := cleanupAccordingE2E()
+		err := DoCleanupAccordingE2E()
 		if err != nil {
 			err = fmt.Errorf("[Cleanup] %s", err)
 			return err
@@ -43,7 +43,7 @@ var Cleanup = &cobra.Command{
 	},
 }
 
-func cleanupAccordingE2E() error {
+func DoCleanupAccordingE2E() error {
 	e2eConfig := config.GlobalConfig.E2EConfig
 	if e2eConfig.Setup.Env == constant.Kind {
 		err := cleanup.KindCleanUp(&e2eConfig)
diff --git a/commands/run/run.go b/commands/run/run.go
index 5827d9d..3d451ff 100644
--- a/commands/run/run.go
+++ b/commands/run/run.go
@@ -18,7 +18,10 @@
 package run
 
 import (
+	"github.com/apache/skywalking-infra-e2e/commands/cleanup"
 	"github.com/apache/skywalking-infra-e2e/commands/setup"
+	"github.com/apache/skywalking-infra-e2e/commands/trigger"
+	"github.com/apache/skywalking-infra-e2e/commands/verify"
 	"github.com/apache/skywalking-infra-e2e/internal/config"
 	"github.com/apache/skywalking-infra-e2e/internal/logger"
 
@@ -51,8 +54,27 @@ func runAccordingE2E() error {
 	logger.Log.Infof("setup part finished successfully")
 
 	// trigger part
+	err = trigger.DoActionAccordingE2E()
+	if err != nil {
+		return err
+	}
+	logger.Log.Infof("trigger part finished successfully")
 
 	// verify part
+	err = verify.DoVerifyAccordingConfig()
+	if err != nil {
+		return err
+	}
+	logger.Log.Infof("verify part finished successfully")
+
+	// cleanup part
+	defer func() {
+		err = cleanup.DoCleanupAccordingE2E()
+		if err != nil {
+			logger.Log.Errorf("cleanup part error: %s", err)
+		}
+		logger.Log.Infof("cleanup part finished successfully")
+	}()
 
 	return nil
 }
diff --git a/commands/verify/verify.go b/commands/verify/verify.go
index 0e700b9..290cf26 100644
--- a/commands/verify/verify.go
+++ b/commands/verify/verify.go
@@ -48,7 +48,7 @@ var Verify = &cobra.Command{
 			return verifySingleCase(expected, actual, query)
 		}
 		// If there is no given flags.
-		return verifyAccordingConfig()
+		return DoVerifyAccordingConfig()
 	},
 }
 
@@ -84,8 +84,8 @@ func verifySingleCase(expectedFile, actualFile, query string) error {
 	return nil
 }
 
-// verifyAccordingConfig reads cases from the config file and verifies them.
-func verifyAccordingConfig() error {
+// DoVerifyAccordingConfig reads cases from the config file and verifies them.
+func DoVerifyAccordingConfig() error {
 	if config.GlobalConfig.Error != nil {
 		return config.GlobalConfig.Error
 	}
diff --git a/examples/simple/e2e.yaml b/examples/simple/e2e.yaml
index e486887..b1d571c 100644
--- a/examples/simple/e2e.yaml
+++ b/examples/simple/e2e.yaml
@@ -18,38 +18,36 @@
 setup:
   env: kind
   file: kind.yaml
-  manifests:
-    - path: busybox1.yaml
-      wait: 
-        - namespace: default
-          resource: pod/busybox1 
-          for: condition=Ready
-    - path: manifests,manifests2
+  steps:
+    - type: command
+      command: |
+        if test -d "$TMPDIR"; then
+            :
+        else
+            TMPDIR=/tmp
+        fi
+
+        cp $TMPDIR/e2e-k8s.config ~/.kube/config
+        export ISTIO_VERSION=1.9.1
+        istioctl version || (curl -L https://istio.io/downloadIstio | sh - && sudo mv $PWD/istio-$ISTIO_VERSION/bin/istioctl /usr/local/bin/)
+        istioctl install -y --set profile=demo \
+            --set meshConfig.defaultConfig.envoyMetricsService.address=skywalking-oap.istio-system:11800 \
+            --set values.telemetry.v2.enabled=false
+        kubectl label namespace default istio-injection=enabled
+    - type: manifest
+      path: busybox1.yaml,manifests
       wait:
         - namespace: default
           resource: pod
-          label-selector: app=busybox2
-          for: condition=Ready
-        - namespace: default
-          resource: pod
           for: condition=Ready
-  runs: # commands are serial within one code block and parallel between code blocks
-    - command: | # it can be a shell script or anything executable
-        cp $TMPDIR/e2e-k8s.config ~/.kube/config
+    - type: command
+      command: |
         kubectl create deployment nginx1 --image=nginx
       wait:
         - namespace: default
           resource: deployment/nginx1
           for: condition=Available
-    - command: |
-        cp $TMPDIR/e2e-k8s.config ~/.kube/config
-        kubectl create deployment nginx2 \
-                                  --image=nginx
-      wait:
-        - namespace: default
-          resource: deployment/nginx2
-          for: condition=Available
-  timeout: 600
+  timeout: 1200
 
 trigger:
   action: http
diff --git a/internal/components/setup/common.go b/internal/components/setup/common.go
index cae40c4..bf3aa9b 100644
--- a/internal/components/setup/common.go
+++ b/internal/components/setup/common.go
@@ -29,20 +29,17 @@ import (
 )
 
 // RunCommandsAndWait Concurrently run commands and wait for conditions.
-func RunCommandsAndWait(runs []config.Run, timeout time.Duration) error {
+func RunCommandsAndWait(run config.Run, timeout time.Duration) error {
 	waitSet := util.NewWaitSet(timeout)
 
-	for idx := range runs {
-		run := runs[idx]
-		commands := run.Command
-		if len(commands) < 1 {
-			continue
-		}
-
-		waitSet.WaitGroup.Add(1)
-		go executeCommandsAndWait(commands, run.Waits, waitSet)
+	commands := run.Command
+	if len(commands) < 1 {
+		return nil
 	}
 
+	waitSet.WaitGroup.Add(1)
+	go executeCommandsAndWait(commands, run.Waits, waitSet)
+
 	go func() {
 		waitSet.WaitGroup.Wait()
 		close(waitSet.FinishChan)
diff --git a/internal/components/setup/kind.go b/internal/components/setup/kind.go
index c4c4f27..ea83809 100644
--- a/internal/components/setup/kind.go
+++ b/internal/components/setup/kind.go
@@ -58,10 +58,10 @@ func KindSetup(e2eConfig *config.E2EConfig) error {
 		return fmt.Errorf("no kind config file was provided")
 	}
 
-	manifests := e2eConfig.Setup.Manifests
+	manifests := e2eConfig.Setup.Steps
 	// if no manifests was provided, then no need to create the cluster.
 	if manifests == nil {
-		logger.Log.Info("no manifests is provided")
+		logger.Log.Info("no steps is provided")
 		return nil
 	}
 
@@ -75,6 +75,7 @@ func KindSetup(e2eConfig *config.E2EConfig) error {
 		return err
 	}
 
+	// run commands and manifests
 	timeout := e2eConfig.Setup.Timeout
 	var waitTimeout time.Duration
 	if timeout <= 0 {
@@ -82,28 +83,37 @@ func KindSetup(e2eConfig *config.E2EConfig) error {
 	} else {
 		waitTimeout = time.Duration(timeout) * time.Second
 	}
-
 	logger.Log.Debugf("wait timeout is %d seconds", int(waitTimeout.Seconds()))
 
 	// record time now
 	timeNow := time.Now()
 
-	err = createManifestsAndWait(c, dc, manifests, waitTimeout)
-	if err != nil {
-		return err
-	}
+	for _, step := range e2eConfig.Setup.Steps {
+		if step.Type == constant.StepTypeManifest {
+			manifest := config.Manifest{
+				Path:  step.Path,
+				Waits: step.Waits,
+			}
+			err = createManifestAndWait(c, dc, manifest, waitTimeout)
+			if err != nil {
+				return err
+			}
+		} else if step.Type == constant.StepTypeCommand {
+			command := config.Run{
+				Command: step.Command,
+				Waits:   step.Waits,
+			}
 
-	// calculates new timeout. manifests and run of setup uses the same countdown.
-	runWaitTimeout := NewTimeout(timeNow, waitTimeout)
-	if runWaitTimeout <= 0 {
-		return fmt.Errorf("kind setup timeout")
-	}
+			err := RunCommandsAndWait(command, waitTimeout)
+			if err != nil {
+				return err
+			}
+		}
+		waitTimeout = NewTimeout(timeNow, waitTimeout)
+		timeNow = time.Now()
 
-	if len(e2eConfig.Setup.Runs) > 0 {
-		logger.Log.Debugf("executing commands...")
-		err := RunCommandsAndWait(e2eConfig.Setup.Runs, runWaitTimeout)
-		if err != nil {
-			return err
+		if waitTimeout <= 0 {
+			return fmt.Errorf("kind setup timeout")
 		}
 	}
 	return nil
@@ -123,8 +133,8 @@ func createKindCluster(kindConfigPath string) error {
 	return nil
 }
 
-// createManifestsAndWait creates manifests in k8s cluster and concurrent waits according to the manifests' wait conditions.
-func createManifestsAndWait(c *kubernetes.Clientset, dc dynamic.Interface, manifests []config.Manifest, timeout time.Duration) error {
+// createManifestAndWait creates manifests in k8s cluster and concurrent waits according to the manifests' wait conditions.
+func createManifestAndWait(c *kubernetes.Clientset, dc dynamic.Interface, manifest config.Manifest, timeout time.Duration) error {
 	waitSet := util.NewWaitSet(timeout)
 
 	kubeConfigYaml, err := ioutil.ReadFile(kubeConfigPath)
@@ -132,32 +142,29 @@ func createManifestsAndWait(c *kubernetes.Clientset, dc dynamic.Interface, manif
 		return err
 	}
 
-	for idx := range manifests {
-		manifest := manifests[idx]
-		waits := manifest.Waits
-		err := createByManifest(c, dc, manifest)
-		if err != nil {
-			return err
-		}
-
-		// len() for nil slices is defined as zero
-		if len(waits) == 0 {
-			logger.Log.Info("no wait-for strategy is provided")
-			continue
-		}
+	waits := manifest.Waits
+	err = createByManifest(c, dc, manifest)
+	if err != nil {
+		return err
+	}
 
-		for idx := range waits {
-			wait := waits[idx]
-			logger.Log.Infof("waiting for %+v", wait)
+	// len() for nil slices is defined as zero
+	if len(waits) == 0 {
+		logger.Log.Info("no wait-for strategy is provided")
+		return nil
+	}
 
-			options, err := getWaitOptions(kubeConfigYaml, &wait)
-			if err != nil {
-				return err
-			}
+	for idx := range waits {
+		wait := waits[idx]
+		logger.Log.Infof("waiting for %+v", wait)
 
-			waitSet.WaitGroup.Add(1)
-			go concurrentlyWait(&wait, options, waitSet)
+		options, err := getWaitOptions(kubeConfigYaml, &wait)
+		if err != nil {
+			return err
 		}
+
+		waitSet.WaitGroup.Add(1)
+		go concurrentlyWait(&wait, options, waitSet)
 	}
 
 	go func() {
@@ -167,12 +174,12 @@ func createManifestsAndWait(c *kubernetes.Clientset, dc dynamic.Interface, manif
 
 	select {
 	case <-waitSet.FinishChan:
-		logger.Log.Infof("create and wait for manifests ready success")
+		logger.Log.Infof("create and wait for manifest ready success")
 	case err := <-waitSet.ErrChan:
-		logger.Log.Errorf("failed to wait for manifests to be ready")
+		logger.Log.Errorf("failed to wait for manifest to be ready")
 		return err
 	case <-time.After(waitSet.Timeout):
-		return fmt.Errorf("wait for manifests ready timeout after %d seconds", int(timeout.Seconds()))
+		return fmt.Errorf("wait for manifest ready timeout after %d seconds", int(timeout.Seconds()))
 	}
 
 	return nil
@@ -214,7 +221,7 @@ func getWaitOptions(kubeConfigYaml []byte, wait *config.Wait) (options *ctlwait.
 }
 
 func createByManifest(c *kubernetes.Clientset, dc dynamic.Interface, manifest config.Manifest) error {
-	files, err := util.GetManifests(manifest.GetPath())
+	files, err := util.GetManifests(manifest.Path)
 	if err != nil {
 		logger.Log.Error("get manifests failed")
 		return err
diff --git a/internal/config/e2eConfig.go b/internal/config/e2eConfig.go
index af90953..24834d8 100644
--- a/internal/config/e2eConfig.go
+++ b/internal/config/e2eConfig.go
@@ -28,11 +28,17 @@ type E2EConfig struct {
 }
 
 type Setup struct {
-	Env       string     `yaml:"env"`
-	File      string     `yaml:"file"`
-	Manifests []Manifest `yaml:"manifests"`
-	Runs      []Run      `yaml:"runs"`
-	Timeout   int        `yaml:"timeout"`
+	Env     string `yaml:"env"`
+	File    string `yaml:"file"`
+	Steps   []Step `yaml:"steps"`
+	Timeout int    `yaml:"timeout"`
+}
+
+type Step struct {
+	Type    string `yaml:"type"`
+	Path    string `yaml:"path"`
+	Command string `yaml:"command"`
+	Waits   []Wait `yaml:"wait"`
 }
 
 func (s *Setup) GetFile() string {
@@ -44,10 +50,6 @@ type Manifest struct {
 	Waits []Wait `yaml:"wait"`
 }
 
-func (m Manifest) GetPath() string {
-	return m.Path
-}
-
 type Run struct {
 	Command string `yaml:"command"`
 	Waits   []Wait `yaml:"wait"`
diff --git a/internal/constant/kind.go b/internal/constant/kind.go
index b6bb7cb..5a0df96 100644
--- a/internal/constant/kind.go
+++ b/internal/constant/kind.go
@@ -32,6 +32,8 @@ const (
 	K8sClusterConfigFileName = "e2e-k8s.config"
 	DefaultWaitTimeout       = 600 * time.Second
 	SingleDefaultWaitTimeout = 30 * 60 * time.Second
+	StepTypeManifest         = "manifest"
+	StepTypeCommand          = "command"
 )
 
 var (