Skip to content

Commit 1d6fd10

Browse files
committed
Fix containerd hosts.toml path on windows
Signed-off-by: Brad Davidson <[email protected]>
1 parent 41f0c6a commit 1d6fd10

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

pkg/agent/containerd/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func writeContainerdHosts(cfg *config.Node, containerdConfig templates.Container
5353

5454
// Write out new templates
5555
for host, config := range hosts {
56-
hostDir := filepath.Join(cfg.Containerd.Registry, host)
56+
hostDir := filepath.Join(cfg.Containerd.Registry, hostDirectory(host))
5757
hostsFile := filepath.Join(hostDir, "hosts.toml")
5858
hostsTemplate, err := templates.ParseHostsTemplateFromConfig(templates.HostsTomlTemplate, config)
5959
if err != nil {

pkg/agent/containerd/config_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const (
2727
runtimesPath = "/usr/local/nvidia/toolkit:/opt/kwasm/bin"
2828
)
2929

30+
// hostDirectory returns the name of the host dir for a given registry.
31+
// This is a no-op on linux, as all possible host:port strings are valid paths.
32+
func hostDirectory(host string) string {
33+
return host
34+
}
35+
3036
func getContainerdArgs(cfg *config.Node) []string {
3137
args := []string{
3238
"containerd",

pkg/agent/containerd/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ func Test_UnitGetHostConfigs(t *testing.T) {
15001500
for host, config := range got {
15011501
hostsTemplate, err := templates.ParseHostsTemplateFromConfig(templates.HostsTomlTemplate, config)
15021502
assert.NoError(t, err, "ParseHostTemplateFromConfig for %s", host)
1503-
t.Logf("%s/hosts.d/%s/hosts.toml\n%s", tempDir, host, hostsTemplate)
1503+
t.Logf("%s/hosts.d/%s/hosts.toml\n%s", tempDir, hostDirectory(host), hostsTemplate)
15041504
}
15051505

15061506
// Confirm that the main containerd config.toml renders properly

pkg/agent/containerd/config_windows.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package containerd
55

66
import (
7+
"net"
8+
79
"github.com/containerd/containerd"
810
"github.com/k3s-io/k3s/pkg/agent/templates"
911
"github.com/k3s-io/k3s/pkg/daemons/config"
@@ -13,6 +15,16 @@ import (
1315
"k8s.io/cri-client/pkg/util"
1416
)
1517

18+
// hostDirectory returns the name of the host dir for a given registry.
19+
// Colons are not allowed in windows paths, so convert `:port` to `_port_`.
20+
// Ref: https://github.com/containerd/containerd/blob/v1.7.25/remotes/docker/config/hosts.go#L291-L298
21+
func hostDirectory(host string) string {
22+
if host, port, err := net.SplitHostPort(host); err == nil && port != "" {
23+
return host + "_" + port + "_"
24+
}
25+
return host
26+
}
27+
1628
func getContainerdArgs(cfg *config.Node) []string {
1729
args := []string{
1830
"containerd",

0 commit comments

Comments
 (0)