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

kubelet: Optionally, have kubelet exit if lock file contention is observed, using --exit-on-lock-contention flag #25596

Merged
merged 1 commit into from
May 20, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/kubelet/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func NewKubeletServer() *KubeletServer {
NodeLabels: make(map[string]string),
OOMScoreAdj: int32(qos.KubeletOOMScoreAdj),
LockFilePath: "",
ExitOnLockContention: false,
PodInfraContainerImage: GetDefaultPodInfraContainerImage(),
Port: ports.KubeletPort,
ReadOnlyPort: ports.KubeletReadOnlyPort,
Expand Down Expand Up @@ -220,6 +221,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.CgroupRoot, "cgroup-root", s.CgroupRoot, "Optional root cgroup to use for pods. This is handled by the container runtime on a best effort basis. Default: '', which means use the container runtime default.")
fs.StringVar(&s.ContainerRuntime, "container-runtime", s.ContainerRuntime, "The container runtime to use. Possible values: 'docker', 'rkt'. Default: 'docker'.")
fs.StringVar(&s.LockFilePath, "lock-file", s.LockFilePath, "<Warning: Alpha feature> The path to file for kubelet to use as a lock file.")
fs.BoolVar(&s.ExitOnLockContention, "exit-on-lock-contention", s.ExitOnLockContention, "Whether kubelet should exit upon lock-file contention.")
fs.StringVar(&s.RktPath, "rkt-path", s.RktPath, "Path of rkt binary. Leave empty to use the first rkt in $PATH. Only used if --container-runtime='rkt'.")
fs.StringVar(&s.RktAPIEndpoint, "rkt-api-endpoint", s.RktAPIEndpoint, "The endpoint of the rkt API service to communicate with. Only used if --container-runtime='rkt'.")
fs.StringVar(&s.RktStage1Image, "rkt-stage1-image", s.RktStage1Image, "image to use as stage1. Local paths and http/https URLs are supported. If empty, the 'stage1.aci' in the same directory as '--rkt-path' will be used.")
Expand Down
16 changes: 14 additions & 2 deletions cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package app

import (
"crypto/tls"
"errors"
"fmt"
"math/rand"
"net"
Expand Down Expand Up @@ -289,11 +290,22 @@ func Run(s *options.KubeletServer, kcfg *KubeletConfig) error {
}

func run(s *options.KubeletServer, kcfg *KubeletConfig) (err error) {
if s.ExitOnLockContention && s.LockFilePath == "" {
return errors.New("cannot exit on lock file contention: no lock file specified")
}

done := make(chan struct{})
if s.LockFilePath != "" {
glog.Infof("aquiring lock on %q", s.LockFilePath)
if err := flock.Acquire(s.LockFilePath); err != nil {
return fmt.Errorf("unable to aquire file lock on %q: %v", s.LockFilePath, err)
}
if s.ExitOnLockContention {
glog.Infof("watching for inotify events for: %v", s.LockFilePath)
if err := watchForLockfileContention(s.LockFilePath, done); err != nil {
return err
}
}
}
if c, err := configz.New("componentconfig"); err == nil {
c.Set(s.KubeletConfiguration)
Expand Down Expand Up @@ -383,8 +395,8 @@ func run(s *options.KubeletServer, kcfg *KubeletConfig) (err error) {
return nil
}

// run forever
select {}
<-done
return nil
}

// InitializeTLS checks for a configured TLSCertFile and TLSPrivateKeyFile: if unspecified a new self-signed
Expand Down
44 changes: 44 additions & 0 deletions cmd/kubelet/app/server_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2015 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 app

import (
"github.com/golang/glog"
"golang.org/x/exp/inotify"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you looked at https://github.com/fsnotify/fsnotify? I believe it works across OSes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, but it does not contain the "open" event, so I went with inotify instead, which was already vendored. https://github.com/fsnotify/fsnotify/blob/master/fsnotify.go#L25

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh ok..

)

func watchForLockfileContention(path string, done chan struct{}) error {
watcher, err := inotify.NewWatcher()
if err != nil {
glog.Errorf("unable to create watcher for lockfile: %v", err)
return err
}
if err = watcher.AddWatch(path, inotify.IN_OPEN|inotify.IN_DELETE_SELF); err != nil {
glog.Errorf("unable to watch lockfile: %v", err)
return err
}
go func() {
select {
case ev := <-watcher.Event:
glog.Infof("inotify event: %v", ev)
case err = <-watcher.Error:
glog.Errorf("inotify watcher error: %v", err)
}
close(done)
}()
return nil
}
3 changes: 2 additions & 1 deletion cmd/kubelet/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package app

import (
"k8s.io/kubernetes/pkg/util/config"
"testing"

"k8s.io/kubernetes/pkg/util/config"
)

func TestValueOfAllocatableResources(t *testing.T) {
Expand Down
25 changes: 25 additions & 0 deletions cmd/kubelet/app/server_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// +build !linux

/*
Copyright 2015 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 app

import "errors"

func watchForLockfileContention(path string, done chan struct{}) error {
return errors.New("kubelet unsupported in this build")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need kubelet to build and run across different platforms. So we need a stub for features that are OS dependent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's why I added this file/function. To enable kubelet to build across platforms. Did you want something more than this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this implementation make the kubelet exit right away when run on OSX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if this flag was supplied, but the kubelet doesn't actually work correctly on OSX, correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We support development on OSX to some extent. So we want integration tests
to function on OSX.

On Wed, May 18, 2016 at 3:57 PM, Derek Parker notifications@github.com
wrote:

In cmd/kubelet/app/server_unsupported.go
#25596 (comment)
:

+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 "errors"
+
+func watchForLockfileContention(path string, done chan struct{}) error {

  • return errors.New("kubelet unsupported in this build")

Yes, if this flag was supplied, but the kubelet doesn't actually work
correctly on OSX, correct?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/kubernetes/kubernetes/pull/25596/files/46ddb9c0dd62d6ad34e9dcf8e3c8ff5d62fac4d2#r63797541

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't effect the integration tests then, at least, as none of them should hit this code path.

}
3 changes: 2 additions & 1 deletion docs/admin/kubelet.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ kubelet
--eviction-pressure-transition-period=5m0s: Duration for which the kubelet has to wait before transitioning out of an eviction pressure condition.
--eviction-soft="": A set of eviction thresholds (e.g. memory.available<1.5Gi) that if met over a corresponding grace period would trigger a pod eviction.
--eviction-soft-grace-period="": A set of eviction grace periods (e.g. memory.available=1m30s) that correspond to how long a soft eviction threshold must hold before triggering a pod eviction.
--exit-on-lock-contention[=false]: Whether kubelet should exit upon lock-file contention.
--experimental-flannel-overlay[=false]: Experimental support for starting the kubelet with the default overlay network (flannel). Assumes flanneld is already running in client mode. [default=false]
--experimental-nvidia-gpus=0: Number of NVIDIA GPU devices on this node. Only 0 (default) and 1 are currently supported.
--file-check-frequency=20s: Duration between checking config files for new data
Expand Down Expand Up @@ -159,7 +160,7 @@ kubelet
--volume-stats-agg-period=1m0s: Specifies interval for kubelet to calculate and cache the volume disk usage for all pods and volumes. To disable volume calculations, set to 0. Default: '1m'
```

###### Auto generated by spf13/cobra on 13-May-2016
###### Auto generated by spf13/cobra on 18-May-2016


<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
Expand Down
1 change: 1 addition & 0 deletions hack/verify-flags/known-flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ experimental-nvidia-gpus
experimental-prefix
external-hostname
external-ip
exit-on-lock-contention
failover-timeout
failure-domains
fake-clientset
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/componentconfig/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func DeepCopy_componentconfig_KubeletConfiguration(in KubeletConfiguration, out
out.RktAPIEndpoint = in.RktAPIEndpoint
out.RktStage1Image = in.RktStage1Image
out.LockFilePath = in.LockFilePath
out.ExitOnLockContention = in.ExitOnLockContention
out.ConfigureCBR0 = in.ConfigureCBR0
out.HairpinMode = in.HairpinMode
out.BabysitDaemons = in.BabysitDaemons
Expand Down