Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Brown <[email protected]>
  • Loading branch information
Derek Brown authored and Derek Brown committed Jan 4, 2025
1 parent f6502ca commit dec201f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions pkg/cluster/admin_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (a *kindAdmin) EnsureInstalled(ctx context.Context) error {
return nil
}

func (a *kindAdmin) kindClusterConfig(desired *api.Cluster, registry *api.Registry, registryAPI containerdRegistryAPI) *v1alpha4.Cluster {
func (a *kindAdmin) kindClusterConfig(desired *api.Cluster, registry *api.Registry, registryAPI containerdRegistryAPI) (*v1alpha4.Cluster, error) {
kindConfig := desired.KindV1Alpha4Cluster
if kindConfig == nil {
kindConfig = &v1alpha4.Cluster{}
Expand Down Expand Up @@ -90,8 +90,7 @@ func (a *kindAdmin) kindClusterConfig(desired *api.Cluster, registry *api.Regist
// Parse the endpoint
parsedEndpoint, err := url.Parse(reg.Endpoint)
if err != nil {
klog.Warningf("Failed to parse registry URL %s: %v", reg.Endpoint, err)
continue
return nil, errors.Wrapf(err, "Error parsing registry endpoint: %s", reg.Endpoint)
}

// Add the registry to the list of mirrors.
Expand All @@ -113,7 +112,7 @@ func (a *kindAdmin) kindClusterConfig(desired *api.Cluster, registry *api.Regist
}
}

return kindConfig
return kindConfig, nil
}

func (a *kindAdmin) Create(ctx context.Context, desired *api.Cluster, registry *api.Registry) error {
Expand Down Expand Up @@ -168,7 +167,11 @@ func (a *kindAdmin) Create(ctx context.Context, desired *api.Cluster, registry *
args = append(args, "--image", node)
}

kindConfig := a.kindClusterConfig(desired, registry, registryAPI)
kindConfig, err := a.kindClusterConfig(desired, registry, registryAPI)
if err != nil {
return errors.Wrap(err, "generating kind config")
}

buf := bytes.NewBuffer(nil)
encoder := yaml.NewEncoder(buf)
err = encoder.Encode(kindConfig)
Expand Down Expand Up @@ -196,7 +199,7 @@ func (a *kindAdmin) Create(ctx context.Context, desired *api.Cluster, registry *
}
}

if registryAPI == containerdRegistryV2 {
if registryAPI == containerdRegistryV2 && len(desired.RegistryAuths) == 0 {
err = a.applyContainerdPatchRegistryApiV2(ctx, desired, registry)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/cluster/admin_kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func TestKindClusterConfigWithPullThroughRegistries(t *testing.T) {
},
}

kindConfig := a.kindClusterConfig(desired, nil, containerdRegistryV2)
kindConfig, err := a.kindClusterConfig(desired, nil, containerdRegistryV2)
assert.NoError(t, err)

expectedMirror := `[plugins."io.containerd.grpc.v1.cri".registry.mirrors."example.com"]
endpoint = ["http://example.com:5000"]
Expand Down

0 comments on commit dec201f

Please sign in to comment.