Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for binaries to run as Windows services #60144

Merged
merged 2 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Godeps/LICENSES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions cmd/kube-proxy/app/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,47 @@ go_library(
"server.go",
] + select({
"@io_bazel_rules_go//go/platform:android": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:darwin": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:linux": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:nacl": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:plan9": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:solaris": [
"init_others.go",
"server_others.go",
],
"@io_bazel_rules_go//go/platform:windows": [
"init_windows.go",
"server_windows.go",
],
"//conditions:default": [],
Expand Down Expand Up @@ -177,6 +188,7 @@ go_library(
"//pkg/proxy/winkernel:go_default_library",
"//pkg/proxy/winuserspace:go_default_library",
"//pkg/util/netsh:go_default_library",
"//pkg/windows/service:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
],
Expand Down
30 changes: 30 additions & 0 deletions cmd/kube-proxy/app/init_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// +build !windows

/*
Copyright 2018 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package app

import (
"github.com/spf13/pflag"
)

func initForOS(service bool) error {
return nil
}

func (o *Options) addOSFlags(fs *pflag.FlagSet) {
}
40 changes: 40 additions & 0 deletions cmd/kube-proxy/app/init_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// +build windows

/*
Copyright 2018 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package app

import (
"k8s.io/kubernetes/pkg/windows/service"

"github.com/spf13/pflag"
)

const (
serviceName = "kube-proxy"
)

func initForOS(windowsService bool) error {
if windowsService {
return service.InitService(serviceName)
}
return nil
}

func (o *Options) addOSFlags(fs *pflag.FlagSet) {
fs.BoolVar(&o.WindowsService, "windows-service", o.WindowsService, "Enable Windows Service Control Manager API integration")
}
8 changes: 8 additions & 0 deletions cmd/kube-proxy/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ type Options struct {
CleanupAndExit bool
// CleanupIPVS, when true, makes the proxy server clean up ipvs rules before running.
CleanupIPVS bool
// WindowsService should be set to true if kube-proxy is running as a service on Windows.
// Its corresponding flag only gets registered in Windows builds
WindowsService bool
// config is the proxy server's configuration object.
config *kubeproxyconfig.KubeProxyConfiguration

Expand All @@ -119,6 +122,7 @@ type Options struct {

// AddFlags adds flags to fs and binds them to options.
func (o *Options) AddFlags(fs *pflag.FlagSet) {
o.addOSFlags(fs)
fs.StringVar(&o.ConfigFile, "config", o.ConfigFile, "The path to the configuration file.")
fs.StringVar(&o.WriteConfigTo, "write-config-to", o.WriteConfigTo, "If set, write the default configuration values to this file and exit.")
fs.BoolVar(&o.CleanupAndExit, "cleanup-iptables", o.CleanupAndExit, "If true cleanup iptables and ipvs rules and exit.")
Expand Down Expand Up @@ -344,6 +348,10 @@ with the apiserver API to configure the proxy.`,
verflag.PrintAndExitIfRequested()
utilflag.PrintFlags(cmd.Flags())

if err := initForOS(opts.WindowsService); err != nil {
glog.Fatalf("failed OS init: %v", err)
}

cmdutil.CheckErr(opts.Complete())
cmdutil.CheckErr(opts.Validate(args))
cmdutil.CheckErr(opts.Run())
Expand Down
14 changes: 14 additions & 0 deletions cmd/kubelet/app/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,47 @@ go_library(
"server.go",
] + select({
"@io_bazel_rules_go//go/platform:android": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:darwin": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:linux": [
"init_others.go",
"server_linux.go",
],
"@io_bazel_rules_go//go/platform:nacl": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:plan9": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:solaris": [
"init_others.go",
"server_unsupported.go",
],
"@io_bazel_rules_go//go/platform:windows": [
"init_windows.go",
"server_unsupported.go",
],
"//conditions:default": [],
Expand Down Expand Up @@ -162,6 +173,9 @@ go_library(
"@io_bazel_rules_go//go/platform:linux": [
"//vendor/golang.org/x/exp/inotify:go_default_library",
],
"@io_bazel_rules_go//go/platform:windows": [
"//pkg/windows/service:go_default_library",
],
"//conditions:default": [],
}),
)
Expand Down
23 changes: 23 additions & 0 deletions cmd/kubelet/app/init_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build !windows

/*
Copyright 2018 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package app

func initForOS(service bool) error {
return nil
}
34 changes: 34 additions & 0 deletions cmd/kubelet/app/init_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build windows

/*
Copyright 2018 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package app

import (
"k8s.io/kubernetes/pkg/windows/service"
)

const (
serviceName = "kubelet"
)

func initForOS(windowsService bool) error {
if windowsService {
return service.InitService(serviceName)
}
return nil
}
11 changes: 11 additions & 0 deletions cmd/kubelet/app/options/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,47 @@ go_library(
] + select({
"@io_bazel_rules_go//go/platform:android": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:darwin": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:dragonfly": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:freebsd": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:linux": [
"globalflags_linux.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:nacl": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:netbsd": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:openbsd": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:plan9": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:solaris": [
"globalflags_other.go",
"osflags_others.go",
],
"@io_bazel_rules_go//go/platform:windows": [
"globalflags_other.go",
"osflags_windows.go",
],
"//conditions:default": [],
}),
Expand Down
5 changes: 5 additions & 0 deletions cmd/kubelet/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ type KubeletFlags struct {
// cAdvisorPort is the port of the localhost cAdvisor endpoint (set to 0 to disable)
CAdvisorPort int32

// WindowsService should be set to true if kubelet is running as a service on Windows.
// Its corresponding flag only gets registered in Windows builds.
WindowsService bool

// EXPERIMENTAL FLAGS
// Whitelist of unsafe sysctls or sysctl patterns (ending in *).
// +optional
Expand Down Expand Up @@ -329,6 +333,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
// AddFlags adds flags for a specific KubeletFlags to the specified FlagSet
func (f *KubeletFlags) AddFlags(fs *pflag.FlagSet) {
f.ContainerRuntimeOptions.AddFlags(fs)
f.addOSFlags(fs)

fs.StringVar(&f.KubeletConfigFile, "config", f.KubeletConfigFile, "The Kubelet will load its initial configuration from this file. The path may be absolute or relative; relative paths start at the Kubelet's current working directory. Omit this flag to use the built-in default configuration values. Command-line flags override configuration from this file.")
fs.StringVar(&f.KubeConfig, "kubeconfig", f.KubeConfig, "Path to a kubeconfig file, specifying how to connect to the API server. Providing --kubeconfig enables API server mode, omitting --kubeconfig enables standalone mode.")
Expand Down
Loading