mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #14731 from mesosphere/sttts-remove-redirfd
Auto commit by PR queue bot
This commit is contained in:
commit
719cf5617e
@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// This package main is used for testing the redirfd package.
|
|
||||||
// Inspired by http://skarnet.org/software/execline/redirfd.html.
|
|
||||||
// Usage:
|
|
||||||
// k8sm-redirfb [-n] [-b] {mode} {fd} {file} {prog...}
|
|
||||||
package main
|
|
@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
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 main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/contrib/mesos/pkg/redirfd"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
nonblock := flag.Bool("n", false, "open file in non-blocking mode")
|
|
||||||
changemode := flag.Bool("b", false, "change mode of file after opening it: to non-blocking mode if the -n option was not given, to blocking mode if it was")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
args := flag.Args()
|
|
||||||
if len(args) < 4 {
|
|
||||||
fmt.Fprintf(os.Stderr, "expected {mode} {fd} {file} instead of: %v\n", args)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var mode redirfd.RedirectMode
|
|
||||||
switch m := args[0]; m {
|
|
||||||
case "r":
|
|
||||||
mode = redirfd.Read
|
|
||||||
case "w":
|
|
||||||
mode = redirfd.Write
|
|
||||||
case "u":
|
|
||||||
mode = redirfd.Update
|
|
||||||
case "a":
|
|
||||||
mode = redirfd.Append
|
|
||||||
case "c":
|
|
||||||
mode = redirfd.AppendExisting
|
|
||||||
case "x":
|
|
||||||
mode = redirfd.WriteNew
|
|
||||||
default:
|
|
||||||
fmt.Fprintf(os.Stderr, "unrecognized mode %q\n", mode)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fd, err := redirfd.ParseFileDescriptor(args[1])
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "failed to parse file descriptor: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
file := args[2]
|
|
||||||
|
|
||||||
f, err := mode.Redirect(*nonblock, *changemode, fd, file)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "redirect failed: %q, %v\n", args[1], err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
var pargs []string
|
|
||||||
if len(args) > 4 {
|
|
||||||
pargs = args[4:]
|
|
||||||
}
|
|
||||||
cmd := exec.Command(args[3], pargs...)
|
|
||||||
cmd.Stdin = os.Stdin
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
switch fd {
|
|
||||||
case redirfd.Stdin:
|
|
||||||
cmd.Stdin = f
|
|
||||||
case redirfd.Stdout:
|
|
||||||
cmd.Stdout = f
|
|
||||||
case redirfd.Stderr:
|
|
||||||
cmd.Stderr = f
|
|
||||||
default:
|
|
||||||
cmd.ExtraFiles = []*os.File{f}
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
if err = cmd.Run(); err != nil {
|
|
||||||
exiterr := err.(*exec.ExitError)
|
|
||||||
state := exiterr.ProcessState
|
|
||||||
if state != nil {
|
|
||||||
sys := state.Sys()
|
|
||||||
if waitStatus, ok := sys.(syscall.WaitStatus); ok {
|
|
||||||
if waitStatus.Signaled() {
|
|
||||||
os.Exit(256 + int(waitStatus.Signal()))
|
|
||||||
} else {
|
|
||||||
os.Exit(waitStatus.ExitStatus())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os.Exit(3)
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -30,11 +29,11 @@ import (
|
|||||||
|
|
||||||
log "github.com/golang/glog"
|
log "github.com/golang/glog"
|
||||||
bindings "github.com/mesos/mesos-go/executor"
|
bindings "github.com/mesos/mesos-go/executor"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/kubernetes/cmd/kubelet/app"
|
"k8s.io/kubernetes/cmd/kubelet/app"
|
||||||
"k8s.io/kubernetes/contrib/mesos/pkg/executor"
|
"k8s.io/kubernetes/contrib/mesos/pkg/executor"
|
||||||
"k8s.io/kubernetes/contrib/mesos/pkg/executor/config"
|
"k8s.io/kubernetes/contrib/mesos/pkg/executor/config"
|
||||||
"k8s.io/kubernetes/contrib/mesos/pkg/hyperkube"
|
"k8s.io/kubernetes/contrib/mesos/pkg/hyperkube"
|
||||||
"k8s.io/kubernetes/contrib/mesos/pkg/redirfd"
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/client/cache"
|
"k8s.io/kubernetes/pkg/client/cache"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
@ -49,8 +48,6 @@ import (
|
|||||||
utilio "k8s.io/kubernetes/pkg/util/io"
|
utilio "k8s.io/kubernetes/pkg/util/io"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
"k8s.io/kubernetes/pkg/util/oom"
|
"k8s.io/kubernetes/pkg/util/oom"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -62,8 +59,6 @@ const (
|
|||||||
type KubeletExecutorServer struct {
|
type KubeletExecutorServer struct {
|
||||||
*app.KubeletServer
|
*app.KubeletServer
|
||||||
SuicideTimeout time.Duration
|
SuicideTimeout time.Duration
|
||||||
ShutdownFD int
|
|
||||||
ShutdownFIFO string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKubeletExecutorServer() *KubeletExecutorServer {
|
func NewKubeletExecutorServer() *KubeletExecutorServer {
|
||||||
@ -77,7 +72,6 @@ func NewKubeletExecutorServer() *KubeletExecutorServer {
|
|||||||
k.RootDirectory = pwd // mesos sandbox dir
|
k.RootDirectory = pwd // mesos sandbox dir
|
||||||
}
|
}
|
||||||
k.Address = net.ParseIP(defaultBindingAddress())
|
k.Address = net.ParseIP(defaultBindingAddress())
|
||||||
k.ShutdownFD = -1 // indicates unspecified FD
|
|
||||||
|
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
@ -85,20 +79,6 @@ func NewKubeletExecutorServer() *KubeletExecutorServer {
|
|||||||
func (s *KubeletExecutorServer) AddFlags(fs *pflag.FlagSet) {
|
func (s *KubeletExecutorServer) AddFlags(fs *pflag.FlagSet) {
|
||||||
s.KubeletServer.AddFlags(fs)
|
s.KubeletServer.AddFlags(fs)
|
||||||
fs.DurationVar(&s.SuicideTimeout, "suicide-timeout", s.SuicideTimeout, "Self-terminate after this period of inactivity. Zero disables suicide watch.")
|
fs.DurationVar(&s.SuicideTimeout, "suicide-timeout", s.SuicideTimeout, "Self-terminate after this period of inactivity. Zero disables suicide watch.")
|
||||||
fs.IntVar(&s.ShutdownFD, "shutdown-fd", s.ShutdownFD, "File descriptor used to signal shutdown to external watchers, requires shutdown-fifo flag")
|
|
||||||
fs.StringVar(&s.ShutdownFIFO, "shutdown-fifo", s.ShutdownFIFO, "FIFO used to signal shutdown to external watchers, requires shutdown-fd flag")
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns a Closer that should be closed to signal impending shutdown, but only if ShutdownFD
|
|
||||||
// and ShutdownFIFO were specified. if they are specified, then this func blocks until there's
|
|
||||||
// a reader on the FIFO stream.
|
|
||||||
func (s *KubeletExecutorServer) syncExternalShutdownWatcher() (io.Closer, error) {
|
|
||||||
if s.ShutdownFD == -1 || s.ShutdownFIFO == "" {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
// redirfd -w n fifo ... # (blocks until the fifo is read)
|
|
||||||
log.Infof("blocked, waiting for shutdown reader for FD %d FIFO at %s", s.ShutdownFD, s.ShutdownFIFO)
|
|
||||||
return redirfd.Write.Redirect(true, false, redirfd.FileDescriptor(s.ShutdownFD), s.ShutdownFIFO)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the specified KubeletExecutorServer.
|
// Run runs the specified KubeletExecutorServer.
|
||||||
@ -130,11 +110,6 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
|
|||||||
log.Infof("Using root directory: %v", s.RootDirectory)
|
log.Infof("Using root directory: %v", s.RootDirectory)
|
||||||
credentialprovider.SetPreferredDockercfgPath(s.RootDirectory)
|
credentialprovider.SetPreferredDockercfgPath(s.RootDirectory)
|
||||||
|
|
||||||
shutdownCloser, err := s.syncExternalShutdownWatcher()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cAdvisorInterface, err := cadvisor.New(s.CAdvisorPort)
|
cAdvisorInterface, err := cadvisor.New(s.CAdvisorPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -241,7 +216,7 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
|
|||||||
kcfg.NodeName = kcfg.Hostname
|
kcfg.NodeName = kcfg.Hostname
|
||||||
|
|
||||||
err = app.RunKubelet(&kcfg, app.KubeletBuilder(func(kc *app.KubeletConfig) (app.KubeletBootstrap, *kconfig.PodConfig, error) {
|
err = app.RunKubelet(&kcfg, app.KubeletBuilder(func(kc *app.KubeletConfig) (app.KubeletBootstrap, *kconfig.PodConfig, error) {
|
||||||
return s.createAndInitKubelet(kc, hks, clientConfig, shutdownCloser)
|
return s.createAndInitKubelet(kc, hks, clientConfig)
|
||||||
}))
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -274,7 +249,6 @@ func (ks *KubeletExecutorServer) createAndInitKubelet(
|
|||||||
kc *app.KubeletConfig,
|
kc *app.KubeletConfig,
|
||||||
hks hyperkube.Interface,
|
hks hyperkube.Interface,
|
||||||
clientConfig *client.Config,
|
clientConfig *client.Config,
|
||||||
shutdownCloser io.Closer,
|
|
||||||
) (app.KubeletBootstrap, *kconfig.PodConfig, error) {
|
) (app.KubeletBootstrap, *kconfig.PodConfig, error) {
|
||||||
|
|
||||||
// TODO(k8s): block until all sources have delivered at least one update to the channel, or break the sync loop
|
// TODO(k8s): block until all sources have delivered at least one update to the channel, or break the sync loop
|
||||||
@ -363,14 +337,7 @@ func (ks *KubeletExecutorServer) createAndInitKubelet(
|
|||||||
Docker: kc.DockerClient,
|
Docker: kc.DockerClient,
|
||||||
SuicideTimeout: ks.SuicideTimeout,
|
SuicideTimeout: ks.SuicideTimeout,
|
||||||
KubeletFinished: kubeletFinished,
|
KubeletFinished: kubeletFinished,
|
||||||
ShutdownAlert: func() {
|
ExitFunc: os.Exit,
|
||||||
if shutdownCloser != nil {
|
|
||||||
if e := shutdownCloser.Close(); e != nil {
|
|
||||||
log.Warningf("failed to signal shutdown to external watcher: %v", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ExitFunc: os.Exit,
|
|
||||||
PodStatusFunc: func(_ executor.KubeletInterface, pod *api.Pod) (*api.PodStatus, error) {
|
PodStatusFunc: func(_ executor.KubeletInterface, pod *api.Pod) (*api.PodStatus, error) {
|
||||||
return klet.GetRuntime().GetPodStatus(pod)
|
return klet.GetRuntime().GetPodStatus(pod)
|
||||||
},
|
},
|
||||||
|
@ -29,10 +29,7 @@ kube::contrib::mesos::server_targets() {
|
|||||||
# The set of test targets that we are building for all platforms
|
# The set of test targets that we are building for all platforms
|
||||||
# Used by hack/lib/golang.sh
|
# Used by hack/lib/golang.sh
|
||||||
kube::contrib::mesos::test_targets() {
|
kube::contrib::mesos::test_targets() {
|
||||||
local -r targets=(
|
true
|
||||||
contrib/mesos/cmd/k8sm-redirfd
|
|
||||||
)
|
|
||||||
echo "${targets[@]}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# The set of source targets to include in the kube-build image
|
# The set of source targets to include in the kube-build image
|
||||||
|
Loading…
Reference in New Issue
Block a user