Skip to content

Commit

Permalink
Fix wildcard entry upstream fallback
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Mar 13, 2024
1 parent 364dfd8 commit bba3e3c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/agent/containerd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ func getHostConfigs(registry *registries.Registry, noDefaultEndpoint bool, mirro
logrus.Errorf("Failed to generate config for registry %s: %v", host, err)
continue
} else {
if host == "*" || noDefaultEndpoint {
if noDefaultEndpoint {
c.Default = nil
} else if host == "*" {
c.Default = &templates.RegistryEndpoint{URL: &url.URL{}}
}
config = *c
}
Expand Down
63 changes: 63 additions & 0 deletions pkg/agent/containerd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,16 @@ func Test_UnitGetHostConfigs(t *testing.T) {
},
},
},
{
name: "wildcard mirror endpoint - no endpoints",
args: args{
registryContent: `
mirrors:
"*":
`,
},
want: HostConfigs{},
},
{
name: "wildcard mirror endpoint - full URL",
args: args{
Expand All @@ -1205,6 +1215,9 @@ func Test_UnitGetHostConfigs(t *testing.T) {
want: HostConfigs{
"_default": templates.HostConfig{
Program: "k3s",
Default: &templates.RegistryEndpoint{
URL: u(""),
},
Endpoints: []templates.RegistryEndpoint{
{
URL: u("https://registry.example.com/v2"),
Expand All @@ -1227,6 +1240,9 @@ func Test_UnitGetHostConfigs(t *testing.T) {
want: HostConfigs{
"_default": templates.HostConfig{
Program: "k3s",
Default: &templates.RegistryEndpoint{
URL: u(""),
},
Endpoints: []templates.RegistryEndpoint{
{
URL: u("https://127.0.0.1:6443/v2"),
Expand Down Expand Up @@ -1258,6 +1274,53 @@ func Test_UnitGetHostConfigs(t *testing.T) {
},
},
},
{
name: "wildcard mirror endpoint - full URL, embedded registry, no default",
args: args{
noDefaultEndpoint: true,
mirrorAddr: "127.0.0.1:6443",
registryContent: `
mirrors:
"*":
endpoint:
- https://registry.example.com/v2
`,
},
want: HostConfigs{
"_default": templates.HostConfig{
Program: "k3s",
Endpoints: []templates.RegistryEndpoint{
{
URL: u("https://127.0.0.1:6443/v2"),
Config: registries.RegistryConfig{
TLS: &registries.TLSConfig{
CAFile: "server-ca",
KeyFile: "client-key",
CertFile: "client-cert",
},
},
},
{
URL: u("https://registry.example.com/v2"),
},
},
},
"127.0.0.1:6443": templates.HostConfig{
Program: "k3s",
Default: &templates.RegistryEndpoint{
URL: u("https://127.0.0.1:6443/v2"),
Config: registries.RegistryConfig{
TLS: &registries.TLSConfig{
CAFile: "server-ca",
KeyFile: "client-key",
CertFile: "client-cert",
},
},
},
},
},
},

{
name: "wildcard config",
args: args{
Expand Down

0 comments on commit bba3e3c

Please sign in to comment.