2016-05-04 06:21:34 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
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"
|
2016-11-16 14:40:29 +00:00
|
|
|
"path/filepath"
|
2016-05-04 06:21:34 +00:00
|
|
|
"testing"
|
2017-03-06 20:30:31 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2016-05-04 06:21:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestKubeletDirs(t *testing.T) {
|
2016-05-30 02:22:22 +00:00
|
|
|
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
2016-12-14 22:31:01 +00:00
|
|
|
defer testKubelet.Cleanup()
|
2016-05-04 06:21:34 +00:00
|
|
|
kubelet := testKubelet.kubelet
|
|
|
|
root := kubelet.rootDirectory
|
|
|
|
|
|
|
|
var exp, got string
|
|
|
|
|
|
|
|
got = kubelet.getPodsDir()
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "pods")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPluginsDir()
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "plugins")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPluginDir("foobar")
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "plugins/foobar")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPodDir("abc123")
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "pods/abc123")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPodVolumesDir("abc123")
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "pods/abc123/volumes")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPodVolumeDir("abc123", "plugin", "foobar")
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "pods/abc123/volumes/plugin/foobar")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPodPluginsDir("abc123")
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "pods/abc123/plugins")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPodPluginDir("abc123", "foobar")
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "pods/abc123/plugins/foobar")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
got = kubelet.getPodContainerDir("abc123", "def456")
|
2016-11-16 14:40:29 +00:00
|
|
|
exp = filepath.Join(root, "pods/abc123/containers/def456")
|
2017-03-06 20:30:31 +00:00
|
|
|
assert.Equal(t, exp, got)
|
2016-05-04 06:21:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestKubeletDirsCompat(t *testing.T) {
|
2016-05-30 02:22:22 +00:00
|
|
|
testKubelet := newTestKubelet(t, false /* controllerAttachDetachEnabled */)
|
2016-12-14 22:31:01 +00:00
|
|
|
defer testKubelet.Cleanup()
|
2016-05-04 06:21:34 +00:00
|
|
|
kubelet := testKubelet.kubelet
|
|
|
|
root := kubelet.rootDirectory
|
2017-03-06 20:30:31 +00:00
|
|
|
require.NoError(t, os.MkdirAll(root, 0750), "can't mkdir(%q)", root)
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
// Old-style pod dir.
|
2017-03-06 20:30:31 +00:00
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/oldpod", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
|
2016-05-04 06:21:34 +00:00
|
|
|
// New-style pod dir.
|
2017-03-06 20:30:31 +00:00
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/pods/newpod", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
|
2016-05-04 06:21:34 +00:00
|
|
|
// Both-style pod dir.
|
2017-03-06 20:30:31 +00:00
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/bothpod", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/pods/bothpod", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
|
|
|
|
assert.Equal(t, filepath.Join(root, "oldpod"), kubelet.getPodDir("oldpod"))
|
|
|
|
assert.Equal(t, filepath.Join(root, "pods/newpod"), kubelet.getPodDir("newpod"))
|
|
|
|
assert.Equal(t, filepath.Join(root, "pods/bothpod"), kubelet.getPodDir("bothpod"))
|
|
|
|
assert.Equal(t, filepath.Join(root, "pods/neitherpod"), kubelet.getPodDir("neitherpod"))
|
2016-05-04 06:21:34 +00:00
|
|
|
|
|
|
|
root = kubelet.getPodDir("newpod")
|
|
|
|
|
|
|
|
// Old-style container dir.
|
2017-03-06 20:30:31 +00:00
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/oldctr", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
|
2016-05-04 06:21:34 +00:00
|
|
|
// New-style container dir.
|
2017-03-06 20:30:31 +00:00
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/containers/newctr", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
|
2016-05-04 06:21:34 +00:00
|
|
|
// Both-style container dir.
|
2017-03-06 20:30:31 +00:00
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/bothctr", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
require.NoError(t, os.MkdirAll(fmt.Sprintf("%s/containers/bothctr", root), 0750), "can't mkdir(%q)", root)
|
|
|
|
|
|
|
|
assert.Equal(t, filepath.Join(root, "oldctr"), kubelet.getPodContainerDir("newpod", "oldctr"))
|
|
|
|
assert.Equal(t, filepath.Join(root, "containers/newctr"), kubelet.getPodContainerDir("newpod", "newctr"))
|
|
|
|
assert.Equal(t, filepath.Join(root, "containers/bothctr"), kubelet.getPodContainerDir("newpod", "bothctr"))
|
|
|
|
assert.Equal(t, filepath.Join(root, "containers/neitherctr"), kubelet.getPodContainerDir("newpod", "neitherctr"))
|
2016-05-04 06:21:34 +00:00
|
|
|
}
|