Skip to content

Commit

Permalink
fixup! e2e: preload httpbin and grpcbin images
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiamoe authored and Roberto Santalla committed Sep 14, 2023
1 parent bd4989c commit bdd2e7b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
8 changes: 8 additions & 0 deletions e2e/disruptors/pod_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions e2e/disruptors/service_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 26 additions & 16 deletions pkg/testutils/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 == "" {
Expand Down
14 changes: 8 additions & 6 deletions pkg/testutils/e2e/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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...)
}

0 comments on commit bdd2e7b

Please sign in to comment.