From bd55e8ded3ccfd2172d8efa5cee2d14366eb7f2c Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Mon, 2 Sep 2024 11:43:12 -0400 Subject: [PATCH] kind: fix setup on HA clusters 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 https://github.com/tilt-dev/ctlptl/issues/356 Signed-off-by: Nick Santos --- pkg/cluster/admin_kind.go | 14 +++++++++++- pkg/cluster/admin_kind_test.go | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/pkg/cluster/admin_kind.go b/pkg/cluster/admin_kind.go index 52068e5..a7b1cdb 100644 --- a/pkg/cluster/admin_kind.go +++ b/pkg/cluster/admin_kind.go @@ -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) { diff --git a/pkg/cluster/admin_kind_test.go b/pkg/cluster/admin_kind_test.go index 0b62d86..fdecd58 100644 --- a/pkg/cluster/admin_kind_test.go +++ b/pkg/cluster/admin_kind_test.go @@ -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) { @@ -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) +}