You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2023/02/17 11:54:12 UTC
[skywalking-infra-e2e] branch main updated: Automatically pull images before loading into KinD (#10397) (#101)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 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 f13a7e4 Automatically pull images before loading into KinD (#10397) (#101)
f13a7e4 is described below
commit f13a7e4d3122a67ee9a643d478421083893e2e85
Author: ethan256 <yu...@163.com>
AuthorDate: Fri Feb 17 19:54:05 2023 +0800
Automatically pull images before loading into KinD (#10397) (#101)
---
internal/components/setup/kind.go | 42 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/internal/components/setup/kind.go b/internal/components/setup/kind.go
index 4fe24a4..2ab9923 100644
--- a/internal/components/setup/kind.go
+++ b/internal/components/setup/kind.go
@@ -22,6 +22,7 @@ import (
"bufio"
"bytes"
"context"
+ "errors"
"fmt"
"net/http"
"os"
@@ -29,6 +30,7 @@ import (
"strconv"
"strings"
"sync"
+ "sync/atomic"
"time"
apiv1 "k8s.io/api/admission/v1"
@@ -45,6 +47,8 @@ import (
"k8s.io/kubectl/pkg/scheme"
ctlutil "k8s.io/kubectl/pkg/util"
+ "github.com/docker/docker/api/types"
+ docker "github.com/docker/docker/client"
kind "sigs.k8s.io/kind/cmd/kind/app"
kindcmd "sigs.k8s.io/kind/pkg/cmd"
@@ -73,8 +77,39 @@ type kindPort struct {
waitExpose string // Need to use when expose
}
-//nolint:gocyclo // skip the cyclomatic complexity check here
+// pullImages pull docker images from remote before loading them into KinD cluster
+func pullImages(images []string) error {
+ cli, err := docker.NewClientWithOpts(docker.FromEnv)
+ if err != nil {
+ return err
+ }
+ defer cli.Close()
+
+ var count int32
+ var wg sync.WaitGroup
+ for _, image := range images {
+ wg.Add(1)
+ go func(image string) {
+ defer wg.Done()
+ out, err := cli.ImagePull(context.Background(), image, types.ImagePullOptions{})
+ if err != nil {
+ logger.Log.Error("pull image error", "name", image, "error", err)
+ return
+ }
+ atomic.AddInt32(&count, 1)
+ out.Close()
+ }(image)
+ }
+ wg.Wait()
+ if int(count) != len(images) {
+ return errors.New("can not pull all images")
+ }
+ return nil
+}
+
// KindSetup sets up environment according to e2e.yaml.
+//
+//nolint:gocyclo // skip the cyclomatic complexity check here
func KindSetup(e2eConfig *config.E2EConfig) error {
kindConfigPath = e2eConfig.Setup.GetFile()
@@ -117,6 +152,11 @@ func KindSetup(e2eConfig *config.E2EConfig) error {
// import images
if len(e2eConfig.Setup.Kind.ImportImages) > 0 {
+ // pull images if this image not exist
+ if err := pullImages(e2eConfig.Setup.Kind.ImportImages); err != nil {
+ return err
+ }
+
for _, image := range e2eConfig.Setup.Kind.ImportImages {
image = os.ExpandEnv(image)
args := []string{"load", "docker-image", image}