From e41e4010e500315547b1380bdfac49c442272785 Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Tue, 15 Nov 2022 17:49:18 +0100 Subject: [PATCH] Revert "Remove stuff which belongs in the windows executor implementation" This reverts commit 1bc0684fb76c7decb78cb1e6980aa5eb4144f99b. Signed-off-by: Manuel Buil --- go.mod | 2 +- pkg/daemons/agent/agent_windows.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9957c6cb97..2e9f7812a4 100644 --- a/go.mod +++ b/go.mod @@ -66,6 +66,7 @@ replace ( ) require ( + github.com/Microsoft/hcsshim v0.9.2 github.com/Mirantis/cri-dockerd v0.0.0-00010101000000-000000000000 github.com/cloudnativelabs/kube-router v1.3.2 github.com/containerd/cgroups v1.0.3 @@ -159,7 +160,6 @@ require ( github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab // indirect github.com/MakeNowJust/heredoc v1.0.0 // indirect github.com/Microsoft/go-winio v0.5.2 // indirect - github.com/Microsoft/hcsshim v0.9.2 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect diff --git a/pkg/daemons/agent/agent_windows.go b/pkg/daemons/agent/agent_windows.go index 36a5f50565..5d1c593840 100644 --- a/pkg/daemons/agent/agent_windows.go +++ b/pkg/daemons/agent/agent_windows.go @@ -7,7 +7,9 @@ import ( "os" "path/filepath" "strings" + "time" + "github.com/Microsoft/hcsshim" "github.com/k3s-io/k3s/pkg/daemons/config" "github.com/k3s-io/k3s/pkg/util" "github.com/sirupsen/logrus" @@ -15,6 +17,9 @@ import ( "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes" ) +// NetworkName may be overridden at runtime in downstream projects +var NetworkName = "vxlan0" + const ( socketPrefix = "npipe://" ) @@ -35,6 +40,10 @@ func kubeProxyArgs(cfg *config.Agent) map[string]string { argsMap["hostname-override"] = cfg.NodeName } + if sourceVip := waitForManagementIP(NetworkName); sourceVip != "" { + argsMap["source-vip"] = sourceVip + } + return argsMap } @@ -124,3 +133,18 @@ func kubeletArgs(cfg *config.Agent) map[string]string { } return argsMap } + +func waitForManagementIP(networkName string) string { + for range time.Tick(time.Second * 5) { + network, err := hcsshim.GetHNSNetworkByName(networkName) + if err != nil { + logrus.WithError(err).Warning("can't find HNS network, retrying", networkName) + continue + } + if network.ManagementIP == "" { + continue + } + return network.ManagementIP + } + return "" +}