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 a02d7fdb2ce..72f64aa9b8f 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/rlimit" "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) + 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/genericapiserver/genericapiserver.go b/pkg/genericapiserver/genericapiserver.go index dcc0e72739d..50c6b7335bc 100644 --- a/pkg/genericapiserver/genericapiserver.go +++ b/pkg/genericapiserver/genericapiserver.go @@ -48,6 +48,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" @@ -221,7 +222,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/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/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/runner.go b/pkg/util/async/runner.go similarity index 99% rename from pkg/util/runner.go rename to pkg/util/async/runner.go index 9e977ee1e98..924f1d168b9 100644 --- a/pkg/util/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/runner_test.go b/pkg/util/async/runner_test.go similarity index 98% rename from pkg/util/runner_test.go rename to pkg/util/async/runner_test.go index d05db5eddc9..b2f0b4c7385 100644 --- a/pkg/util/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/resource_container_linux.go b/pkg/util/resourcecontainer/resource_container_linux.go similarity index 87% rename from pkg/util/resource_container_linux.go rename to pkg/util/resourcecontainer/resource_container_linux.go index a844e4c1453..f7c2046a097 100644 --- a/pkg/util/resource_container_linux.go +++ b/pkg/util/resourcecontainer/resource_container_linux.go @@ -16,11 +16,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -package util +package resourcecontainer import ( "os" - "syscall" "github.com/opencontainers/runc/libcontainer/cgroups/fs" "github.com/opencontainers/runc/libcontainer/configs" @@ -43,7 +42,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/resource_container_unsupported.go b/pkg/util/resourcecontainer/resource_container_unsupported.go similarity index 85% rename from pkg/util/resource_container_unsupported.go rename to pkg/util/resourcecontainer/resource_container_unsupported.go index ba861b0dfe4..da471312651 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" @@ -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..d1ea8553415 --- /dev/null +++ b/pkg/util/rlimit/rlimit_linux.go @@ -0,0 +1,27 @@ +// +build linux + +/* +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. +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..25f57be2c31 --- /dev/null +++ b/pkg/util/rlimit/rlimit_unsupported.go @@ -0,0 +1,27 @@ +// +build !linux + +/* +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. +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") +} 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"