Skip to content

Commit

Permalink
kind: fix setup on HA clusters (#357)
Browse files Browse the repository at this point in the history
when there are multiple control plane nodes,
kind creates an LB node in front of them.

before this change, we would try
to configure the registry on the LB node,
which is unnecessary and doesn't work.

fixes #356

Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks authored Sep 2, 2024
1 parent 8d20d87 commit 4ffc924
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/cluster/admin_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,19 @@ func (a *kindAdmin) applyContainerdPatchRegistryApiV2(ctx context.Context, desir
if err != nil {
return errors.Wrap(err, "configuring registry")
}
return applyContainerdPatchRegistryApiV2(ctx, a.runner, a.iostreams, nodes, desired, registry)
filtered := []string{}
for _, node := range nodes {
if strings.HasSuffix(node, "external-load-balancer") {
// Ignore the external load balancers.
// These load-balance traffic to the control plane nodes.
// They don't need registry configuration.
continue
}
filtered = append(filtered, node)
}

return applyContainerdPatchRegistryApiV2(ctx, a.runner, a.iostreams,
filtered, desired, registry)
}

func (a *kindAdmin) getNodes(ctx context.Context, cluster string) ([]string, error) {
Expand Down
39 changes: 39 additions & 0 deletions pkg/cluster/admin_kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"

"github.com/tilt-dev/ctlptl/internal/exec"
"github.com/tilt-dev/ctlptl/pkg/api"
)

func TestNodeImage(t *testing.T) {
Expand Down Expand Up @@ -43,3 +44,41 @@ func TestNodeImage(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "kindest/node:v1.16.9@sha256:7175872357bc85847ec4b1aba46ed1d12fa054c83ac7a8a11f5c268957fd5765", img)
}

func TestPatchRegistryConfig(t *testing.T) {
nodeExec := []string{}
runner := exec.NewFakeCmdRunner(func(argv []string) string {
if argv[0] == "kind" && argv[1] == "get" && argv[2] == "nodes" {
return `kind-external-load-balancer
kind-control-plane
kind-control-plane2
`
}
if argv[0] == "docker" && argv[1] == "exec" && argv[2] == "-i" {
nodeExec = append(nodeExec, argv[3])
}
return ""
})
iostreams := genericclioptions.IOStreams{
In: os.Stdin,
Out: os.Stdout,
ErrOut: os.Stderr,
}
a := newKindAdmin(iostreams, runner, &fakeDockerClient{})
ctx := context.Background()

err := a.applyContainerdPatchRegistryApiV2(
ctx,
&api.Cluster{Name: "test-cluster"},
&api.Registry{Name: "test-registry"})
assert.NoError(t, err)

// Assert that we only executed commands
// in the control plane nodes, not the LB.
assert.Equal(t, []string{
"kind-control-plane",
"kind-control-plane",
"kind-control-plane2",
"kind-control-plane2",
}, nodeExec)
}

0 comments on commit 4ffc924

Please sign in to comment.