Commit 791d160b authored by Clayton Coleman's avatar Clayton Coleman

Split the Kubelet flag options and struct

Reduces the size of the app/server.go file and ensures that the flags and their defaults are clearly separated.
parent b1e48312
...@@ -17,13 +17,14 @@ limitations under the License. ...@@ -17,13 +17,14 @@ limitations under the License.
package main package main
import ( import (
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app" "k8s.io/kubernetes/cmd/kubelet/app"
"k8s.io/kubernetes/cmd/kubelet/app/options"
) )
// NewKubelet creates a new hyperkube Server object that includes the // NewKubelet creates a new hyperkube Server object that includes the
// description and flags. // description and flags.
func NewKubelet() *Server { func NewKubelet() *Server {
s := kubeletapp.NewKubeletServer() s := options.NewKubeletServer()
hks := Server{ hks := Server{
SimpleUsage: "kubelet", SimpleUsage: "kubelet",
Long: `The kubelet binary is responsible for maintaining a set of containers on a Long: `The kubelet binary is responsible for maintaining a set of containers on a
...@@ -33,7 +34,7 @@ func NewKubelet() *Server { ...@@ -33,7 +34,7 @@ func NewKubelet() *Server {
configuration data, with the running set of containers by starting or stopping configuration data, with the running set of containers by starting or stopping
Docker containers.`, Docker containers.`,
Run: func(_ *Server, _ []string) error { Run: func(_ *Server, _ []string) error {
return s.Run(nil) return app.Run(s, nil)
}, },
} }
s.AddFlags(hks.Flags()) s.AddFlags(hks.Flags())
......
...@@ -25,7 +25,8 @@ import ( ...@@ -25,7 +25,8 @@ import (
"os" "os"
"runtime" "runtime"
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app" "k8s.io/kubernetes/cmd/kubelet/app"
"k8s.io/kubernetes/cmd/kubelet/app/options"
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/version/verflag" "k8s.io/kubernetes/pkg/version/verflag"
...@@ -34,7 +35,7 @@ import ( ...@@ -34,7 +35,7 @@ import (
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
s := kubeletapp.NewKubeletServer() s := options.NewKubeletServer()
s.AddFlags(pflag.CommandLine) s.AddFlags(pflag.CommandLine)
util.InitFlags() util.InitFlags()
...@@ -43,7 +44,7 @@ func main() { ...@@ -43,7 +44,7 @@ func main() {
verflag.PrintAndExitIfRequested() verflag.PrintAndExitIfRequested()
if err := s.Run(nil); err != nil { if err := app.Run(s, nil); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err) fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1) os.Exit(1)
} }
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
bindings "github.com/mesos/mesos-go/executor" bindings "github.com/mesos/mesos-go/executor"
"github.com/spf13/pflag" "github.com/spf13/pflag"
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app" kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
"k8s.io/kubernetes/cmd/kubelet/app/options"
"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"
...@@ -42,7 +43,7 @@ import ( ...@@ -42,7 +43,7 @@ import (
) )
type KubeletExecutorServer struct { type KubeletExecutorServer struct {
*kubeletapp.KubeletServer *options.KubeletServer
SuicideTimeout time.Duration SuicideTimeout time.Duration
LaunchGracePeriod time.Duration LaunchGracePeriod time.Duration
...@@ -54,7 +55,7 @@ type KubeletExecutorServer struct { ...@@ -54,7 +55,7 @@ type KubeletExecutorServer struct {
func NewKubeletExecutorServer() *KubeletExecutorServer { func NewKubeletExecutorServer() *KubeletExecutorServer {
k := &KubeletExecutorServer{ k := &KubeletExecutorServer{
KubeletServer: kubeletapp.NewKubeletServer(), KubeletServer: options.NewKubeletServer(),
SuicideTimeout: config.DefaultSuicideTimeout, SuicideTimeout: config.DefaultSuicideTimeout,
LaunchGracePeriod: config.DefaultLaunchGracePeriod, LaunchGracePeriod: config.DefaultLaunchGracePeriod,
kletReady: make(chan struct{}), kletReady: make(chan struct{}),
...@@ -156,7 +157,7 @@ func (s *KubeletExecutorServer) runKubelet( ...@@ -156,7 +157,7 @@ func (s *KubeletExecutorServer) runKubelet(
} }
}() }()
kcfg, err := s.UnsecuredKubeletConfig() kcfg, err := kubeletapp.UnsecuredKubeletConfig(s.KubeletServer)
if err != nil { if err != nil {
return err return err
} }
...@@ -186,7 +187,7 @@ func (s *KubeletExecutorServer) runKubelet( ...@@ -186,7 +187,7 @@ func (s *KubeletExecutorServer) runKubelet(
kcfg.KubeClient = apiclient kcfg.KubeClient = apiclient
// taken from KubeletServer#Run(*KubeletConfig) // taken from KubeletServer#Run(*KubeletConfig)
eventClientConfig, err := s.CreateAPIServerClientConfig() eventClientConfig, err := kubeletapp.CreateAPIServerClientConfig(s.KubeletServer)
if err != nil { if err != nil {
return err return err
} }
...@@ -242,7 +243,7 @@ func (s *KubeletExecutorServer) runKubelet( ...@@ -242,7 +243,7 @@ func (s *KubeletExecutorServer) runKubelet(
// initialize the cloud provider. We explicitly wouldn't want // initialize the cloud provider. We explicitly wouldn't want
// that because then every kubelet instance would query the master // that because then every kubelet instance would query the master
// state.json which does not scale. // state.json which does not scale.
err = s.KubeletServer.Run(kcfg) err = kubeletapp.Run(s.KubeletServer, kcfg)
return return
} }
...@@ -263,7 +264,7 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error { ...@@ -263,7 +264,7 @@ func (s *KubeletExecutorServer) Run(hks hyperkube.Interface, _ []string) error {
// create apiserver client // create apiserver client
var apiclient *client.Client var apiclient *client.Client
clientConfig, err := s.CreateAPIServerClientConfig() clientConfig, err := kubeletapp.CreateAPIServerClientConfig(s.KubeletServer)
if err == nil { if err == nil {
apiclient, err = client.New(clientConfig) apiclient, err = client.New(clientConfig)
} }
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
"strings" "strings"
"syscall" "syscall"
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app"
exservice "k8s.io/kubernetes/contrib/mesos/pkg/executor/service" exservice "k8s.io/kubernetes/contrib/mesos/pkg/executor/service"
"k8s.io/kubernetes/contrib/mesos/pkg/hyperkube" "k8s.io/kubernetes/contrib/mesos/pkg/hyperkube"
"k8s.io/kubernetes/contrib/mesos/pkg/minion/config" "k8s.io/kubernetes/contrib/mesos/pkg/minion/config"
...@@ -250,7 +251,7 @@ func (ms *MinionServer) Run(hks hyperkube.Interface, _ []string) error { ...@@ -250,7 +251,7 @@ func (ms *MinionServer) Run(hks hyperkube.Interface, _ []string) error {
} }
// create apiserver client // create apiserver client
clientConfig, err := ms.KubeletExecutorServer.CreateAPIServerClientConfig() clientConfig, err := kubeletapp.CreateAPIServerClientConfig(ms.KubeletExecutorServer.KubeletServer)
if err != nil { if err != nil {
// required for k8sm since we need to send api.Binding information // required for k8sm since we need to send api.Binding information
// back to the apiserver // back to the apiserver
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
"time" "time"
log "github.com/golang/glog" log "github.com/golang/glog"
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app" "k8s.io/kubernetes/cmd/kubelet/app/options"
"k8s.io/kubernetes/contrib/mesos/pkg/runtime" "k8s.io/kubernetes/contrib/mesos/pkg/runtime"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors" "k8s.io/kubernetes/pkg/api/errors"
...@@ -47,7 +47,7 @@ type StatusUpdater struct { ...@@ -47,7 +47,7 @@ type StatusUpdater struct {
} }
func NewStatusUpdater(client *client.Client, relistPeriod time.Duration, nowFunc func() time.Time) *StatusUpdater { func NewStatusUpdater(client *client.Client, relistPeriod time.Duration, nowFunc func() time.Time) *StatusUpdater {
kubecfg := kubeletapp.NewKubeletServer() // only create to get the config, this is without side-effects kubecfg := options.NewKubeletServer() // only create to get the config, this is without side-effects
return &StatusUpdater{ return &StatusUpdater{
client: client, client: client,
relistPeriod: relistPeriod, relistPeriod: relistPeriod,
......
...@@ -21,8 +21,8 @@ import ( ...@@ -21,8 +21,8 @@ import (
"time" "time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/kubernetes/cmd/kube-controller-manager/app" cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
kubeletapp "k8s.io/kubernetes/cmd/kubelet/app" "k8s.io/kubernetes/cmd/kubelet/app/options"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
) )
...@@ -46,8 +46,8 @@ func Test_nodeWithUpdatedStatus(t *testing.T) { ...@@ -46,8 +46,8 @@ func Test_nodeWithUpdatedStatus(t *testing.T) {
} }
} }
cm := app.NewCMServer() cm := cmapp.NewCMServer()
kubecfg := kubeletapp.NewKubeletServer() kubecfg := options.NewKubeletServer()
assert.True(t, kubecfg.NodeStatusUpdateFrequency*3 < cm.NodeMonitorGracePeriod) // sanity check for defaults assert.True(t, kubecfg.NodeStatusUpdateFrequency*3 < cm.NodeMonitorGracePeriod) // sanity check for defaults
n := testNode(0, api.ConditionTrue, "KubeletReady") n := testNode(0, api.ConditionTrue, "KubeletReady")
......
...@@ -216,6 +216,16 @@ func (c *ContainerID) UnmarshalJSON(data []byte) error { ...@@ -216,6 +216,16 @@ func (c *ContainerID) UnmarshalJSON(data []byte) error {
return c.ParseString(string(data)) return c.ParseString(string(data))
} }
// DockerID is an ID of docker container. It is a type to make it clear when we're working with docker container Ids
type DockerID string
func (id DockerID) ContainerID() ContainerID {
return ContainerID{
Type: "docker",
ID: string(id),
}
}
type ContainerState string type ContainerState string
const ( const (
......
...@@ -24,7 +24,6 @@ import ( ...@@ -24,7 +24,6 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
) )
// This file contains helper functions to convert docker API types to runtime // This file contains helper functions to convert docker API types to runtime
...@@ -55,7 +54,7 @@ func toRuntimeContainer(c *docker.APIContainers) (*kubecontainer.Container, erro ...@@ -55,7 +54,7 @@ func toRuntimeContainer(c *docker.APIContainers) (*kubecontainer.Container, erro
} }
return &kubecontainer.Container{ return &kubecontainer.Container{
ID: kubetypes.DockerID(c.ID).ContainerID(), ID: kubecontainer.DockerID(c.ID).ContainerID(),
Name: dockerName.ContainerName, Name: dockerName.ContainerName,
Image: c.Image, Image: c.Image,
Hash: hash, Hash: hash,
......
...@@ -38,10 +38,9 @@ import ( ...@@ -38,10 +38,9 @@ import (
) )
const ( const (
PodInfraContainerName = leaky.PodInfraContainerName PodInfraContainerName = leaky.PodInfraContainerName
DockerPrefix = "docker://" DockerPrefix = "docker://"
PodInfraContainerImage = "gcr.io/google_containers/pause:2.0" LogSuffix = "log"
LogSuffix = "log"
) )
const ( const (
......
...@@ -189,7 +189,7 @@ func TestExecSupportNotExists(t *testing.T) { ...@@ -189,7 +189,7 @@ func TestExecSupportNotExists(t *testing.T) {
func TestDockerContainerCommand(t *testing.T) { func TestDockerContainerCommand(t *testing.T) {
runner := &DockerManager{} runner := &DockerManager{}
containerID := kubetypes.DockerID("1234").ContainerID() containerID := kubecontainer.DockerID("1234").ContainerID()
command := []string{"ls"} command := []string{"ls"}
cmd, _ := runner.getRunInContainerCommand(containerID, command) cmd, _ := runner.getRunInContainerCommand(containerID, command)
if cmd.Dir != "/var/lib/docker/execdriver/native/"+containerID.ID { if cmd.Dir != "/var/lib/docker/execdriver/native/"+containerID.ID {
...@@ -578,13 +578,13 @@ func TestFindContainersByPod(t *testing.T) { ...@@ -578,13 +578,13 @@ func TestFindContainersByPod(t *testing.T) {
Namespace: "ns", Namespace: "ns",
Containers: []*kubecontainer.Container{ Containers: []*kubecontainer.Container{
{ {
ID: kubetypes.DockerID("foobar").ContainerID(), ID: kubecontainer.DockerID("foobar").ContainerID(),
Name: "foobar", Name: "foobar",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
}, },
{ {
ID: kubetypes.DockerID("baz").ContainerID(), ID: kubecontainer.DockerID("baz").ContainerID(),
Name: "baz", Name: "baz",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
...@@ -597,7 +597,7 @@ func TestFindContainersByPod(t *testing.T) { ...@@ -597,7 +597,7 @@ func TestFindContainersByPod(t *testing.T) {
Namespace: "ns", Namespace: "ns",
Containers: []*kubecontainer.Container{ Containers: []*kubecontainer.Container{
{ {
ID: kubetypes.DockerID("barbar").ContainerID(), ID: kubecontainer.DockerID("barbar").ContainerID(),
Name: "barbar", Name: "barbar",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
...@@ -639,19 +639,19 @@ func TestFindContainersByPod(t *testing.T) { ...@@ -639,19 +639,19 @@ func TestFindContainersByPod(t *testing.T) {
Namespace: "ns", Namespace: "ns",
Containers: []*kubecontainer.Container{ Containers: []*kubecontainer.Container{
{ {
ID: kubetypes.DockerID("foobar").ContainerID(), ID: kubecontainer.DockerID("foobar").ContainerID(),
Name: "foobar", Name: "foobar",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
}, },
{ {
ID: kubetypes.DockerID("barfoo").ContainerID(), ID: kubecontainer.DockerID("barfoo").ContainerID(),
Name: "barfoo", Name: "barfoo",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
}, },
{ {
ID: kubetypes.DockerID("baz").ContainerID(), ID: kubecontainer.DockerID("baz").ContainerID(),
Name: "baz", Name: "baz",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
...@@ -664,7 +664,7 @@ func TestFindContainersByPod(t *testing.T) { ...@@ -664,7 +664,7 @@ func TestFindContainersByPod(t *testing.T) {
Namespace: "ns", Namespace: "ns",
Containers: []*kubecontainer.Container{ Containers: []*kubecontainer.Container{
{ {
ID: kubetypes.DockerID("barbar").ContainerID(), ID: kubecontainer.DockerID("barbar").ContainerID(),
Name: "barbar", Name: "barbar",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
...@@ -677,7 +677,7 @@ func TestFindContainersByPod(t *testing.T) { ...@@ -677,7 +677,7 @@ func TestFindContainersByPod(t *testing.T) {
Namespace: "ns", Namespace: "ns",
Containers: []*kubecontainer.Container{ Containers: []*kubecontainer.Container{
{ {
ID: kubetypes.DockerID("bazbaz").ContainerID(), ID: kubecontainer.DockerID("bazbaz").ContainerID(),
Name: "bazbaz", Name: "bazbaz",
Hash: 0x1234, Hash: 0x1234,
State: kubecontainer.ContainerStateUnknown, State: kubecontainer.ContainerStateUnknown,
...@@ -696,7 +696,7 @@ func TestFindContainersByPod(t *testing.T) { ...@@ -696,7 +696,7 @@ func TestFindContainersByPod(t *testing.T) {
fakeClient := &FakeDockerClient{} fakeClient := &FakeDockerClient{}
np, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil)) np, _ := network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
// image back-off is set to nil, this test shouldnt pull images // image back-off is set to nil, this test shouldnt pull images
containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, PodInfraContainerImage, 0, 0, "", kubecontainer.FakeOS{}, np, nil, nil, nil) containerManager := NewFakeDockerManager(fakeClient, &record.FakeRecorder{}, nil, nil, &cadvisorapi.MachineInfo{}, kubetypes.PodInfraContainerImage, 0, 0, "", kubecontainer.FakeOS{}, np, nil, nil, nil)
for i, test := range tests { for i, test := range tests {
fakeClient.ContainerList = test.containerList fakeClient.ContainerList = test.containerList
fakeClient.ExitedContainerList = test.exitedContainerList fakeClient.ExitedContainerList = test.exitedContainerList
......
...@@ -319,7 +319,7 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont ...@@ -319,7 +319,7 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont
} }
if dm.networkPlugin.Name() != network.DefaultPluginName { if dm.networkPlugin.Name() != network.DefaultPluginName {
netStatus, err := dm.networkPlugin.Status(podNamespace, podName, kubetypes.DockerID(container.ID)) netStatus, err := dm.networkPlugin.Status(podNamespace, podName, kubecontainer.DockerID(container.ID))
if err != nil { if err != nil {
glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", dm.networkPlugin.Name(), podName, err) glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", dm.networkPlugin.Name(), podName, err)
} else if netStatus != nil { } else if netStatus != nil {
...@@ -354,7 +354,7 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin ...@@ -354,7 +354,7 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
RestartCount: containerInfo.RestartCount, RestartCount: containerInfo.RestartCount,
Image: iResult.Config.Image, Image: iResult.Config.Image,
ImageID: DockerPrefix + iResult.Image, ImageID: DockerPrefix + iResult.Image,
ID: kubetypes.DockerID(id).ContainerID(), ID: kubecontainer.DockerID(id).ContainerID(),
ExitCode: iResult.State.ExitCode, ExitCode: iResult.State.ExitCode,
CreatedAt: iResult.Created, CreatedAt: iResult.Created,
Hash: hash, Hash: hash,
...@@ -771,7 +771,7 @@ func (dm *DockerManager) runContainer( ...@@ -771,7 +771,7 @@ func (dm *DockerManager) runContainer(
} }
dm.recorder.Eventf(ref, api.EventTypeNormal, kubecontainer.StartedContainer, "Started container with docker id %v", util.ShortenString(dockerContainer.ID, 12)) dm.recorder.Eventf(ref, api.EventTypeNormal, kubecontainer.StartedContainer, "Started container with docker id %v", util.ShortenString(dockerContainer.ID, 12))
return kubetypes.DockerID(dockerContainer.ID).ContainerID(), nil return kubecontainer.DockerID(dockerContainer.ID).ContainerID(), nil
} }
func setEntrypointAndCommand(container *api.Container, opts *kubecontainer.RunContainerOptions, dockerOpts *docker.CreateContainerOptions) { func setEntrypointAndCommand(container *api.Container, opts *kubecontainer.RunContainerOptions, dockerOpts *docker.CreateContainerOptions) {
...@@ -1266,7 +1266,7 @@ func (dm *DockerManager) KillPod(pod *api.Pod, runningPod kubecontainer.Pod) err ...@@ -1266,7 +1266,7 @@ func (dm *DockerManager) KillPod(pod *api.Pod, runningPod kubecontainer.Pod) err
} }
wg.Wait() wg.Wait()
if networkContainer != nil { if networkContainer != nil {
if err := dm.networkPlugin.TearDownPod(runningPod.Namespace, runningPod.Name, kubetypes.DockerID(networkContainer.ID.ID)); err != nil { if err := dm.networkPlugin.TearDownPod(runningPod.Namespace, runningPod.Name, kubecontainer.DockerID(networkContainer.ID.ID)); err != nil {
glog.Errorf("Failed tearing down the infra container: %v", err) glog.Errorf("Failed tearing down the infra container: %v", err)
errs <- err errs <- err
} }
...@@ -1559,7 +1559,7 @@ func appendToFile(filePath, stringToAppend string) error { ...@@ -1559,7 +1559,7 @@ func appendToFile(filePath, stringToAppend string) error {
} }
// createPodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container. // createPodInfraContainer starts the pod infra container for a pod. Returns the docker container ID of the newly created container.
func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.DockerID, error) { func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubecontainer.DockerID, error) {
start := time.Now() start := time.Now()
defer func() { defer func() {
metrics.ContainerManagerLatency.WithLabelValues("createPodInfraContainer").Observe(metrics.SinceInMicroseconds(start)) metrics.ContainerManagerLatency.WithLabelValues("createPodInfraContainer").Observe(metrics.SinceInMicroseconds(start))
...@@ -1601,7 +1601,7 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.Docker ...@@ -1601,7 +1601,7 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.Docker
return "", err return "", err
} }
return kubetypes.DockerID(id.ID), nil return kubecontainer.DockerID(id.ID), nil
} }
// Structure keeping information on changes that need to happen for a pod. The semantics is as follows: // Structure keeping information on changes that need to happen for a pod. The semantics is as follows:
...@@ -1617,9 +1617,9 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.Docker ...@@ -1617,9 +1617,9 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.Docker
type podContainerChangesSpec struct { type podContainerChangesSpec struct {
StartInfraContainer bool StartInfraContainer bool
InfraChanged bool InfraChanged bool
InfraContainerId kubetypes.DockerID InfraContainerId kubecontainer.DockerID
ContainersToStart map[int]string ContainersToStart map[int]string
ContainersToKeep map[kubetypes.DockerID]int ContainersToKeep map[kubecontainer.DockerID]int
} }
func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kubecontainer.PodStatus) (podContainerChangesSpec, error) { func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kubecontainer.PodStatus) (podContainerChangesSpec, error) {
...@@ -1630,10 +1630,10 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub ...@@ -1630,10 +1630,10 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
glog.V(4).Infof("Syncing Pod %q: %+v", format.Pod(pod), pod) glog.V(4).Infof("Syncing Pod %q: %+v", format.Pod(pod), pod)
containersToStart := make(map[int]string) containersToStart := make(map[int]string)
containersToKeep := make(map[kubetypes.DockerID]int) containersToKeep := make(map[kubecontainer.DockerID]int)
var err error var err error
var podInfraContainerID kubetypes.DockerID var podInfraContainerID kubecontainer.DockerID
var changed bool var changed bool
podInfraContainerStatus := podStatus.FindContainerStatusByName(PodInfraContainerName) podInfraContainerStatus := podStatus.FindContainerStatusByName(PodInfraContainerName)
if podInfraContainerStatus != nil && podInfraContainerStatus.State == kubecontainer.ContainerStateRunning { if podInfraContainerStatus != nil && podInfraContainerStatus.State == kubecontainer.ContainerStateRunning {
...@@ -1652,7 +1652,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub ...@@ -1652,7 +1652,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
} else { } else {
glog.V(4).Infof("Pod infra container looks good, keep it %q", format.Pod(pod)) glog.V(4).Infof("Pod infra container looks good, keep it %q", format.Pod(pod))
createPodInfraContainer = false createPodInfraContainer = false
podInfraContainerID = kubetypes.DockerID(podInfraContainerStatus.ID.ID) podInfraContainerID = kubecontainer.DockerID(podInfraContainerStatus.ID.ID)
containersToKeep[podInfraContainerID] = -1 containersToKeep[podInfraContainerID] = -1
} }
...@@ -1672,7 +1672,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub ...@@ -1672,7 +1672,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
continue continue
} }
containerID := kubetypes.DockerID(containerStatus.ID.ID) containerID := kubecontainer.DockerID(containerStatus.ID.ID)
hash := containerStatus.Hash hash := containerStatus.Hash
glog.V(3).Infof("pod %q container %q exists as %v", format.Pod(pod), container.Name, containerID) glog.V(3).Infof("pod %q container %q exists as %v", format.Pod(pod), container.Name, containerID)
...@@ -1718,7 +1718,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub ...@@ -1718,7 +1718,7 @@ func (dm *DockerManager) computePodContainerChanges(pod *api.Pod, podStatus *kub
// If Infra container is the last running one, we don't want to keep it. // If Infra container is the last running one, we don't want to keep it.
if !createPodInfraContainer && len(containersToStart) == 0 && len(containersToKeep) == 1 { if !createPodInfraContainer && len(containersToStart) == 0 && len(containersToKeep) == 1 {
containersToKeep = make(map[kubetypes.DockerID]int) containersToKeep = make(map[kubecontainer.DockerID]int)
} }
return podContainerChangesSpec{ return podContainerChangesSpec{
...@@ -1780,7 +1780,7 @@ func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubec ...@@ -1780,7 +1780,7 @@ func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubec
// Otherwise kill any running containers in this pod which are not specified as ones to keep. // Otherwise kill any running containers in this pod which are not specified as ones to keep.
runningContainerStatues := podStatus.GetRunningContainerStatuses() runningContainerStatues := podStatus.GetRunningContainerStatuses()
for _, containerStatus := range runningContainerStatues { for _, containerStatus := range runningContainerStatues {
_, keep := containerChanges.ContainersToKeep[kubetypes.DockerID(containerStatus.ID.ID)] _, keep := containerChanges.ContainersToKeep[kubecontainer.DockerID(containerStatus.ID.ID)]
if !keep { if !keep {
// NOTE(random-liu): Just log ID or log container status here? // NOTE(random-liu): Just log ID or log container status here?
glog.V(3).Infof("Killing unwanted container %+v", containerStatus) glog.V(3).Infof("Killing unwanted container %+v", containerStatus)
......
...@@ -88,7 +88,7 @@ func newTestDockerManagerWithHTTPClient(fakeHTTPClient *fakeHTTP) (*DockerManage ...@@ -88,7 +88,7 @@ func newTestDockerManagerWithHTTPClient(fakeHTTPClient *fakeHTTP) (*DockerManage
proberesults.NewManager(), proberesults.NewManager(),
containerRefManager, containerRefManager,
&cadvisorapi.MachineInfo{}, &cadvisorapi.MachineInfo{},
PodInfraContainerImage, kubetypes.PodInfraContainerImage,
0, 0, "", 0, 0, "",
kubecontainer.FakeOS{}, kubecontainer.FakeOS{},
networkPlugin, networkPlugin,
...@@ -532,7 +532,7 @@ func generatePodInfraContainerHash(pod *api.Pod) uint64 { ...@@ -532,7 +532,7 @@ func generatePodInfraContainerHash(pod *api.Pod) uint64 {
container := &api.Container{ container := &api.Container{
Name: PodInfraContainerName, Name: PodInfraContainerName,
Image: PodInfraContainerImage, Image: kubetypes.PodInfraContainerImage,
Ports: ports, Ports: ports,
ImagePullPolicy: podInfraContainerImagePullPolicy, ImagePullPolicy: podInfraContainerImagePullPolicy,
} }
...@@ -830,7 +830,7 @@ func TestSyncPodsUnhealthy(t *testing.T) { ...@@ -830,7 +830,7 @@ func TestSyncPodsUnhealthy(t *testing.T) {
ID: infraContainerID, ID: infraContainerID,
Name: "/k8s_POD." + strconv.FormatUint(generatePodInfraContainerHash(pod), 16) + "_foo_new_12345678_42", Name: "/k8s_POD." + strconv.FormatUint(generatePodInfraContainerHash(pod), 16) + "_foo_new_12345678_42",
}}) }})
dm.livenessManager.Set(kubetypes.DockerID(unhealthyContainerID).ContainerID(), proberesults.Failure, nil) dm.livenessManager.Set(kubecontainer.DockerID(unhealthyContainerID).ContainerID(), proberesults.Failure, nil)
runSyncPod(t, dm, fakeDocker, pod, nil, false) runSyncPod(t, dm, fakeDocker, pod, nil, false)
......
...@@ -106,9 +106,6 @@ const ( ...@@ -106,9 +106,6 @@ const (
// not block on anything else. // not block on anything else.
podKillingChannelCapacity = 50 podKillingChannelCapacity = 50
// system default DNS resolver configuration
ResolvConfDefault = "/etc/resolv.conf"
// Period for performing global cleanup tasks. // Period for performing global cleanup tasks.
housekeepingPeriod = time.Second * 2 housekeepingPeriod = time.Second * 2
......
...@@ -28,7 +28,6 @@ import ( ...@@ -28,7 +28,6 @@ import (
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockertools" "k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubelet/network" "k8s.io/kubernetes/pkg/kubelet/network"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
) )
const ( const (
...@@ -102,7 +101,7 @@ func (plugin *cniNetworkPlugin) Name() string { ...@@ -102,7 +101,7 @@ func (plugin *cniNetworkPlugin) Name() string {
return CNIPluginName return CNIPluginName
} }
func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubetypes.DockerID) error { func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
if !ok { if !ok {
return fmt.Errorf("CNI execution called on non-docker runtime") return fmt.Errorf("CNI execution called on non-docker runtime")
...@@ -121,7 +120,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubet ...@@ -121,7 +120,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubet
return err return err
} }
func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubetypes.DockerID) error { func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
if !ok { if !ok {
return fmt.Errorf("CNI execution called on non-docker runtime") return fmt.Errorf("CNI execution called on non-docker runtime")
...@@ -136,7 +135,7 @@ func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id ku ...@@ -136,7 +135,7 @@ func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id ku
// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin. // TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
// Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls // Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls
func (plugin *cniNetworkPlugin) Status(namespace string, name string, id kubetypes.DockerID) (*network.PodNetworkStatus, error) { func (plugin *cniNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager) runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
if !ok { if !ok {
return nil, fmt.Errorf("CNI execution called on non-docker runtime") return nil, fmt.Errorf("CNI execution called on non-docker runtime")
......
...@@ -38,6 +38,7 @@ import ( ...@@ -38,6 +38,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/dockertools" "k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubelet/network" "k8s.io/kubernetes/pkg/kubelet/network"
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results" proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
) )
// The temp dir where test plugins will be stored. // The temp dir where test plugins will be stored.
...@@ -156,7 +157,7 @@ func newTestDockerManager() (*dockertools.DockerManager, *dockertools.FakeDocker ...@@ -156,7 +157,7 @@ func newTestDockerManager() (*dockertools.DockerManager, *dockertools.FakeDocker
proberesults.NewManager(), proberesults.NewManager(),
containerRefManager, containerRefManager,
&cadvisorapi.MachineInfo{}, &cadvisorapi.MachineInfo{},
dockertools.PodInfraContainerImage, kubetypes.PodInfraContainerImage,
0, 0, "", 0, 0, "",
kubecontainer.FakeOS{}, kubecontainer.FakeOS{},
networkPlugin, networkPlugin,
......
...@@ -66,8 +66,8 @@ import ( ...@@ -66,8 +66,8 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/network" "k8s.io/kubernetes/pkg/kubelet/network"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
utilexec "k8s.io/kubernetes/pkg/util/exec" utilexec "k8s.io/kubernetes/pkg/util/exec"
) )
...@@ -132,19 +132,19 @@ func (plugin *execNetworkPlugin) validate() error { ...@@ -132,19 +132,19 @@ func (plugin *execNetworkPlugin) validate() error {
return nil return nil
} }
func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id kubetypes.DockerID) error { func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
out, err := utilexec.New().Command(plugin.getExecutable(), setUpCmd, namespace, name, string(id)).CombinedOutput() out, err := utilexec.New().Command(plugin.getExecutable(), setUpCmd, namespace, name, string(id)).CombinedOutput()
glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s, %v", string(out), err) glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s, %v", string(out), err)
return err return err
} }
func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id kubetypes.DockerID) error { func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
out, err := utilexec.New().Command(plugin.getExecutable(), tearDownCmd, namespace, name, string(id)).CombinedOutput() out, err := utilexec.New().Command(plugin.getExecutable(), tearDownCmd, namespace, name, string(id)).CombinedOutput()
glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s, %v", string(out), err) glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s, %v", string(out), err)
return err return err
} }
func (plugin *execNetworkPlugin) Status(namespace string, name string, id kubetypes.DockerID) (*network.PodNetworkStatus, error) { func (plugin *execNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, string(id)).CombinedOutput() out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, string(id)).CombinedOutput()
glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err) glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err)
if err != nil { if err != nil {
......
...@@ -26,7 +26,6 @@ import ( ...@@ -26,7 +26,6 @@ import (
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
utilerrors "k8s.io/kubernetes/pkg/util/errors" utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/validation" "k8s.io/kubernetes/pkg/util/validation"
) )
...@@ -46,13 +45,13 @@ type NetworkPlugin interface { ...@@ -46,13 +45,13 @@ type NetworkPlugin interface {
// SetUpPod is the method called after the infra container of // SetUpPod is the method called after the infra container of
// the pod has been created but before the other containers of the // the pod has been created but before the other containers of the
// pod are launched. // pod are launched.
SetUpPod(namespace string, name string, podInfraContainerID kubetypes.DockerID) error SetUpPod(namespace string, name string, podInfraContainerID kubecontainer.DockerID) error
// TearDownPod is the method called before a pod's infra container will be deleted // TearDownPod is the method called before a pod's infra container will be deleted
TearDownPod(namespace string, name string, podInfraContainerID kubetypes.DockerID) error TearDownPod(namespace string, name string, podInfraContainerID kubecontainer.DockerID) error
// Status is the method called to obtain the ipv4 or ipv6 addresses of the container // Status is the method called to obtain the ipv4 or ipv6 addresses of the container
Status(namespace string, name string, podInfraContainerID kubetypes.DockerID) (*PodNetworkStatus, error) Status(namespace string, name string, podInfraContainerID kubecontainer.DockerID) (*PodNetworkStatus, error)
} }
// PodNetworkStatus stores the network status of a pod (currently just the primary IP address) // PodNetworkStatus stores the network status of a pod (currently just the primary IP address)
...@@ -134,14 +133,14 @@ func (plugin *noopNetworkPlugin) Name() string { ...@@ -134,14 +133,14 @@ func (plugin *noopNetworkPlugin) Name() string {
return DefaultPluginName return DefaultPluginName
} }
func (plugin *noopNetworkPlugin) SetUpPod(namespace string, name string, id kubetypes.DockerID) error { func (plugin *noopNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
return nil return nil
} }
func (plugin *noopNetworkPlugin) TearDownPod(namespace string, name string, id kubetypes.DockerID) error { func (plugin *noopNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
return nil return nil
} }
func (plugin *noopNetworkPlugin) Status(namespace string, name string, id kubetypes.DockerID) (*PodNetworkStatus, error) { func (plugin *noopNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*PodNetworkStatus, error) {
return nil, nil return nil, nil
} }
/*
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 types
const (
PodInfraContainerImage = "gcr.io/google_containers/pause:2.0"
// system default DNS resolver configuration
ResolvConfDefault = "/etc/resolv.conf"
)
...@@ -21,21 +21,10 @@ import ( ...@@ -21,21 +21,10 @@ import (
"time" "time"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
) )
// TODO: Reconcile custom types in kubelet/types and this subpackage // TODO: Reconcile custom types in kubelet/types and this subpackage
// DockerID is an ID of docker container. It is a type to make it clear when we're working with docker container Ids
type DockerID string
func (id DockerID) ContainerID() kubecontainer.ContainerID {
return kubecontainer.ContainerID{
Type: "docker",
ID: string(id),
}
}
type HttpGetter interface { type HttpGetter interface {
Get(url string) (*http.Response, error) Get(url string) (*http.Response, error)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment