From bdd2e7bcef996bd49b865c90d47e42f17a3b9b8c Mon Sep 17 00:00:00 2001 From: Roberto Santalla Date: Wed, 13 Sep 2023 17:55:24 +0200 Subject: [PATCH] fixup! e2e: preload httpbin and grpcbin images --- e2e/disruptors/pod_e2e_test.go | 8 ++++++ e2e/disruptors/service_e2e_test.go | 7 +++++ pkg/testutils/cluster/cluster.go | 42 +++++++++++++++++----------- pkg/testutils/e2e/cluster/cluster.go | 14 ++++++---- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/e2e/disruptors/pod_e2e_test.go b/e2e/disruptors/pod_e2e_test.go index 932d1db6..aa29c22a 100644 --- a/e2e/disruptors/pod_e2e_test.go +++ b/e2e/disruptors/pod_e2e_test.go @@ -39,6 +39,14 @@ func Test_PodDisruptor(t *testing.T) { _ = cluster.Cleanup() }) + err = cluster.Load( + fixtures.BuildHttpbinPod().Spec.Containers[0].Image, + fixtures.BuildGrpcpbinPod().Spec.Containers[0].Image, + ) + if err != nil { + t.Fatalf("preloading test pod images: %v", err) + } + k8s, err := kubernetes.NewFromKubeconfig(cluster.Kubeconfig()) if err != nil { t.Errorf("error creating kubernetes client: %v", err) diff --git a/e2e/disruptors/service_e2e_test.go b/e2e/disruptors/service_e2e_test.go index c92b0a69..4a546bd5 100644 --- a/e2e/disruptors/service_e2e_test.go +++ b/e2e/disruptors/service_e2e_test.go @@ -34,6 +34,13 @@ func Test_ServiceDisruptor(t *testing.T) { _ = cluster.Cleanup() }) + err = cluster.Load( + fixtures.BuildHttpbinPod().Spec.Containers[0].Image, + ) + if err != nil { + t.Fatalf("preloading test pod images: %v", err) + } + k8s, err := kubernetes.NewFromKubeconfig(cluster.Kubeconfig()) if err != nil { t.Errorf("error creating kubernetes client: %v", err) diff --git a/pkg/testutils/cluster/cluster.go b/pkg/testutils/cluster/cluster.go index 8058f113..b9ea3800 100644 --- a/pkg/testutils/cluster/cluster.go +++ b/pkg/testutils/cluster/cluster.go @@ -269,20 +269,6 @@ func (c *Config) Create() (*Cluster, error) { return nil, err } - // pre-load images - if len(c.options.Images) > 0 { - var nodes []nodes.Node - - nodes, err = provider.ListInternalNodes(c.name) - if err != nil { - return nil, err - } - err = loadImages(c.options.Images, nodes) - if err != nil { - return nil, err - } - } - kubeconfig := c.options.Kubeconfig if kubeconfig == "" { kubeconfig = filepath.Join(os.TempDir(), c.name) @@ -292,11 +278,21 @@ func (c *Config) Create() (*Cluster, error) { return nil, err } - return &Cluster{ + cluster := &Cluster{ name: c.name, kubeconfig: kubeconfig, provider: *provider, - }, nil + } + + // pre-load images + if len(c.options.Images) > 0 { + err = cluster.Load(c.options.Images...) + if err != nil { + return nil, fmt.Errorf("preloading images: %w", err) + } + } + + return cluster, nil } // Delete deletes a test cluster @@ -317,6 +313,20 @@ func (c *Cluster) Name() string { return c.name } +// Load loads the supplied images into the cluster. +func (c *Cluster) Load(images ...string) error { + nodes, err := c.provider.ListInternalNodes(c.name) + if err != nil { + return err + } + err = loadImages(images, nodes) + if err != nil { + return err + } + + return nil +} + // GetCluster returns an existing cluster if exists, nil otherwise func GetCluster(name string, kubeconfig string) (*Cluster, error) { if name == "" || kubeconfig == "" { diff --git a/pkg/testutils/e2e/cluster/cluster.go b/pkg/testutils/e2e/cluster/cluster.go index 9568e0b4..d08e045c 100644 --- a/pkg/testutils/e2e/cluster/cluster.go +++ b/pkg/testutils/e2e/cluster/cluster.go @@ -45,6 +45,8 @@ type E2eCluster interface { Kubeconfig() string // Name returns the name of the cluster Name() string + // Load loads the supplied images to the clusters' nodes. + Load(images ...string) error } const contourConfig = ` @@ -108,12 +110,8 @@ func InstallContourIngress(ctx context.Context, cluster E2eCluster) error { // TODO: allow override of default port using an environment variable (E2E_INGRESS_PORT) func DefaultE2eClusterConfig() E2eClusterConfig { return E2eClusterConfig{ - Name: "e2e-test", - Images: []string{ - "ghcr.io/grafana/xk6-disruptor-agent:latest", - "kennethreitz/httpbin", - "moul/grpcbin", - }, + Name: "e2e-test", + Images: []string{"ghcr.io/grafana/xk6-disruptor-agent:latest"}, IngressAddr: "localhost", IngressPort: 30080, Reuse: false, @@ -355,3 +353,7 @@ func (c *e2eCluster) Ingress() string { func (c *e2eCluster) Kubeconfig() string { return c.cluster.Kubeconfig() } + +func (c *e2eCluster) Load(images ...string) error { + return c.cluster.Load(images...) +}