mirror of https://github.com/k3s-io/k3s
Merge pull request #25124 from pmorie/kubelet-getters
Automatic merge from submit-queue Reduce kubelet LOC: extract getters Step 1 of #25028 as discussed in @kubernetes/sig-node meetingpull/6/head
commit
03e7e08e70
|
@ -77,7 +77,6 @@ import (
|
|||
kubeio "k8s.io/kubernetes/pkg/util/io"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
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/procfs"
|
||||
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
|
||||
|
@ -825,114 +824,6 @@ func (kl *Kubelet) addSource(source string) {
|
|||
kl.sourcesSeen.Insert(source)
|
||||
}
|
||||
|
||||
// getRootDir returns the full path to the directory under which kubelet can
|
||||
// store data. These functions are useful to pass interfaces to other modules
|
||||
// that may need to know where to write data without getting a whole kubelet
|
||||
// instance.
|
||||
func (kl *Kubelet) getRootDir() string {
|
||||
return kl.rootDirectory
|
||||
}
|
||||
|
||||
// getPodsDir returns the full path to the directory under which pod
|
||||
// directories are created.
|
||||
func (kl *Kubelet) getPodsDir() string {
|
||||
return path.Join(kl.getRootDir(), "pods")
|
||||
}
|
||||
|
||||
// getPluginsDir returns the full path to the directory under which plugin
|
||||
// directories are created. Plugins can use these directories for data that
|
||||
// they need to persist. Plugins should create subdirectories under this named
|
||||
// after their own names.
|
||||
func (kl *Kubelet) getPluginsDir() string {
|
||||
return path.Join(kl.getRootDir(), "plugins")
|
||||
}
|
||||
|
||||
// getPluginDir returns a data directory name for a given plugin name.
|
||||
// Plugins can use these directories to store data that they need to persist.
|
||||
// For per-pod plugin data, see getPodPluginDir.
|
||||
func (kl *Kubelet) getPluginDir(pluginName string) string {
|
||||
return path.Join(kl.getPluginsDir(), pluginName)
|
||||
}
|
||||
|
||||
// GetPodDir returns the full path to the per-pod data directory for the
|
||||
// specified pod. This directory may not exist if the pod does not exist.
|
||||
func (kl *Kubelet) GetPodDir(podUID types.UID) string {
|
||||
return kl.getPodDir(podUID)
|
||||
}
|
||||
|
||||
// getPodDir returns the full path to the per-pod directory for the pod with
|
||||
// the given UID.
|
||||
func (kl *Kubelet) getPodDir(podUID types.UID) string {
|
||||
// Backwards compat. The "old" stuff should be removed before 1.0
|
||||
// release. The thinking here is this:
|
||||
// !old && !new = use new
|
||||
// !old && new = use new
|
||||
// old && !new = use old
|
||||
// old && new = use new (but warn)
|
||||
oldPath := path.Join(kl.getRootDir(), string(podUID))
|
||||
oldExists := dirExists(oldPath)
|
||||
newPath := path.Join(kl.getPodsDir(), string(podUID))
|
||||
newExists := dirExists(newPath)
|
||||
if oldExists && !newExists {
|
||||
return oldPath
|
||||
}
|
||||
if oldExists {
|
||||
glog.Warningf("Data dir for pod %q exists in both old and new form, using new", podUID)
|
||||
}
|
||||
return newPath
|
||||
}
|
||||
|
||||
// getPodVolumesDir returns the full path to the per-pod data directory under
|
||||
// which volumes are created for the specified pod. This directory may not
|
||||
// exist if the pod does not exist.
|
||||
func (kl *Kubelet) getPodVolumesDir(podUID types.UID) string {
|
||||
return path.Join(kl.getPodDir(podUID), "volumes")
|
||||
}
|
||||
|
||||
// getPodVolumeDir returns the full path to the directory which represents the
|
||||
// named volume under the named plugin for specified pod. This directory may not
|
||||
// exist if the pod does not exist.
|
||||
func (kl *Kubelet) getPodVolumeDir(podUID types.UID, pluginName string, volumeName string) string {
|
||||
return path.Join(kl.getPodVolumesDir(podUID), pluginName, volumeName)
|
||||
}
|
||||
|
||||
// getPodPluginsDir returns the full path to the per-pod data directory under
|
||||
// which plugins may store data for the specified pod. This directory may not
|
||||
// exist if the pod does not exist.
|
||||
func (kl *Kubelet) getPodPluginsDir(podUID types.UID) string {
|
||||
return path.Join(kl.getPodDir(podUID), "plugins")
|
||||
}
|
||||
|
||||
// getPodPluginDir returns a data directory name for a given plugin name for a
|
||||
// given pod UID. Plugins can use these directories to store data that they
|
||||
// need to persist. For non-per-pod plugin data, see getPluginDir.
|
||||
func (kl *Kubelet) getPodPluginDir(podUID types.UID, pluginName string) string {
|
||||
return path.Join(kl.getPodPluginsDir(podUID), pluginName)
|
||||
}
|
||||
|
||||
// getPodContainerDir returns the full path to the per-pod data directory under
|
||||
// which container data is held for the specified pod. This directory may not
|
||||
// exist if the pod or container does not exist.
|
||||
func (kl *Kubelet) getPodContainerDir(podUID types.UID, ctrName string) string {
|
||||
// Backwards compat. The "old" stuff should be removed before 1.0
|
||||
// release. The thinking here is this:
|
||||
// !old && !new = use new
|
||||
// !old && new = use new
|
||||
// old && !new = use old
|
||||
// old && new = use new (but warn)
|
||||
oldPath := path.Join(kl.getPodDir(podUID), ctrName)
|
||||
oldExists := dirExists(oldPath)
|
||||
newPath := path.Join(kl.getPodDir(podUID), "containers", ctrName)
|
||||
newExists := dirExists(newPath)
|
||||
if oldExists && !newExists {
|
||||
return oldPath
|
||||
}
|
||||
if oldExists {
|
||||
glog.Warningf("Data dir for pod %q, container %q exists in both old and new form, using new", podUID, ctrName)
|
||||
}
|
||||
return newPath
|
||||
}
|
||||
|
||||
// dirExists returns true if the path exists and represents a directory.
|
||||
func dirExists(path string) bool {
|
||||
s, err := os.Stat(path)
|
||||
|
@ -975,14 +866,6 @@ func (kl *Kubelet) listPodsFromDisk() ([]types.UID, error) {
|
|||
return pods, nil
|
||||
}
|
||||
|
||||
// GetNode returns the node info for the configured node name of this Kubelet.
|
||||
func (kl *Kubelet) GetNode() (*api.Node, error) {
|
||||
if kl.standaloneMode {
|
||||
return kl.initialNodeStatus()
|
||||
}
|
||||
return kl.nodeInfo.GetNodeInfo(kl.nodeName)
|
||||
}
|
||||
|
||||
// Starts garbage collection threads.
|
||||
func (kl *Kubelet) StartGarbageCollection() {
|
||||
go wait.Until(func() {
|
||||
|
@ -2437,20 +2320,6 @@ func (kl *Kubelet) rejectPod(pod *api.Pod, reason, message string) {
|
|||
Message: "Pod " + message})
|
||||
}
|
||||
|
||||
// getNodeAnyWay() must return a *api.Node which is required by RunGeneralPredicates().
|
||||
// The *api.Node is obtained as follows:
|
||||
// Return kubelet's nodeInfo for this node, except on error or if in standalone mode,
|
||||
// in which case return a manufactured nodeInfo representing a node with no pods,
|
||||
// zero capacity, and the default labels.
|
||||
func (kl *Kubelet) getNodeAnyWay() (*api.Node, error) {
|
||||
if !kl.standaloneMode {
|
||||
if n, err := kl.nodeInfo.GetNodeInfo(kl.nodeName); err == nil {
|
||||
return n, nil
|
||||
}
|
||||
}
|
||||
return kl.initialNodeStatus()
|
||||
}
|
||||
|
||||
// canAdmitPod determines if a pod can be admitted, and gives a reason if it
|
||||
// cannot. "pod" is new pod, while "pods" include all admitted pods plus the
|
||||
// new pod. The function returns a boolean value indicating whether the pod
|
||||
|
@ -2861,55 +2730,6 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName string, lo
|
|||
return kl.containerRuntime.GetContainerLogs(pod, containerID, logOptions, stdout, stderr)
|
||||
}
|
||||
|
||||
// GetHostname Returns the hostname as the kubelet sees it.
|
||||
func (kl *Kubelet) GetHostname() string {
|
||||
return kl.hostname
|
||||
}
|
||||
|
||||
// Returns host IP or nil in case of error.
|
||||
func (kl *Kubelet) GetHostIP() (net.IP, error) {
|
||||
node, err := kl.GetNode()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get node: %v", err)
|
||||
}
|
||||
return nodeutil.GetNodeHostIP(node)
|
||||
}
|
||||
|
||||
// GetPods returns all pods bound to the kubelet and their spec, and the mirror
|
||||
// pods.
|
||||
func (kl *Kubelet) GetPods() []*api.Pod {
|
||||
return kl.podManager.GetPods()
|
||||
}
|
||||
|
||||
// GetRunningPods returns all pods running on kubelet from looking at the
|
||||
// container runtime cache. This function converts kubecontainer.Pod to
|
||||
// api.Pod, so only the fields that exist in both kubecontainer.Pod and
|
||||
// api.Pod are considered meaningful.
|
||||
func (kl *Kubelet) GetRunningPods() ([]*api.Pod, error) {
|
||||
pods, err := kl.runtimeCache.GetPods()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiPods := make([]*api.Pod, 0, len(pods))
|
||||
for _, pod := range pods {
|
||||
apiPods = append(apiPods, pod.ToAPIPod())
|
||||
}
|
||||
return apiPods, nil
|
||||
}
|
||||
|
||||
// GetPodByFullName gets the pod with the given 'full' name, which
|
||||
// incorporates the namespace as well as whether the pod was found.
|
||||
func (kl *Kubelet) GetPodByFullName(podFullName string) (*api.Pod, bool) {
|
||||
return kl.podManager.GetPodByFullName(podFullName)
|
||||
}
|
||||
|
||||
// GetPodByName provides the first pod that matches namespace and name, as well
|
||||
// as whether the pod was found.
|
||||
func (kl *Kubelet) GetPodByName(namespace, name string) (*api.Pod, bool) {
|
||||
return kl.podManager.GetPodByName(namespace, name)
|
||||
}
|
||||
|
||||
// updateRuntimeUp calls the container runtime status callback, initializing
|
||||
// the runtime dependent modules when the container runtime first comes up,
|
||||
// and returns an error if the status check fails. If the status check is OK,
|
||||
|
@ -3788,12 +3608,6 @@ func (kl *Kubelet) ListenAndServeReadOnly(address net.IP, port uint) {
|
|||
server.ListenAndServeKubeletReadOnlyServer(kl, kl.resourceAnalyzer, address, port, kl.containerRuntime)
|
||||
}
|
||||
|
||||
// GetRuntime returns the current Runtime implementation in use by the kubelet. This func
|
||||
// is exported to simplify integration with third party kubelet extensions (e.g. kubernetes-mesos).
|
||||
func (kl *Kubelet) GetRuntime() kubecontainer.Runtime {
|
||||
return kl.containerRuntime
|
||||
}
|
||||
|
||||
// updatePodCIDR updates the pod CIDR in the runtime state if it is different
|
||||
// from the current CIDR.
|
||||
func (kl *Kubelet) updatePodCIDR(cidr string) {
|
||||
|
@ -3819,8 +3633,3 @@ func (kl *Kubelet) shapingEnabled() bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// GetNodeConfig returns the container manager node config.
|
||||
func (kl *Kubelet) GetNodeConfig() cm.NodeConfig {
|
||||
return kl.containerManager.GetNodeConfig()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
Copyright 2016 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 kubelet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"path"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
nodeutil "k8s.io/kubernetes/pkg/util/node"
|
||||
)
|
||||
|
||||
// getRootDir returns the full path to the directory under which kubelet can
|
||||
// store data. These functions are useful to pass interfaces to other modules
|
||||
// that may need to know where to write data without getting a whole kubelet
|
||||
// instance.
|
||||
func (kl *Kubelet) getRootDir() string {
|
||||
return kl.rootDirectory
|
||||
}
|
||||
|
||||
// getPodsDir returns the full path to the directory under which pod
|
||||
// directories are created.
|
||||
func (kl *Kubelet) getPodsDir() string {
|
||||
return path.Join(kl.getRootDir(), "pods")
|
||||
}
|
||||
|
||||
// getPluginsDir returns the full path to the directory under which plugin
|
||||
// directories are created. Plugins can use these directories for data that
|
||||
// they need to persist. Plugins should create subdirectories under this named
|
||||
// after their own names.
|
||||
func (kl *Kubelet) getPluginsDir() string {
|
||||
return path.Join(kl.getRootDir(), "plugins")
|
||||
}
|
||||
|
||||
// getPluginDir returns a data directory name for a given plugin name.
|
||||
// Plugins can use these directories to store data that they need to persist.
|
||||
// For per-pod plugin data, see getPodPluginDir.
|
||||
func (kl *Kubelet) getPluginDir(pluginName string) string {
|
||||
return path.Join(kl.getPluginsDir(), pluginName)
|
||||
}
|
||||
|
||||
// GetPodDir returns the full path to the per-pod data directory for the
|
||||
// specified pod. This directory may not exist if the pod does not exist.
|
||||
func (kl *Kubelet) GetPodDir(podUID types.UID) string {
|
||||
return kl.getPodDir(podUID)
|
||||
}
|
||||
|
||||
// getPodDir returns the full path to the per-pod directory for the pod with
|
||||
// the given UID.
|
||||
func (kl *Kubelet) getPodDir(podUID types.UID) string {
|
||||
// Backwards compat. The "old" stuff should be removed before 1.0
|
||||
// release. The thinking here is this:
|
||||
// !old && !new = use new
|
||||
// !old && new = use new
|
||||
// old && !new = use old
|
||||
// old && new = use new (but warn)
|
||||
oldPath := path.Join(kl.getRootDir(), string(podUID))
|
||||
oldExists := dirExists(oldPath)
|
||||
newPath := path.Join(kl.getPodsDir(), string(podUID))
|
||||
newExists := dirExists(newPath)
|
||||
if oldExists && !newExists {
|
||||
return oldPath
|
||||
}
|
||||
if oldExists {
|
||||
glog.Warningf("Data dir for pod %q exists in both old and new form, using new", podUID)
|
||||
}
|
||||
return newPath
|
||||
}
|
||||
|
||||
// getPodVolumesDir returns the full path to the per-pod data directory under
|
||||
// which volumes are created for the specified pod. This directory may not
|
||||
// exist if the pod does not exist.
|
||||
func (kl *Kubelet) getPodVolumesDir(podUID types.UID) string {
|
||||
return path.Join(kl.getPodDir(podUID), "volumes")
|
||||
}
|
||||
|
||||
// getPodVolumeDir returns the full path to the directory which represents the
|
||||
// named volume under the named plugin for specified pod. This directory may not
|
||||
// exist if the pod does not exist.
|
||||
func (kl *Kubelet) getPodVolumeDir(podUID types.UID, pluginName string, volumeName string) string {
|
||||
return path.Join(kl.getPodVolumesDir(podUID), pluginName, volumeName)
|
||||
}
|
||||
|
||||
// getPodPluginsDir returns the full path to the per-pod data directory under
|
||||
// which plugins may store data for the specified pod. This directory may not
|
||||
// exist if the pod does not exist.
|
||||
func (kl *Kubelet) getPodPluginsDir(podUID types.UID) string {
|
||||
return path.Join(kl.getPodDir(podUID), "plugins")
|
||||
}
|
||||
|
||||
// getPodPluginDir returns a data directory name for a given plugin name for a
|
||||
// given pod UID. Plugins can use these directories to store data that they
|
||||
// need to persist. For non-per-pod plugin data, see getPluginDir.
|
||||
func (kl *Kubelet) getPodPluginDir(podUID types.UID, pluginName string) string {
|
||||
return path.Join(kl.getPodPluginsDir(podUID), pluginName)
|
||||
}
|
||||
|
||||
// getPodContainerDir returns the full path to the per-pod data directory under
|
||||
// which container data is held for the specified pod. This directory may not
|
||||
// exist if the pod or container does not exist.
|
||||
func (kl *Kubelet) getPodContainerDir(podUID types.UID, ctrName string) string {
|
||||
// Backwards compat. The "old" stuff should be removed before 1.0
|
||||
// release. The thinking here is this:
|
||||
// !old && !new = use new
|
||||
// !old && new = use new
|
||||
// old && !new = use old
|
||||
// old && new = use new (but warn)
|
||||
oldPath := path.Join(kl.getPodDir(podUID), ctrName)
|
||||
oldExists := dirExists(oldPath)
|
||||
newPath := path.Join(kl.getPodDir(podUID), "containers", ctrName)
|
||||
newExists := dirExists(newPath)
|
||||
if oldExists && !newExists {
|
||||
return oldPath
|
||||
}
|
||||
if oldExists {
|
||||
glog.Warningf("Data dir for pod %q, container %q exists in both old and new form, using new", podUID, ctrName)
|
||||
}
|
||||
return newPath
|
||||
}
|
||||
|
||||
// GetPods returns all pods bound to the kubelet and their spec, and the mirror
|
||||
// pods.
|
||||
func (kl *Kubelet) GetPods() []*api.Pod {
|
||||
return kl.podManager.GetPods()
|
||||
}
|
||||
|
||||
// GetRunningPods returns all pods running on kubelet from looking at the
|
||||
// container runtime cache. This function converts kubecontainer.Pod to
|
||||
// api.Pod, so only the fields that exist in both kubecontainer.Pod and
|
||||
// api.Pod are considered meaningful.
|
||||
func (kl *Kubelet) GetRunningPods() ([]*api.Pod, error) {
|
||||
pods, err := kl.runtimeCache.GetPods()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
apiPods := make([]*api.Pod, 0, len(pods))
|
||||
for _, pod := range pods {
|
||||
apiPods = append(apiPods, pod.ToAPIPod())
|
||||
}
|
||||
return apiPods, nil
|
||||
}
|
||||
|
||||
// GetPodByFullName gets the pod with the given 'full' name, which
|
||||
// incorporates the namespace as well as whether the pod was found.
|
||||
func (kl *Kubelet) GetPodByFullName(podFullName string) (*api.Pod, bool) {
|
||||
return kl.podManager.GetPodByFullName(podFullName)
|
||||
}
|
||||
|
||||
// GetPodByName provides the first pod that matches namespace and name, as well
|
||||
// as whether the pod was found.
|
||||
func (kl *Kubelet) GetPodByName(namespace, name string) (*api.Pod, bool) {
|
||||
return kl.podManager.GetPodByName(namespace, name)
|
||||
}
|
||||
|
||||
// GetHostname Returns the hostname as the kubelet sees it.
|
||||
func (kl *Kubelet) GetHostname() string {
|
||||
return kl.hostname
|
||||
}
|
||||
|
||||
// GetRuntime returns the current Runtime implementation in use by the kubelet. This func
|
||||
// is exported to simplify integration with third party kubelet extensions (e.g. kubernetes-mesos).
|
||||
func (kl *Kubelet) GetRuntime() kubecontainer.Runtime {
|
||||
return kl.containerRuntime
|
||||
}
|
||||
|
||||
// GetNode returns the node info for the configured node name of this Kubelet.
|
||||
func (kl *Kubelet) GetNode() (*api.Node, error) {
|
||||
if kl.standaloneMode {
|
||||
return kl.initialNodeStatus()
|
||||
}
|
||||
return kl.nodeInfo.GetNodeInfo(kl.nodeName)
|
||||
}
|
||||
|
||||
// getNodeAnyWay() must return a *api.Node which is required by RunGeneralPredicates().
|
||||
// The *api.Node is obtained as follows:
|
||||
// Return kubelet's nodeInfo for this node, except on error or if in standalone mode,
|
||||
// in which case return a manufactured nodeInfo representing a node with no pods,
|
||||
// zero capacity, and the default labels.
|
||||
func (kl *Kubelet) getNodeAnyWay() (*api.Node, error) {
|
||||
if !kl.standaloneMode {
|
||||
if n, err := kl.nodeInfo.GetNodeInfo(kl.nodeName); err == nil {
|
||||
return n, nil
|
||||
}
|
||||
}
|
||||
return kl.initialNodeStatus()
|
||||
}
|
||||
|
||||
// GetNodeConfig returns the container manager node config.
|
||||
func (kl *Kubelet) GetNodeConfig() cm.NodeConfig {
|
||||
return kl.containerManager.GetNodeConfig()
|
||||
}
|
||||
|
||||
// Returns host IP or nil in case of error.
|
||||
func (kl *Kubelet) GetHostIP() (net.IP, error) {
|
||||
node, err := kl.GetNode()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get node: %v", err)
|
||||
}
|
||||
return nodeutil.GetNodeHostIP(node)
|
||||
}
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
Copyright 2016 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 kubelet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKubeletDirs(t *testing.T) {
|
||||
testKubelet := newTestKubelet(t)
|
||||
kubelet := testKubelet.kubelet
|
||||
root := kubelet.rootDirectory
|
||||
|
||||
var exp, got string
|
||||
|
||||
got = kubelet.getPodsDir()
|
||||
exp = path.Join(root, "pods")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPluginsDir()
|
||||
exp = path.Join(root, "plugins")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPluginDir("foobar")
|
||||
exp = path.Join(root, "plugins/foobar")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("abc123")
|
||||
exp = path.Join(root, "pods/abc123")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodVolumesDir("abc123")
|
||||
exp = path.Join(root, "pods/abc123/volumes")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodVolumeDir("abc123", "plugin", "foobar")
|
||||
exp = path.Join(root, "pods/abc123/volumes/plugin/foobar")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodPluginsDir("abc123")
|
||||
exp = path.Join(root, "pods/abc123/plugins")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodPluginDir("abc123", "foobar")
|
||||
exp = path.Join(root, "pods/abc123/plugins/foobar")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("abc123", "def456")
|
||||
exp = path.Join(root, "pods/abc123/containers/def456")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubeletDirsCompat(t *testing.T) {
|
||||
testKubelet := newTestKubelet(t)
|
||||
kubelet := testKubelet.kubelet
|
||||
root := kubelet.rootDirectory
|
||||
if err := os.MkdirAll(root, 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
|
||||
var exp, got string
|
||||
|
||||
// Old-style pod dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/oldpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// New-style pod dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/pods/newpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// Both-style pod dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/bothpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/pods/bothpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("oldpod")
|
||||
exp = path.Join(root, "oldpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("newpod")
|
||||
exp = path.Join(root, "pods/newpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("bothpod")
|
||||
exp = path.Join(root, "pods/bothpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("neitherpod")
|
||||
exp = path.Join(root, "pods/neitherpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
root = kubelet.getPodDir("newpod")
|
||||
|
||||
// Old-style container dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/oldctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// New-style container dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/containers/newctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// Both-style container dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/bothctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/containers/bothctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "oldctr")
|
||||
exp = path.Join(root, "oldctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "newctr")
|
||||
exp = path.Join(root, "containers/newctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "bothctr")
|
||||
exp = path.Join(root, "containers/bothctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "neitherctr")
|
||||
exp = path.Join(root, "containers/neitherctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -221,161 +220,6 @@ func newTestPods(count int) []*api.Pod {
|
|||
return pods
|
||||
}
|
||||
|
||||
func TestKubeletDirs(t *testing.T) {
|
||||
testKubelet := newTestKubelet(t)
|
||||
kubelet := testKubelet.kubelet
|
||||
root := kubelet.rootDirectory
|
||||
|
||||
var exp, got string
|
||||
|
||||
got = kubelet.getPodsDir()
|
||||
exp = path.Join(root, "pods")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPluginsDir()
|
||||
exp = path.Join(root, "plugins")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPluginDir("foobar")
|
||||
exp = path.Join(root, "plugins/foobar")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("abc123")
|
||||
exp = path.Join(root, "pods/abc123")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodVolumesDir("abc123")
|
||||
exp = path.Join(root, "pods/abc123/volumes")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodVolumeDir("abc123", "plugin", "foobar")
|
||||
exp = path.Join(root, "pods/abc123/volumes/plugin/foobar")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodPluginsDir("abc123")
|
||||
exp = path.Join(root, "pods/abc123/plugins")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodPluginDir("abc123", "foobar")
|
||||
exp = path.Join(root, "pods/abc123/plugins/foobar")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("abc123", "def456")
|
||||
exp = path.Join(root, "pods/abc123/containers/def456")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubeletDirsCompat(t *testing.T) {
|
||||
testKubelet := newTestKubelet(t)
|
||||
kubelet := testKubelet.kubelet
|
||||
root := kubelet.rootDirectory
|
||||
if err := os.MkdirAll(root, 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
|
||||
var exp, got string
|
||||
|
||||
// Old-style pod dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/oldpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// New-style pod dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/pods/newpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// Both-style pod dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/bothpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/pods/bothpod", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("oldpod")
|
||||
exp = path.Join(root, "oldpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("newpod")
|
||||
exp = path.Join(root, "pods/newpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("bothpod")
|
||||
exp = path.Join(root, "pods/bothpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodDir("neitherpod")
|
||||
exp = path.Join(root, "pods/neitherpod")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
root = kubelet.getPodDir("newpod")
|
||||
|
||||
// Old-style container dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/oldctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// New-style container dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/containers/newctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
// Both-style container dir.
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/bothctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
if err := os.MkdirAll(fmt.Sprintf("%s/containers/bothctr", root), 0750); err != nil {
|
||||
t.Fatalf("can't mkdir(%q): %s", root, err)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "oldctr")
|
||||
exp = path.Join(root, "oldctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "newctr")
|
||||
exp = path.Join(root, "containers/newctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "bothctr")
|
||||
exp = path.Join(root, "containers/bothctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
|
||||
got = kubelet.getPodContainerDir("newpod", "neitherctr")
|
||||
exp = path.Join(root, "containers/neitherctr")
|
||||
if got != exp {
|
||||
t.Errorf("expected %q', got %q", exp, got)
|
||||
}
|
||||
}
|
||||
|
||||
var emptyPodUIDs map[types.UID]kubetypes.SyncPodType
|
||||
|
||||
func TestSyncLoopTimeUpdate(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue