diff --git a/CHANGES.md b/CHANGES.md index 1fe7d32..ef8ca61 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,45 +2,11 @@ Changes by Version ================== Release Notes. -1.3.0 +1.4.0 ------------------ -#### Features -* 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. -* Support non-fail-fast execution of test cases -* support verify cases concurrently -* Add .exe suffix to windows build artifact -* Export the kubeconfig path during executing the following steps -* Automatically pull images before loading into KinD -* Support outputting the result of 'verify' in YAML format and only outputting the summary of the result of 'verify' -* Make e2e test itself in github action -* Support outputting the summary of 'verify' in YAML format -* Make e2e output summary with numeric information -* Add 'subtractor' function - -#### Improvements - -* Bump up GHA to avoid too many warnings -* Leverage the built-in cache in setup-go@v4 -* Add `batchOutput` config to reduce outputs -* Disable batch mode by default, add it to GHA and enable by default -* Improve GitHub Actions usability and speed by using composite actions' new feature -* Migrate deprecated GitHub Actions command to recommended ones -* Bump up kind to v0.14.0 -* Optimization of the output information of verification -* verifier: notEmpty should be able to handle nil -* Remove invalid configuration in GitHub Actions - #### Bug Fixes -* Fix deprecation warnings -* Ignore cancel error when copying container logs - -#### Documentation - -* Add a doc to introduce how to use e2e to test itself +* Fix kind load docker-image error #### Issues and PR - All issues are [here](https://github.com/apache/skywalking/milestone/148?closed=1) diff --git a/internal/components/cleanup/kind.go b/internal/components/cleanup/kind.go index cd9e9f3..d2817fd 100644 --- a/internal/components/cleanup/kind.go +++ b/internal/components/cleanup/kind.go @@ -23,13 +23,13 @@ import ( "strings" "time" - "gopkg.in/yaml.v2" kind "sigs.k8s.io/kind/cmd/kind/app" kindcmd "sigs.k8s.io/kind/pkg/cmd" "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/apache/skywalking-infra-e2e/internal/util" ) const ( @@ -37,10 +37,6 @@ const ( retryInterval = 2 // in seconds ) -type KindClusterNameConfig struct { - Name string -} - func KindCleanUp(e2eConfig *config.E2EConfig) error { kindConfigFilePath := e2eConfig.Setup.GetFile() @@ -61,27 +57,8 @@ func KindCleanUp(e2eConfig *config.E2EConfig) error { return nil } -func getKindClusterName(kindConfigFilePath string) (name string, err error) { - data, err := os.ReadFile(kindConfigFilePath) - if err != nil { - return "", err - } - - nameConfig := KindClusterNameConfig{} - err = yaml.Unmarshal(data, &nameConfig) - if err != nil { - return "", err - } - - if nameConfig.Name == "" { - nameConfig.Name = constant.KindClusterDefaultName - } - - return nameConfig.Name, nil -} - func cleanKindCluster(kindConfigFilePath string) (err error) { - clusterName, err := getKindClusterName(kindConfigFilePath) + clusterName, err := util.GetKindClusterName(kindConfigFilePath) if err != nil { return err } diff --git a/internal/components/setup/kind.go b/internal/components/setup/kind.go index a7b7b92..a344fe0 100644 --- a/internal/components/setup/kind.go +++ b/internal/components/setup/kind.go @@ -156,15 +156,9 @@ func pullImages(ctx context.Context, images []string) error { //nolint:gocyclo // skip the cyclomatic complexity check here func KindSetup(e2eConfig *config.E2EConfig) error { kindConfigPath = e2eConfig.Setup.GetFile() - 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") + if err := checkKubeConfig(kindConfigPath); err != nil { + return err } steps := e2eConfig.Setup.Steps @@ -205,8 +199,12 @@ func KindSetup(e2eConfig *config.E2EConfig) error { return err } + clusterName, err := util.GetKindClusterName(kindConfigPath) + if err != nil { + return err + } for _, image := range images { - args := []string{"load", "docker-image", image} + args := []string{"load", "docker-image", image, "--name", clusterName} logger.Log.Infof("import docker images: %s", image) if err := kind.Run(kindcmd.NewLogger(), kindcmd.StandardIOStreams(), args); err != nil { @@ -254,6 +252,17 @@ func KindSetup(e2eConfig *config.E2EConfig) error { return nil } +func checkKubeConfig(kindConfigPath string) error { + 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") + } + return nil +} + func KindShouldWaitSignal() bool { return portForwardContext != nil && portForwardContext.resourceCount > 0 } diff --git a/internal/util/k8s.go b/internal/util/k8s.go index 6213b07..bbb9e64 100644 --- a/internal/util/k8s.go +++ b/internal/util/k8s.go @@ -40,6 +40,7 @@ import ( "k8s.io/client-go/restmapper" "k8s.io/client-go/tools/clientcmd" + "github.com/apache/skywalking-infra-e2e/internal/constant" "github.com/apache/skywalking-infra-e2e/internal/logger" ) @@ -51,6 +52,10 @@ type K8sClusterInfo struct { namespace string } +type KindClusterNameConfig struct { + Name string `json:"name"` +} + // ConnectToK8sCluster gets clientSet and dynamic client from k8s config file. func ConnectToK8sCluster(kubeConfigPath string) (info *K8sClusterInfo, err error) { config, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath) @@ -224,3 +229,23 @@ func OperateManifest(c *kubernetes.Clientset, dc dynamic.Interface, manifest str return nil } + +func GetKindClusterName(kindConfigFilePath string) (name string, err error) { + data, err := os.ReadFile(kindConfigFilePath) + if err != nil { + return "", err + } + + nameConfig := KindClusterNameConfig{} + decoder := yamlutil.NewYAMLOrJSONDecoder(bytes.NewReader(data), 100) + err = decoder.Decode(&nameConfig) + if err != nil { + return "", err + } + + if nameConfig.Name == "" { + nameConfig.Name = constant.KindClusterDefaultName + } + + return nameConfig.Name, nil +}