From 1255b64eedbecddc3cd6bf053e19e182ac3d2e89 Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Fri, 16 Jun 2023 23:16:37 -0700 Subject: [PATCH] Initial Windows port for K3s multi-exec binary (#7) --- main.go => main_linux.go | 3 ++ main_windows.go | 36 +++++++++++++++++++ .../windows/win-bridge/win-bridge_windows.go | 4 +-- .../win-overlay/win-overlay_windows.go | 4 +-- 4 files changed, 43 insertions(+), 4 deletions(-) rename main.go => main_linux.go (97%) create mode 100644 main_windows.go diff --git a/main.go b/main_linux.go similarity index 97% rename from main.go rename to main_linux.go index 03581550..33dc2834 100644 --- a/main.go +++ b/main_linux.go @@ -1,3 +1,6 @@ +//go:build linux +// +build linux + package main import ( diff --git a/main_windows.go b/main_windows.go new file mode 100644 index 00000000..7e41ec29 --- /dev/null +++ b/main_windows.go @@ -0,0 +1,36 @@ +//go:build windows +// +build windows + +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/docker/docker/pkg/reexec" + + "github.com/containernetworking/cni/pkg/version" + bv "github.com/containernetworking/plugins/pkg/utils/buildversion" + hostlocal "github.com/containernetworking/plugins/plugins/ipam/host-local" + "github.com/containernetworking/plugins/plugins/main/windows/win-bridge" + "github.com/containernetworking/plugins/plugins/main/windows/win-overlay" + "github.com/containernetworking/plugins/plugins/meta/flannel" +) + +func main() { + os.Args[0] = filepath.Base(os.Args[0]) + reexec.Register("flannel", flannel.Main) + reexec.Register("host-local", hostlocal.Main) + reexec.Register("win-bridge", winbridge.Main) + reexec.Register("win-overlay", winoverlay.Main) + reexec.Register("flannel.exe", flannel.Main) + reexec.Register("host-local.exe", hostlocal.Main) + reexec.Register("win-bridge.exe", winbridge.Main) + reexec.Register("win-overlay.exe", winoverlay.Main) + if !reexec.Init() { + _, _ = fmt.Fprintln(os.Stderr, bv.BuildString("plugins")) + _, _ = fmt.Fprintf(os.Stderr, "CNI protocol versions supported: %s\n", strings.Join(version.All.SupportedVersions(), ", ")) + } +} diff --git a/plugins/main/windows/win-bridge/win-bridge_windows.go b/plugins/main/windows/win-bridge/win-bridge_windows.go index 3e6de2b4..45649676 100644 --- a/plugins/main/windows/win-bridge/win-bridge_windows.go +++ b/plugins/main/windows/win-bridge/win-bridge_windows.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package winbridge import ( "encoding/json" @@ -214,6 +214,6 @@ func cmdCheck(_ *skel.CmdArgs) error { return nil } -func main() { +func Main() { skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("win-bridge")) } diff --git a/plugins/main/windows/win-overlay/win-overlay_windows.go b/plugins/main/windows/win-overlay/win-overlay_windows.go index 2df1b74b..e19a5f42 100644 --- a/plugins/main/windows/win-overlay/win-overlay_windows.go +++ b/plugins/main/windows/win-overlay/win-overlay_windows.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package main +package winoverlay import ( "encoding/json" @@ -287,6 +287,6 @@ func cmdCheck(_ *skel.CmdArgs) error { return nil } -func main() { +func Main() { skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("win-overlay")) }