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/27 08:59:52 UTC
[skywalking-infra-e2e] 01/01: add on field in cleanup
This is an automated email from the ASF dual-hosted git repository.
zhangke pushed a commit to branch cleanup
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git
commit 93f19b94f7f352d385edd52ea42123c7ba7e2f61
Author: HumbertZhang <50...@qq.com>
AuthorDate: Sat Mar 27 16:58:07 2021 +0800
add on field in cleanup
---
commands/cleanup/cleanup.go | 1 +
commands/run/run.go | 23 +++++++++++++++++++++++
examples/simple/e2e.yaml | 11 +++++------
internal/components/setup/kind.go | 6 +++---
internal/config/e2eConfig.go | 5 +++++
internal/constant/cleanup.go | 26 ++++++++++++++++++++++++++
6 files changed, 63 insertions(+), 9 deletions(-)
diff --git a/commands/cleanup/cleanup.go b/commands/cleanup/cleanup.go
index dd87482..7e48757 100644
--- a/commands/cleanup/cleanup.go
+++ b/commands/cleanup/cleanup.go
@@ -45,6 +45,7 @@ var Cleanup = &cobra.Command{
func DoCleanupAccordingE2E() error {
e2eConfig := config.GlobalConfig.E2EConfig
+
if e2eConfig.Setup.Env == constant.Kind {
err := cleanup.KindCleanUp(&e2eConfig)
if err != nil {
diff --git a/commands/run/run.go b/commands/run/run.go
index 2a32006..b35da3e 100644
--- a/commands/run/run.go
+++ b/commands/run/run.go
@@ -23,6 +23,7 @@ import (
"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/constant"
"github.com/apache/skywalking-infra-e2e/internal/logger"
"github.com/spf13/cobra"
@@ -55,6 +56,28 @@ func runAccordingE2E() error {
// cleanup part
defer func() {
+ clean := true
+
+ switch config.GlobalConfig.E2EConfig.Cleanup.On {
+ case constant.CleanUpNever:
+ clean = false
+ case constant.CleanUpOnSuccess:
+ // failed
+ if err != nil {
+ clean = false
+ }
+ case constant.CleanUpOnFailure:
+ // success
+ if err == nil {
+ clean = false
+ }
+ }
+
+ if !clean {
+ logger.Log.Infof("cleanup passed according to config")
+ return
+ }
+
err = cleanup.DoCleanupAccordingE2E()
if err != nil {
logger.Log.Errorf("cleanup part error: %s", err)
diff --git a/examples/simple/e2e.yaml b/examples/simple/e2e.yaml
index f71d3a8..46505ee 100644
--- a/examples/simple/e2e.yaml
+++ b/examples/simple/e2e.yaml
@@ -20,12 +20,7 @@ setup:
file: kind.yaml
steps:
- command: |
- if test -d "$TMPDIR"; then
- :
- else
- TMPDIR=/tmp
- fi
-
+ # kind k8s cluster is in $TMPDIR
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/)
@@ -46,6 +41,10 @@ setup:
for: condition=Available
timeout: 1200
+cleanup:
+ # always never success failure
+ on: always
+
trigger:
action: http
interval: 3s
diff --git a/internal/components/setup/kind.go b/internal/components/setup/kind.go
index 915a207..3108f58 100644
--- a/internal/components/setup/kind.go
+++ b/internal/components/setup/kind.go
@@ -58,9 +58,9 @@ func KindSetup(e2eConfig *config.E2EConfig) error {
return fmt.Errorf("no kind config file was provided")
}
- manifests := e2eConfig.Setup.Steps
- // if no manifests was provided, then no need to create the cluster.
- if manifests == nil {
+ steps := e2eConfig.Setup.Steps
+ // if no steps was provided, then no need to create the cluster.
+ if steps == nil {
logger.Log.Info("no steps is provided")
return nil
}
diff --git a/internal/config/e2eConfig.go b/internal/config/e2eConfig.go
index 23620f1..4758473 100644
--- a/internal/config/e2eConfig.go
+++ b/internal/config/e2eConfig.go
@@ -23,6 +23,7 @@ import "github.com/apache/skywalking-infra-e2e/internal/util"
// E2EConfig corresponds to configuration file e2e.yaml.
type E2EConfig struct {
Setup Setup `yaml:"setup"`
+ Cleanup Cleanup `yaml:"cleanup"`
Trigger Trigger `yaml:"trigger"`
Verify []VerifyCase `yaml:"verify"`
}
@@ -34,6 +35,10 @@ type Setup struct {
Timeout int `yaml:"timeout"`
}
+type Cleanup struct {
+ On string `yaml:"on"`
+}
+
type Step struct {
Path string `yaml:"path"`
Command string `yaml:"command"`
diff --git a/internal/constant/cleanup.go b/internal/constant/cleanup.go
new file mode 100644
index 0000000..72a72f4
--- /dev/null
+++ b/internal/constant/cleanup.go
@@ -0,0 +1,26 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package constant
+
+const (
+ CleanUpOnSuccess = "success"
+ CleanUpOnFailure = "failure"
+ CleanUpAlways = "always"
+ CleanUpNever = "never"
+)