Skip to content

Commit

Permalink
Merge pull request kubernetes#26958 from resouer/util-line
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Refactoring runner resource container linedelimiter to it's own pkg

Continuing my work ref kubernetes#15634

Anyone is ok to review this fix.
  • Loading branch information
Kubernetes Submit Queue authored Aug 3, 2016
2 parents 48bd636 + e0ab760 commit 24216fe
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 25 deletions.
4 changes: 2 additions & 2 deletions cmd/kube-proxy/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ 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"
utiliptables "k8s.io/kubernetes/pkg/util/iptables"
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"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/genericapiserver/genericapiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pkg/kubectl/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/master/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/runner.go → pkg/util/async/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package async

import (
"sync"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/runner_test.go → pkg/util/async/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package async

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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})
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package resourcecontainer

import (
"errors"
Expand All @@ -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")
}
27 changes: 27 additions & 0 deletions pkg/util/rlimit/rlimit_linux.go
Original file line number Diff line number Diff line change
@@ -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})
}
27 changes: 27 additions & 0 deletions pkg/util/rlimit/rlimit_unsupported.go
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package strings

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package util
package strings

import (
"fmt"
Expand Down

0 comments on commit 24216fe

Please sign in to comment.