You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2023/01/11 15:35:54 UTC

[skywalking-infra-e2e] branch main updated: Add a field kubeconfig to support e2e test on an existing kubernetes cluster (#94)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 78bb28a  Add a field kubeconfig to support  e2e test on an existing kubernetes cluster (#94)
78bb28a is described below

commit 78bb28ae165e39df7d5c70c8a0ad19a074b584db
Author: Ye Cao <da...@gmail.com>
AuthorDate: Wed Jan 11 23:35:48 2023 +0800

    Add a field kubeconfig to support  e2e test on an existing kubernetes cluster (#94)
---
 CHANGES.md                                    |  1 +
 commands/cleanup/cleanup.go                   | 10 +++++++---
 docs/en/concepts-and-designs/module-design.md |  2 +-
 docs/en/setup/Configuration-File.md           |  6 +++++-
 go.mod                                        |  4 +---
 go.sum                                        | 12 +++---------
 internal/components/setup/kind.go             | 18 ++++++++++++++----
 internal/config/e2eConfig.go                  |  8 ++++++++
 8 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index e4c57ef..a15f0dd 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -8,6 +8,7 @@ Release Notes.
 * Support `sha256enc` and `sha512enc` encoding in verify case.
 * Support `hasPrefix` and `hasSuffix` string verifier in verify case.
 * Bump up `kind` to v0.14.0.
+* Add a field `kubeconfig` to support running e2e test on an existing kubernetes cluster.
 
 #### Bug Fixes
 
diff --git a/commands/cleanup/cleanup.go b/commands/cleanup/cleanup.go
index c8fb538..3e7079d 100644
--- a/commands/cleanup/cleanup.go
+++ b/commands/cleanup/cleanup.go
@@ -46,9 +46,13 @@ func DoCleanupAccordingE2E() error {
 	e2eConfig := config.GlobalConfig.E2EConfig
 
 	if e2eConfig.Setup.Env == constant.Kind {
-		err := cleanup.KindCleanUp(&e2eConfig)
-		if err != nil {
-			return err
+		kubeConfigPath := e2eConfig.Setup.GetKubeconfig()
+		// if there is an existing kubernetes cluster, don't delete the kind cluster.
+		if kubeConfigPath == "" {
+			err := cleanup.KindCleanUp(&e2eConfig)
+			if err != nil {
+				return err
+			}
 		}
 	} else if e2eConfig.Setup.Env == constant.Compose {
 		err := cleanup.ComposeCleanUp(&e2eConfig)
diff --git a/docs/en/concepts-and-designs/module-design.md b/docs/en/concepts-and-designs/module-design.md
index 06bb400..14d44ba 100644
--- a/docs/en/concepts-and-designs/module-design.md
+++ b/docs/en/concepts-and-designs/module-design.md
@@ -55,7 +55,7 @@ Support two ways to set up the environment:
   1. Wait until all services are ready according to the interval, etc.
   1. Execute command to set up the testing environment or help verify, such as `yq` help to eval the YAML format.
 - **kind**:
-  1. Start the `KinD` cluster according to the config files.
+  1. Start the `KinD` cluster according to the config files or Start on an existing kubernetes cluster.
   1. Apply the resources files (`--manifests`) or/and run the custom init command (`--commands`).
   1. Check the pods' readiness.
   1. Wait until all pods are ready according to the `interval`, etc.
diff --git a/docs/en/setup/Configuration-File.md b/docs/en/setup/Configuration-File.md
index 23f3d1f..d6e833c 100644
--- a/docs/en/setup/Configuration-File.md
+++ b/docs/en/setup/Configuration-File.md
@@ -25,6 +25,7 @@ Support two kinds of the environment to set up the system.
 setup:
   env: kind
   file: path/to/kind.yaml               # Specified kinD manifest file path
+  kubeconfig: path/.kube/config         # The path of kubeconfig
   timeout: 20m                          # timeout duration
   init-system-environment: path/to/env  # Import environment file
   steps:                                # customize steps for prepare the environment
@@ -46,8 +47,11 @@ setup:
           port:                         # Want to expose port from resource
 ```
 
+> **_NOTE:_** The fields `file` and `kubeconfig` are mutually exclusive.
+
 The `KinD` environment follow these steps:
-1. Start the `KinD` cluster according to the config file, expose `KUBECONFIG` to environment for help execute `kubectl` in the steps.
+1. [optional]Start the `KinD` cluster according to the config file, expose `KUBECONFIG` to environment for help execute `kubectl` in the next steps.
+1. [optional]Setup the kubeconfig field for help execute `kubectl` in the next steps.
 1. Load docker images from `kind.import-images` if needed.
 1. Apply the resources files (`--manifests`) or/and run the custom init command (`--commands`) by steps.
 1. Wait until all steps are finished and all services are ready with the timeout(second).
diff --git a/go.mod b/go.mod
index 5c9a0c7..a29ce95 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
 	github.com/docker/docker v20.10.7+incompatible
 	github.com/docker/go-connections v0.4.0
 	github.com/google/go-cmp v0.5.5
-	github.com/hashicorp/go-multierror v1.1.1
+	github.com/pterm/pterm v0.12.45
 	github.com/sirupsen/logrus v1.7.0
 	github.com/spf13/cobra v1.4.0
 	github.com/testcontainers/testcontainers-go v0.11.1
@@ -59,7 +59,6 @@ require (
 	github.com/gookit/color v1.5.0 // indirect
 	github.com/gorilla/mux v1.8.0 // indirect
 	github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
-	github.com/hashicorp/errwrap v1.1.0 // indirect
 	github.com/imdario/mergo v0.3.11 // indirect
 	github.com/inconshreveable/mousetrap v1.0.0 // indirect
 	github.com/josharian/intern v1.0.0 // indirect
@@ -85,7 +84,6 @@ require (
 	github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
 	github.com/pkg/errors v0.9.1 // indirect
 	github.com/pmezard/go-difflib v1.0.0 // indirect
-	github.com/pterm/pterm v0.12.45 // indirect
 	github.com/rivo/uniseg v0.2.0 // indirect
 	github.com/russross/blackfriday v1.5.2 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
diff --git a/go.sum b/go.sum
index c1f04e2..b773ea2 100644
--- a/go.sum
+++ b/go.sum
@@ -67,6 +67,7 @@ github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBE
 github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k=
 github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI=
 github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c=
+github.com/MarvinJWendt/testza v0.4.2 h1:Vbw9GkSB5erJI2BPnBL9SVGV9myE+XmUSFahBGUhW2Q=
 github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE=
 github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
 github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
@@ -441,15 +442,11 @@ github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBt
 github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
 github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
 github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
-github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
-github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
 github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
 github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
 github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
 github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
 github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
-github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
-github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
 github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
 github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
 github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
@@ -498,6 +495,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
 github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
 github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
 github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
+github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
 github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -693,8 +691,8 @@ github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiB
 github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
 github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
-github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
 github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
+github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
 github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
@@ -998,13 +996,10 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20211025112917-711f33c9992c h1:i4MLwL3EbCgobekQtkVW94UBSPLMadfEGtKq+CAFsEU=
-golang.org/x/sys v0.0.0-20211025112917-711f33c9992c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
 golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
-golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
 golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
@@ -1016,7 +1011,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
 golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
diff --git a/internal/components/setup/kind.go b/internal/components/setup/kind.go
index 8f186be..039d0f9 100644
--- a/internal/components/setup/kind.go
+++ b/internal/components/setup/kind.go
@@ -73,12 +73,19 @@ type kindPort struct {
 	waitExpose string // Need to use when expose
 }
 
+//nolint:gocyclo // skip the cyclomatic complexity check here
 // KindSetup sets up environment according to e2e.yaml.
 func KindSetup(e2eConfig *config.E2EConfig) error {
 	kindConfigPath = e2eConfig.Setup.GetFile()
 
-	if kindConfigPath == "" {
-		return fmt.Errorf("no kind config file was provided")
+	kubeConfigPath = e2eConfig.Setup.GetKubeconfig()
+
+	if kindConfigPath == "" && kubeConfigPath == "" {
+		return fmt.Errorf("no kind config file and kubeconfig file was provided")
+	}
+
+	if kindConfigPath != "" && kubeConfigPath != "" {
+		return fmt.Errorf("the kind config file and kubeconfig file cannot be provided at the same time")
 	}
 
 	steps := e2eConfig.Setup.Steps
@@ -94,8 +101,11 @@ func KindSetup(e2eConfig *config.E2EConfig) error {
 		util.ExportEnvVars(profilePath)
 	}
 
-	if err := createKindCluster(kindConfigPath, e2eConfig); err != nil {
-		return err
+	// if there is an existing cluster, don't create a new kind cluster here.
+	if kubeConfigPath == "" {
+		if err := createKindCluster(kindConfigPath, e2eConfig); err != nil {
+			return err
+		}
 	}
 
 	// import images
diff --git a/internal/config/e2eConfig.go b/internal/config/e2eConfig.go
index 2062150..18a3352 100644
--- a/internal/config/e2eConfig.go
+++ b/internal/config/e2eConfig.go
@@ -39,6 +39,7 @@ type E2EConfig struct {
 type Setup struct {
 	Env                   string    `yaml:"env"`
 	File                  string    `yaml:"file"`
+	Kubeconfig            string    `yaml:"kubeconfig"`
 	Steps                 []Step    `yaml:"steps"`
 	Timeout               any       `yaml:"timeout"`
 	InitSystemEnvironment string    `yaml:"init-system-environment"`
@@ -99,6 +100,13 @@ func (s *Setup) GetFile() string {
 	return file
 }
 
+func (s *Setup) GetKubeconfig() string {
+	// expand the file path with system environment
+	file := os.ExpandEnv(s.Kubeconfig)
+	file = util.ResolveAbs(file)
+	return file
+}
+
 type Manifest struct {
 	Path  string `yaml:"path"`
 	Waits []Wait `yaml:"wait"`