diff --git a/pkg/agent/config/config_windows.go b/pkg/agent/config/config_windows.go index a604ca134d..a9534ccfc5 100644 --- a/pkg/agent/config/config_windows.go +++ b/pkg/agent/config/config_windows.go @@ -10,5 +10,5 @@ import ( func applyContainerdStateAndAddress(nodeConfig *config.Node) { nodeConfig.Containerd.State = filepath.Join(nodeConfig.Containerd.Root, "state") - nodeConfig.Containerd.Address = "npipe://///./pipe/containerd-containerd" + nodeConfig.Containerd.Address = "npipe:////./pipe/containerd-containerd" } diff --git a/pkg/agent/templates/templates_windows.go b/pkg/agent/templates/templates_windows.go index 05ab122232..5d70bd98ae 100644 --- a/pkg/agent/templates/templates_windows.go +++ b/pkg/agent/templates/templates_windows.go @@ -4,6 +4,7 @@ package templates import ( "bytes" + "net/url" "strings" "text/template" ) @@ -18,7 +19,7 @@ required_plugins = [] oom_score = 0 [grpc] - address = "{{ replace .NodeConfig.Containerd.Address }}" + address = "{{ deschemify .NodeConfig.Containerd.Address }}" tcp_address = "" tcp_tls_cert = "" tcp_tls_key = "" @@ -165,6 +166,16 @@ func ParseTemplateFromConfig(templateBuffer string, config interface{}) (string, "replace": func(s string) string { return strings.ReplaceAll(s, "\\", "\\\\") }, + "deschemify": func(s string) string { + if strings.HasPrefix(s, "npipe:") { + u, err := url.Parse(s) + if err != nil { + return "" + } + return u.Path + } + return s + }, } t := template.Must(template.New("compiled_template").Funcs(funcs).Parse(templateBuffer)) if err := t.Execute(out, config); err != nil { diff --git a/pkg/daemons/agent/agent.go b/pkg/daemons/agent/agent.go index 38f22a7e65..a03f4d1520 100644 --- a/pkg/daemons/agent/agent.go +++ b/pkg/daemons/agent/agent.go @@ -15,7 +15,7 @@ import ( const ( unixPrefix = "unix://" - windowsPrefix = "npipe:" + windowsPrefix = "npipe://" ) func Agent(config *config.Agent) error { diff --git a/pkg/daemons/agent/agent_windows.go b/pkg/daemons/agent/agent_windows.go index 7d5f4af26f..87e7d9d451 100644 --- a/pkg/daemons/agent/agent_windows.go +++ b/pkg/daemons/agent/agent_windows.go @@ -16,8 +16,12 @@ import ( "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes" ) +var ( + NetworkName string = "vxlan0" +) + func checkRuntimeEndpoint(cfg *config.Agent, argsMap map[string]string) { - if strings.HasPrefix(argsMap["container-runtime-endpoint"], windowsPrefix) { + if strings.HasPrefix(cfg.RuntimeSocket, windowsPrefix) { argsMap["container-runtime-endpoint"] = cfg.RuntimeSocket } else { argsMap["container-runtime-endpoint"] = windowsPrefix + cfg.RuntimeSocket @@ -35,9 +39,7 @@ func kubeProxyArgs(cfg *config.Agent) map[string]string { argsMap["hostname-override"] = cfg.NodeName } - argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "WinOverlay=true") - - if sourceVip := waitForManagementIp("vxlan0"); sourceVip != "" { + if sourceVip := waitForManagementIp(NetworkName); sourceVip != "" { argsMap["source-vip"] = sourceVip } @@ -133,7 +135,7 @@ func waitForManagementIp(networkName string) string { for range time.Tick(time.Second * 5) { network, err := hcsshim.GetHNSEndpointByName(networkName) if err != nil { - logrus.WithError(err).Warning("can't find %s, retrying", networkName) + logrus.WithError(err).Warning("can't find HNS endpoint for network, retrying", networkName) continue } return network.IPAddress.String() diff --git a/pkg/daemons/agent/agent_windows_test.go b/pkg/daemons/agent/agent_windows_test.go new file mode 100644 index 0000000000..d77b3506b9 --- /dev/null +++ b/pkg/daemons/agent/agent_windows_test.go @@ -0,0 +1,47 @@ +// +build windows + +package agent + +import ( + "testing" + + "github.com/rancher/k3s/pkg/daemons/config" +) + +func TestCheckRuntimeEndpoint(t *testing.T) { + type args struct { + cfg *config.Agent + } + tests := []struct { + name string + args args + want string + }{ + { + name: "Runtime endpoint unaltered", + args: args{ + cfg: &config.Agent{RuntimeSocket: "npipe:////./pipe/containerd-containerd"}, + }, + want: "npipe:////./pipe/containerd-containerd", + }, + { + name: "Runtime endpoint altered", + args: args{ + cfg: &config.Agent{RuntimeSocket: "//./pipe/containerd-containerd"}, + }, + want: "npipe:////./pipe/containerd-containerd", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + argsMap := map[string]string{} + checkRuntimeEndpoint(tt.args.cfg, argsMap) + if argsMap["container-runtime-endpoint"] != tt.want { + got := argsMap["container-runtime-endpoint"] + t.Errorf("error, input was " + tt.args.cfg.RuntimeSocket + " should be " + tt.want + ", but got " + got) + } + }) + + } +}