Skip to content

Commit

Permalink
Add more logs for KIND initialization (#80)
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Neumann <[email protected]>
  • Loading branch information
ANeumann82 authored May 8, 2020
1 parent ebb44c1 commit 536959e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ func (h *Harness) RunKIND() (*rest.Config, error) {
h.kind = &kind

if h.kind.IsRunning() {
h.T.Logf("KIND is already running, using existing cluster")
return clientcmd.BuildConfigFromFlags("", h.explicitPath())
}

kindCfg := &kindConfig.Cluster{}

if h.TestSuite.KINDConfig != "" {
h.T.Logf("Loading KIND config from %s", h.TestSuite.KINDConfig)
var err error
kindCfg, err = loadKindConfig(h.TestSuite.KINDConfig)
if err != nil {
Expand All @@ -138,11 +140,12 @@ func (h *Harness) RunKIND() (*rest.Config, error) {

h.addNodeCaches(dockerClient, kindCfg)

h.T.Log("Starting KIND cluster")
if err := h.kind.Run(kindCfg); err != nil {
return nil, err
}

if err := h.kind.AddContainers(dockerClient, h.TestSuite.KINDContainers); err != nil {
if err := h.kind.AddContainers(dockerClient, h.TestSuite.KINDContainers, h.T); err != nil {
return nil, err
}
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/test/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"context"
"testing"

"sigs.k8s.io/kind/pkg/apis/config/v1alpha3"
"sigs.k8s.io/kind/pkg/cluster"
Expand Down Expand Up @@ -55,18 +56,21 @@ func (k *kind) IsRunning() bool {

// AddContainers loads the named Docker containers into a KIND cluster.
// The cluster must be running for this to work.
func (k *kind) AddContainers(docker testutils.DockerClient, containers []string) error {
func (k *kind) AddContainers(docker testutils.DockerClient, containers []string, t *testing.T) error {
if !k.IsRunning() {
panic("KIND cluster isn't running")
}

t.Logf("Adding Containers to KIND...\n")

nodes, err := k.Provider.ListNodes(k.context)
if err != nil {
return err
}

for _, node := range nodes {
for _, container := range containers {
t.Logf("Add image %s to node %s\n", container, node.String())
if err := loadContainer(docker, node, container); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/test/kind_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestAddContainers(t *testing.T) {
t.Errorf("failed to close image pull output: %v", err)
}

if err := kind.AddContainers(docker, []string{testImage}); err != nil {
if err := kind.AddContainers(docker, []string{testImage}, t); err != nil {
t.Errorf("failed to add container to KIND cluster: %v", err)
}

Expand Down

0 comments on commit 536959e

Please sign in to comment.