From 2346ccc63fcfe17f585b31d17854a5c7370a3e9d Mon Sep 17 00:00:00 2001 From: Knic Knic Date: Sat, 22 Feb 2020 10:39:33 -0800 Subject: [PATCH 1/2] get build on windows and get api_server to work --- pkg/agent/containerd/command.go | 15 +++++++++++++++ pkg/agent/containerd/command_windows.go | 7 +++++++ pkg/agent/containerd/containerd.go | 5 +---- pkg/agent/netpol/netpol_windows.go | 10 ++++++++++ pkg/agent/netpol/network_policy.go | 2 ++ pkg/agent/netpol/network_policy_controller.go | 2 ++ pkg/agent/netpol/utils.go | 2 ++ pkg/agent/syssetup/setup.go | 2 ++ pkg/agent/syssetup/setup_windows.go | 3 +++ pkg/passwd/passwd.go | 3 ++- pkg/rootless/mounts.go | 2 ++ pkg/rootless/rootless.go | 2 ++ pkg/rootless/rootless_windows.go | 9 +++++++++ pkg/rootlessports/controller.go | 2 ++ pkg/rootlessports/controller_windows.go | 10 ++++++++++ pkg/server/server.go | 5 +++-- pkg/util/file.go | 15 +++++++++++++++ pkg/util/file_windows.go | 13 +++++++++++++ 18 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 pkg/agent/containerd/command.go create mode 100644 pkg/agent/containerd/command_windows.go create mode 100644 pkg/agent/netpol/netpol_windows.go create mode 100644 pkg/agent/syssetup/setup_windows.go create mode 100644 pkg/rootless/rootless_windows.go create mode 100644 pkg/rootlessports/controller_windows.go create mode 100644 pkg/util/file.go create mode 100644 pkg/util/file_windows.go diff --git a/pkg/agent/containerd/command.go b/pkg/agent/containerd/command.go new file mode 100644 index 0000000000..07ead8e2a5 --- /dev/null +++ b/pkg/agent/containerd/command.go @@ -0,0 +1,15 @@ +// +build !windows + +package containerd + +import ( + "os/exec" + "syscall" +) + +func addDeathSig(cmd *exec.Cmd) { + // not supported in this OS + cmd.SysProcAttr = &syscall.SysProcAttr{ + Pdeathsig: syscall.SIGKILL, + } +} diff --git a/pkg/agent/containerd/command_windows.go b/pkg/agent/containerd/command_windows.go new file mode 100644 index 0000000000..f0bc94d859 --- /dev/null +++ b/pkg/agent/containerd/command_windows.go @@ -0,0 +1,7 @@ +package containerd + +import "os/exec" + +func addDeathSig(_ *exec.Cmd) { + // not supported in this OS +} diff --git a/pkg/agent/containerd/containerd.go b/pkg/agent/containerd/containerd.go index 9c71e88f0a..8627d6ecd9 100644 --- a/pkg/agent/containerd/containerd.go +++ b/pkg/agent/containerd/containerd.go @@ -8,7 +8,6 @@ import ( "os" "os/exec" "path/filepath" - "syscall" "time" "github.com/containerd/containerd" @@ -66,9 +65,7 @@ func Run(ctx context.Context, cfg *config.Node) error { cmd := exec.Command(args[0], args[1:]...) cmd.Stdout = stdOut cmd.Stderr = stdErr - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + addDeathSig(cmd) if err := cmd.Run(); err != nil { fmt.Fprintf(os.Stderr, "containerd: %s\n", err) } diff --git a/pkg/agent/netpol/netpol_windows.go b/pkg/agent/netpol/netpol_windows.go new file mode 100644 index 0000000000..177f582e7e --- /dev/null +++ b/pkg/agent/netpol/netpol_windows.go @@ -0,0 +1,10 @@ +package netpol + +import ( + "context" + daemonconfig "github.com/rancher/k3s/pkg/daemons/config" +) + +func Run(ctx context.Context, nodeConfig *daemonconfig.Node) error{ + panic("Netpol is not supported on windows ensure to pass --disable-network-policy") +} \ No newline at end of file diff --git a/pkg/agent/netpol/network_policy.go b/pkg/agent/netpol/network_policy.go index 497c96adca..a9ce693779 100644 --- a/pkg/agent/netpol/network_policy.go +++ b/pkg/agent/netpol/network_policy.go @@ -1,3 +1,5 @@ +// +build !windows + package netpol import ( diff --git a/pkg/agent/netpol/network_policy_controller.go b/pkg/agent/netpol/network_policy_controller.go index de65599575..111ef45ba9 100644 --- a/pkg/agent/netpol/network_policy_controller.go +++ b/pkg/agent/netpol/network_policy_controller.go @@ -1,6 +1,8 @@ // Apache License v2.0 (copyright Cloud Native Labs & Rancher Labs) // - modified from https://github.com/cloudnativelabs/kube-router/blob/d6f9f31a7b/pkg/controllers/netpol/network_policy_controller.go +// +build !windows + package netpol import ( diff --git a/pkg/agent/netpol/utils.go b/pkg/agent/netpol/utils.go index ba7729e5dd..1ba3c3cc58 100644 --- a/pkg/agent/netpol/utils.go +++ b/pkg/agent/netpol/utils.go @@ -1,6 +1,8 @@ // Apache License v2.0 (copyright Cloud Native Labs & Rancher Labs) // - modified from https://github.com/cloudnativelabs/kube-router/tree/d6f9f31a7b/pkg/utils +// +build !windows + package netpol import ( diff --git a/pkg/agent/syssetup/setup.go b/pkg/agent/syssetup/setup.go index d2955a9a87..91955ec328 100644 --- a/pkg/agent/syssetup/setup.go +++ b/pkg/agent/syssetup/setup.go @@ -1,3 +1,5 @@ +// +build !windows + package syssetup import ( diff --git a/pkg/agent/syssetup/setup_windows.go b/pkg/agent/syssetup/setup_windows.go new file mode 100644 index 0000000000..5880d44cfb --- /dev/null +++ b/pkg/agent/syssetup/setup_windows.go @@ -0,0 +1,3 @@ +package syssetup + +func Configure() {} \ No newline at end of file diff --git a/pkg/passwd/passwd.go b/pkg/passwd/passwd.go index cce8817260..5919e68df0 100644 --- a/pkg/passwd/passwd.go +++ b/pkg/passwd/passwd.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/rancher/k3s/pkg/token" + "github.com/rancher/k3s/pkg/util" ) type entry struct { @@ -141,7 +142,7 @@ func writePasswords(passwdFile string, records [][]string) error { } defer out.Close() - if err := out.Chmod(0600); err != nil { + if err := util.SetFileModeForFile(out, 0600); err != nil { return err } diff --git a/pkg/rootless/mounts.go b/pkg/rootless/mounts.go index 1c820e0f7b..984b3bd076 100644 --- a/pkg/rootless/mounts.go +++ b/pkg/rootless/mounts.go @@ -1,3 +1,5 @@ +// +build !windows + package rootless import ( diff --git a/pkg/rootless/rootless.go b/pkg/rootless/rootless.go index 32d8f8cd5a..0c0452e1a2 100644 --- a/pkg/rootless/rootless.go +++ b/pkg/rootless/rootless.go @@ -1,3 +1,5 @@ +// +build !windows + package rootless import ( diff --git a/pkg/rootless/rootless_windows.go b/pkg/rootless/rootless_windows.go new file mode 100644 index 0000000000..91ba40c00c --- /dev/null +++ b/pkg/rootless/rootless_windows.go @@ -0,0 +1,9 @@ +package rootless + +import ( +) + + +func Rootless(stateDir string) error { + panic("Rootless not supported on windows") +} diff --git a/pkg/rootlessports/controller.go b/pkg/rootlessports/controller.go index e5a4a7f7af..bd091b503a 100644 --- a/pkg/rootlessports/controller.go +++ b/pkg/rootlessports/controller.go @@ -1,3 +1,5 @@ +// +build !windows + package rootlessports import ( diff --git a/pkg/rootlessports/controller_windows.go b/pkg/rootlessports/controller_windows.go new file mode 100644 index 0000000000..819651cf03 --- /dev/null +++ b/pkg/rootlessports/controller_windows.go @@ -0,0 +1,10 @@ +package rootlessports + +import ( + "context" + coreClients "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1" +) + +func Register(ctx context.Context, serviceController coreClients.ServiceController, httpsPort int) error { + panic("Rootless is not supported on windows") +} \ No newline at end of file diff --git a/pkg/server/server.go b/pkg/server/server.go index e0ca1a8f9e..320d44e3b5 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -24,6 +24,7 @@ import ( "github.com/rancher/k3s/pkg/rootlessports" "github.com/rancher/k3s/pkg/servicelb" "github.com/rancher/k3s/pkg/static" + "github.com/rancher/k3s/pkg/util" v1 "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1" "github.com/rancher/wrangler/pkg/leader" "github.com/rancher/wrangler/pkg/resolvehome" @@ -263,12 +264,12 @@ func writeKubeConfig(certs string, config *Config) error { if config.ControlConfig.KubeConfigMode != "" { mode, err := strconv.ParseInt(config.ControlConfig.KubeConfigMode, 8, 0) if err == nil { - os.Chmod(kubeConfig, os.FileMode(mode)) + util.SetFileModeForPath(kubeConfig, os.FileMode(mode)) } else { logrus.Errorf("failed to set %s to mode %s: %v", kubeConfig, os.FileMode(mode), err) } } else { - os.Chmod(kubeConfig, os.FileMode(0600)) + util.SetFileModeForPath(kubeConfig, os.FileMode(0600)) } if kubeConfigSymlink != kubeConfig { diff --git a/pkg/util/file.go b/pkg/util/file.go new file mode 100644 index 0000000000..4a8866ad7e --- /dev/null +++ b/pkg/util/file.go @@ -0,0 +1,15 @@ +// +build !windows + +package util + +import ( + "os" +) + +func SetFileModeForPath(name string, mode os.FileMode) error { + return os.Chmod(name, mode) +} + +func SetFileModeForFile(file *os.File, mode os.FileMode) error { + return file.Chmod(mode) +} diff --git a/pkg/util/file_windows.go b/pkg/util/file_windows.go new file mode 100644 index 0000000000..3ca66e756a --- /dev/null +++ b/pkg/util/file_windows.go @@ -0,0 +1,13 @@ +package util + +import ( + "os" +) + +func SetFileModeForPath(name string, mode os.FileMode) error { + return nil +} + +func SetFileModeForFile(file *os.File, mode os.FileMode) error { + return nil +} From c2db115ec3441e63e82db90671f8cb6f0fb24fd3 Mon Sep 17 00:00:00 2001 From: Knic Knic Date: Sun, 23 Feb 2020 00:48:26 -0800 Subject: [PATCH 2/2] fix formatting --- pkg/agent/containerd/command.go | 30 ++++++++++++------------- pkg/agent/containerd/command_windows.go | 14 ++++++------ pkg/agent/netpol/netpol_windows.go | 20 ++++++++--------- pkg/agent/syssetup/setup_windows.go | 6 ++--- pkg/rootless/rootless_windows.go | 14 +++++------- pkg/rootlessports/controller_windows.go | 20 ++++++++--------- pkg/util/file.go | 30 ++++++++++++------------- pkg/util/file_windows.go | 26 ++++++++++----------- 8 files changed, 78 insertions(+), 82 deletions(-) diff --git a/pkg/agent/containerd/command.go b/pkg/agent/containerd/command.go index 07ead8e2a5..d5962f7661 100644 --- a/pkg/agent/containerd/command.go +++ b/pkg/agent/containerd/command.go @@ -1,15 +1,15 @@ -// +build !windows - -package containerd - -import ( - "os/exec" - "syscall" -) - -func addDeathSig(cmd *exec.Cmd) { - // not supported in this OS - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } -} +// +build !windows + +package containerd + +import ( + "os/exec" + "syscall" +) + +func addDeathSig(cmd *exec.Cmd) { + // not supported in this OS + cmd.SysProcAttr = &syscall.SysProcAttr{ + Pdeathsig: syscall.SIGKILL, + } +} diff --git a/pkg/agent/containerd/command_windows.go b/pkg/agent/containerd/command_windows.go index f0bc94d859..2658ff22f7 100644 --- a/pkg/agent/containerd/command_windows.go +++ b/pkg/agent/containerd/command_windows.go @@ -1,7 +1,7 @@ -package containerd - -import "os/exec" - -func addDeathSig(_ *exec.Cmd) { - // not supported in this OS -} +package containerd + +import "os/exec" + +func addDeathSig(_ *exec.Cmd) { + // not supported in this OS +} diff --git a/pkg/agent/netpol/netpol_windows.go b/pkg/agent/netpol/netpol_windows.go index 177f582e7e..0b67622d45 100644 --- a/pkg/agent/netpol/netpol_windows.go +++ b/pkg/agent/netpol/netpol_windows.go @@ -1,10 +1,10 @@ -package netpol - -import ( - "context" - daemonconfig "github.com/rancher/k3s/pkg/daemons/config" -) - -func Run(ctx context.Context, nodeConfig *daemonconfig.Node) error{ - panic("Netpol is not supported on windows ensure to pass --disable-network-policy") -} \ No newline at end of file +package netpol + +import ( + "context" + daemonconfig "github.com/rancher/k3s/pkg/daemons/config" +) + +func Run(ctx context.Context, nodeConfig *daemonconfig.Node) error { + panic("Netpol is not supported on windows ensure to pass --disable-network-policy") +} diff --git a/pkg/agent/syssetup/setup_windows.go b/pkg/agent/syssetup/setup_windows.go index 5880d44cfb..4053e2a901 100644 --- a/pkg/agent/syssetup/setup_windows.go +++ b/pkg/agent/syssetup/setup_windows.go @@ -1,3 +1,3 @@ -package syssetup - -func Configure() {} \ No newline at end of file +package syssetup + +func Configure() {} diff --git a/pkg/rootless/rootless_windows.go b/pkg/rootless/rootless_windows.go index 91ba40c00c..4431d0ab73 100644 --- a/pkg/rootless/rootless_windows.go +++ b/pkg/rootless/rootless_windows.go @@ -1,9 +1,5 @@ -package rootless - -import ( -) - - -func Rootless(stateDir string) error { - panic("Rootless not supported on windows") -} +package rootless + +func Rootless(stateDir string) error { + panic("Rootless not supported on windows") +} diff --git a/pkg/rootlessports/controller_windows.go b/pkg/rootlessports/controller_windows.go index 819651cf03..0e75c14dc8 100644 --- a/pkg/rootlessports/controller_windows.go +++ b/pkg/rootlessports/controller_windows.go @@ -1,10 +1,10 @@ -package rootlessports - -import ( - "context" - coreClients "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1" -) - -func Register(ctx context.Context, serviceController coreClients.ServiceController, httpsPort int) error { - panic("Rootless is not supported on windows") -} \ No newline at end of file +package rootlessports + +import ( + "context" + coreClients "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1" +) + +func Register(ctx context.Context, serviceController coreClients.ServiceController, httpsPort int) error { + panic("Rootless is not supported on windows") +} diff --git a/pkg/util/file.go b/pkg/util/file.go index 4a8866ad7e..3622c7f41e 100644 --- a/pkg/util/file.go +++ b/pkg/util/file.go @@ -1,15 +1,15 @@ -// +build !windows - -package util - -import ( - "os" -) - -func SetFileModeForPath(name string, mode os.FileMode) error { - return os.Chmod(name, mode) -} - -func SetFileModeForFile(file *os.File, mode os.FileMode) error { - return file.Chmod(mode) -} +// +build !windows + +package util + +import ( + "os" +) + +func SetFileModeForPath(name string, mode os.FileMode) error { + return os.Chmod(name, mode) +} + +func SetFileModeForFile(file *os.File, mode os.FileMode) error { + return file.Chmod(mode) +} diff --git a/pkg/util/file_windows.go b/pkg/util/file_windows.go index 3ca66e756a..2dbc4c98ee 100644 --- a/pkg/util/file_windows.go +++ b/pkg/util/file_windows.go @@ -1,13 +1,13 @@ -package util - -import ( - "os" -) - -func SetFileModeForPath(name string, mode os.FileMode) error { - return nil -} - -func SetFileModeForFile(file *os.File, mode os.FileMode) error { - return nil -} +package util + +import ( + "os" +) + +func SetFileModeForPath(name string, mode os.FileMode) error { + return nil +} + +func SetFileModeForFile(file *os.File, mode os.FileMode) error { + return nil +}