Fixing various bugs related to windows.

This changes the crictl template for issues with the socket information. It also addresses a typo in the socket address. Last it makes tweaks to configuration that aren't required or had incorrect logic.

Signed-off-by: Jamie Phillips <jamie.phillips@suse.com>


spelling
This commit is contained in:
Jamie Phillips 2021-07-07 15:50:18 -04:00 committed by Brad Davidson
parent 4be912b9c5
commit a62d143936
5 changed files with 68 additions and 8 deletions

View File

@ -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"
}

View File

@ -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 {

View File

@ -15,7 +15,7 @@ import (
const (
unixPrefix = "unix://"
windowsPrefix = "npipe:"
windowsPrefix = "npipe://"
)
func Agent(config *config.Agent) error {

View File

@ -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()

View File

@ -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)
}
})
}
}