Skip to content

Commit

Permalink
Fix kind load docker-image error (#126)
Browse files Browse the repository at this point in the history
* Fix kind load docker-image error

* Update CHANGES.md to 1.4.0
  • Loading branch information
CodePrometheus authored May 20, 2024
1 parent 1485ae0 commit 616a7d4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 70 deletions.
38 changes: 2 additions & 36 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 2 additions & 25 deletions internal/components/cleanup/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ 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 (
maxRetry = 5
retryInterval = 2 // in seconds
)

type KindClusterNameConfig struct {
Name string
}

func KindCleanUp(e2eConfig *config.E2EConfig) error {
kindConfigFilePath := e2eConfig.Setup.GetFile()

Expand All @@ -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
}
Expand Down
27 changes: 18 additions & 9 deletions internal/components/setup/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 25 additions & 0 deletions internal/util/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 616a7d4

Please sign in to comment.