From 15d0f5cfd58fab4b78db4ae38b880ff253822513 Mon Sep 17 00:00:00 2001 From: Harry Zhang Date: Tue, 7 Jun 2016 17:24:03 +0800 Subject: [PATCH 1/4] Move linedelimiter to it's own pkg Refactoring resource container --- cmd/kube-proxy/app/server.go | 4 ++-- cmd/kubelet/app/server.go | 4 ++-- pkg/kubectl/cmd/cmd_test.go | 4 ++-- pkg/util/{ => resourcecontainer}/resource_container_linux.go | 2 +- .../{ => resourcecontainer}/resource_container_unsupported.go | 2 +- pkg/util/{ => strings}/line_delimiter.go | 2 +- pkg/util/{ => strings}/line_delimiter_test.go | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename pkg/util/{ => resourcecontainer}/resource_container_linux.go (98%) rename pkg/util/{ => resourcecontainer}/resource_container_unsupported.go (97%) rename pkg/util/{ => strings}/line_delimiter.go (99%) rename pkg/util/{ => strings}/line_delimiter_test.go (98%) diff --git a/cmd/kube-proxy/app/server.go b/cmd/kube-proxy/app/server.go index f618c209fd5..261181f2acc 100644 --- a/cmd/kube-proxy/app/server.go +++ b/cmd/kube-proxy/app/server.go @@ -39,7 +39,6 @@ import ( "k8s.io/kubernetes/pkg/proxy/iptables" "k8s.io/kubernetes/pkg/proxy/userspace" "k8s.io/kubernetes/pkg/types" - "k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util/configz" utildbus "k8s.io/kubernetes/pkg/util/dbus" "k8s.io/kubernetes/pkg/util/exec" @@ -47,6 +46,7 @@ import ( utilnet "k8s.io/kubernetes/pkg/util/net" nodeutil "k8s.io/kubernetes/pkg/util/node" "k8s.io/kubernetes/pkg/util/oom" + "k8s.io/kubernetes/pkg/util/resourcecontainer" "k8s.io/kubernetes/pkg/util/wait" "github.com/golang/glog" @@ -158,7 +158,7 @@ func NewProxyServerDefault(config *options.ProxyServerConfig) (*ProxyServer, err if config.ResourceContainer != "" { // Run in its own container. - if err := util.RunInResourceContainer(config.ResourceContainer); err != nil { + if err := resourcecontainer.RunInResourceContainer(config.ResourceContainer); err != nil { glog.Warningf("Failed to start in resource-only container %q: %v", config.ResourceContainer, err) } else { glog.V(2).Infof("Running in resource-only container %q", config.ResourceContainer) diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index cece8629744..b493d9c773f 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -62,7 +62,6 @@ import ( "k8s.io/kubernetes/pkg/kubelet/network" "k8s.io/kubernetes/pkg/kubelet/server" kubetypes "k8s.io/kubernetes/pkg/kubelet/types" - "k8s.io/kubernetes/pkg/util" utilconfig "k8s.io/kubernetes/pkg/util/config" "k8s.io/kubernetes/pkg/util/configz" "k8s.io/kubernetes/pkg/util/crypto" @@ -71,6 +70,7 @@ import ( "k8s.io/kubernetes/pkg/util/mount" nodeutil "k8s.io/kubernetes/pkg/util/node" "k8s.io/kubernetes/pkg/util/oom" + "k8s.io/kubernetes/pkg/util/resourcecontainer" "k8s.io/kubernetes/pkg/util/runtime" "k8s.io/kubernetes/pkg/util/wait" "k8s.io/kubernetes/pkg/version" @@ -688,7 +688,7 @@ func RunKubelet(kcfg *KubeletConfig) error { return fmt.Errorf("failed to create kubelet: %v", err) } - util.ApplyRLimitForSelf(kcfg.MaxOpenFiles) + resourcecontainer.ApplyRLimitForSelf(kcfg.MaxOpenFiles) // TODO(dawnchen): remove this once we deprecated old debian containervm images. // This is a workaround for issue: https://github.com/opencontainers/runc/issues/726 diff --git a/pkg/kubectl/cmd/cmd_test.go b/pkg/kubectl/cmd/cmd_test.go index af5cdad1eee..05b8476eb3a 100644 --- a/pkg/kubectl/cmd/cmd_test.go +++ b/pkg/kubectl/cmd/cmd_test.go @@ -41,7 +41,7 @@ import ( "k8s.io/kubernetes/pkg/kubectl/resource" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime/serializer" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/strings" ) func initTestErrorHandler(t *testing.T) { @@ -801,7 +801,7 @@ func Example_printServiceWithNamespacesAndLabels() { Status: api.ServiceStatus{}, }}, } - ld := util.NewLineDelimiter(os.Stdout, "|") + ld := strings.NewLineDelimiter(os.Stdout, "|") defer ld.Flush() mapper, _ := f.Object(false) diff --git a/pkg/util/resource_container_linux.go b/pkg/util/resourcecontainer/resource_container_linux.go similarity index 98% rename from pkg/util/resource_container_linux.go rename to pkg/util/resourcecontainer/resource_container_linux.go index a844e4c1453..6ea75b2eb3a 100644 --- a/pkg/util/resource_container_linux.go +++ b/pkg/util/resourcecontainer/resource_container_linux.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package resourcecontainer import ( "os" diff --git a/pkg/util/resource_container_unsupported.go b/pkg/util/resourcecontainer/resource_container_unsupported.go similarity index 97% rename from pkg/util/resource_container_unsupported.go rename to pkg/util/resourcecontainer/resource_container_unsupported.go index ba861b0dfe4..0bfb79bb591 100644 --- a/pkg/util/resource_container_unsupported.go +++ b/pkg/util/resourcecontainer/resource_container_unsupported.go @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package resourcecontainer import ( "errors" diff --git a/pkg/util/line_delimiter.go b/pkg/util/strings/line_delimiter.go similarity index 99% rename from pkg/util/line_delimiter.go rename to pkg/util/strings/line_delimiter.go index 9f64260c862..56e38302a14 100644 --- a/pkg/util/line_delimiter.go +++ b/pkg/util/strings/line_delimiter.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package strings import ( "bytes" diff --git a/pkg/util/line_delimiter_test.go b/pkg/util/strings/line_delimiter_test.go similarity index 98% rename from pkg/util/line_delimiter_test.go rename to pkg/util/strings/line_delimiter_test.go index a3a036c5c68..15bee165b59 100644 --- a/pkg/util/line_delimiter_test.go +++ b/pkg/util/strings/line_delimiter_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package strings import ( "fmt" From b7a387c8f586bf9a08ba45aa1f3f6bcabd6a3e5b Mon Sep 17 00:00:00 2001 From: harry zhang Date: Tue, 7 Jun 2016 08:14:29 -0400 Subject: [PATCH 2/4] Refactoring runner --- pkg/util/{ => async}/runner.go | 0 pkg/util/{ => async}/runner_test.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename pkg/util/{ => async}/runner.go (100%) rename pkg/util/{ => async}/runner_test.go (100%) diff --git a/pkg/util/runner.go b/pkg/util/async/runner.go similarity index 100% rename from pkg/util/runner.go rename to pkg/util/async/runner.go diff --git a/pkg/util/runner_test.go b/pkg/util/async/runner_test.go similarity index 100% rename from pkg/util/runner_test.go rename to pkg/util/async/runner_test.go From 94c6994ab33d66ad9516bf54f91fda2569622b38 Mon Sep 17 00:00:00 2001 From: Harry Zhang Date: Sun, 3 Jul 2016 07:18:03 -0400 Subject: [PATCH 3/4] Move rlimit to it's own pkg --- cmd/kubelet/app/server.go | 3 ++- .../resource_container_linux.go | 4 --- .../resource_container_unsupported.go | 4 --- pkg/util/rlimit/rlimit_linux.go | 27 +++++++++++++++++++ pkg/util/rlimit/rlimit_unsupported.go | 27 +++++++++++++++++++ 5 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 pkg/util/rlimit/rlimit_linux.go create mode 100644 pkg/util/rlimit/rlimit_unsupported.go diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index b493d9c773f..10011075255 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -71,6 +71,7 @@ import ( nodeutil "k8s.io/kubernetes/pkg/util/node" "k8s.io/kubernetes/pkg/util/oom" "k8s.io/kubernetes/pkg/util/resourcecontainer" + "k8s.io/kubernetes/pkg/util/rlimit" "k8s.io/kubernetes/pkg/util/runtime" "k8s.io/kubernetes/pkg/util/wait" "k8s.io/kubernetes/pkg/version" @@ -688,7 +689,7 @@ func RunKubelet(kcfg *KubeletConfig) error { return fmt.Errorf("failed to create kubelet: %v", err) } - resourcecontainer.ApplyRLimitForSelf(kcfg.MaxOpenFiles) + rlimit.RlimitNumFiles(kcfg.MaxOpenFiles) // TODO(dawnchen): remove this once we deprecated old debian containervm images. // This is a workaround for issue: https://github.com/opencontainers/runc/issues/726 diff --git a/pkg/util/resourcecontainer/resource_container_linux.go b/pkg/util/resourcecontainer/resource_container_linux.go index 6ea75b2eb3a..dc8e1909a94 100644 --- a/pkg/util/resourcecontainer/resource_container_linux.go +++ b/pkg/util/resourcecontainer/resource_container_linux.go @@ -43,7 +43,3 @@ func RunInResourceContainer(containerName string) error { return manager.Apply(os.Getpid()) } - -func ApplyRLimitForSelf(maxOpenFiles uint64) { - syscall.Setrlimit(syscall.RLIMIT_NOFILE, &syscall.Rlimit{Max: maxOpenFiles, Cur: maxOpenFiles}) -} diff --git a/pkg/util/resourcecontainer/resource_container_unsupported.go b/pkg/util/resourcecontainer/resource_container_unsupported.go index 0bfb79bb591..da471312651 100644 --- a/pkg/util/resourcecontainer/resource_container_unsupported.go +++ b/pkg/util/resourcecontainer/resource_container_unsupported.go @@ -25,7 +25,3 @@ import ( func RunInResourceContainer(containerName string) error { return errors.New("resource-only containers unsupported in this platform") } - -func ApplyRLimitForSelf(maxOpenFiles uint64) error { - return errors.New("SetRLimit unsupported in this platform") -} diff --git a/pkg/util/rlimit/rlimit_linux.go b/pkg/util/rlimit/rlimit_linux.go new file mode 100644 index 00000000000..c7d383d8090 --- /dev/null +++ b/pkg/util/rlimit/rlimit_linux.go @@ -0,0 +1,27 @@ +// +build linux + +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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 rlimit + +import ( + "syscall" +) + +func RlimitNumFiles(maxOpenFiles uint64) { + syscall.Setrlimit(syscall.RLIMIT_NOFILE, &syscall.Rlimit{Max: maxOpenFiles, Cur: maxOpenFiles}) +} diff --git a/pkg/util/rlimit/rlimit_unsupported.go b/pkg/util/rlimit/rlimit_unsupported.go new file mode 100644 index 00000000000..6759681b36f --- /dev/null +++ b/pkg/util/rlimit/rlimit_unsupported.go @@ -0,0 +1,27 @@ +// +build !linux + +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +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 rlimit + +import ( + "errors" +) + +func RlimitNumFiles(maxOpenFiles uint64) error { + return errors.New("SetRLimit unsupported in this platform") +} From e0ab76019e958ee6804db7ceaf986f9d4b705cef Mon Sep 17 00:00:00 2001 From: Harry Zhang Date: Sun, 3 Jul 2016 09:02:11 -0400 Subject: [PATCH 4/4] Rename runnter pkg name --- cmd/kubelet/app/server.go | 1 - pkg/genericapiserver/genericapiserver.go | 3 ++- pkg/master/controller.go | 6 +++--- pkg/util/async/runner.go | 2 +- pkg/util/async/runner_test.go | 2 +- pkg/util/resourcecontainer/resource_container_linux.go | 1 - pkg/util/rlimit/rlimit_linux.go | 2 +- pkg/util/rlimit/rlimit_unsupported.go | 2 +- 8 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index 10011075255..6059eb08352 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -70,7 +70,6 @@ import ( "k8s.io/kubernetes/pkg/util/mount" nodeutil "k8s.io/kubernetes/pkg/util/node" "k8s.io/kubernetes/pkg/util/oom" - "k8s.io/kubernetes/pkg/util/resourcecontainer" "k8s.io/kubernetes/pkg/util/rlimit" "k8s.io/kubernetes/pkg/util/runtime" "k8s.io/kubernetes/pkg/util/wait" diff --git a/pkg/genericapiserver/genericapiserver.go b/pkg/genericapiserver/genericapiserver.go index 9b0cc5baf23..849f483a2f2 100644 --- a/pkg/genericapiserver/genericapiserver.go +++ b/pkg/genericapiserver/genericapiserver.go @@ -47,6 +47,7 @@ import ( "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/ui" "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/async" "k8s.io/kubernetes/pkg/util/crypto" utilnet "k8s.io/kubernetes/pkg/util/net" utilruntime "k8s.io/kubernetes/pkg/util/runtime" @@ -220,7 +221,7 @@ type GenericAPIServer struct { PublicReadWritePort int ServiceReadWriteIP net.IP ServiceReadWritePort int - masterServices *util.Runner + masterServices *async.Runner ExtraServicePorts []api.ServicePort ExtraEndpointPorts []api.EndpointPort diff --git a/pkg/master/controller.go b/pkg/master/controller.go index 6fad85f94c0..fdf5e92b0c3 100644 --- a/pkg/master/controller.go +++ b/pkg/master/controller.go @@ -31,7 +31,7 @@ import ( "k8s.io/kubernetes/pkg/registry/service" servicecontroller "k8s.io/kubernetes/pkg/registry/service/ipallocator/controller" portallocatorcontroller "k8s.io/kubernetes/pkg/registry/service/portallocator/controller" - "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/pkg/util/async" "k8s.io/kubernetes/pkg/util/intstr" utilnet "k8s.io/kubernetes/pkg/util/net" "k8s.io/kubernetes/pkg/util/runtime" @@ -68,7 +68,7 @@ type Controller struct { PublicServicePort int KubernetesServiceNodePort int - runner *util.Runner + runner *async.Runner } // Start begins the core controller loops that must exist for bootstrapping @@ -95,7 +95,7 @@ func (c *Controller) Start() { glog.Errorf("Unable to perform initial Kubernetes service initialization: %v", err) } - c.runner = util.NewRunner(c.RunKubernetesNamespaces, c.RunKubernetesService, repairClusterIPs.RunUntil, repairNodePorts.RunUntil) + c.runner = async.NewRunner(c.RunKubernetesNamespaces, c.RunKubernetesService, repairClusterIPs.RunUntil, repairNodePorts.RunUntil) c.runner.Start() } diff --git a/pkg/util/async/runner.go b/pkg/util/async/runner.go index 9e977ee1e98..924f1d168b9 100644 --- a/pkg/util/async/runner.go +++ b/pkg/util/async/runner.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package async import ( "sync" diff --git a/pkg/util/async/runner_test.go b/pkg/util/async/runner_test.go index d05db5eddc9..b2f0b4c7385 100644 --- a/pkg/util/async/runner_test.go +++ b/pkg/util/async/runner_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package async import ( "fmt" diff --git a/pkg/util/resourcecontainer/resource_container_linux.go b/pkg/util/resourcecontainer/resource_container_linux.go index dc8e1909a94..f7c2046a097 100644 --- a/pkg/util/resourcecontainer/resource_container_linux.go +++ b/pkg/util/resourcecontainer/resource_container_linux.go @@ -20,7 +20,6 @@ package resourcecontainer import ( "os" - "syscall" "github.com/opencontainers/runc/libcontainer/cgroups/fs" "github.com/opencontainers/runc/libcontainer/configs" diff --git a/pkg/util/rlimit/rlimit_linux.go b/pkg/util/rlimit/rlimit_linux.go index c7d383d8090..d1ea8553415 100644 --- a/pkg/util/rlimit/rlimit_linux.go +++ b/pkg/util/rlimit/rlimit_linux.go @@ -1,7 +1,7 @@ // +build linux /* -Copyright 2016 The Kubernetes Authors All rights reserved. +Copyright 2016 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. diff --git a/pkg/util/rlimit/rlimit_unsupported.go b/pkg/util/rlimit/rlimit_unsupported.go index 6759681b36f..25f57be2c31 100644 --- a/pkg/util/rlimit/rlimit_unsupported.go +++ b/pkg/util/rlimit/rlimit_unsupported.go @@ -1,7 +1,7 @@ // +build !linux /* -Copyright 2016 The Kubernetes Authors All rights reserved. +Copyright 2016 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.