2016-10-14 18:52:18 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
|
|
|
|
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 kuberuntime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-06-22 17:25:57 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2017-06-22 18:24:23 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2018-02-06 22:11:09 +00:00
|
|
|
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
2016-10-14 18:52:18 +00:00
|
|
|
containertest "k8s.io/kubernetes/pkg/kubelet/container/testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestCreatePodSandbox tests creating sandbox and its corresponding pod log directory.
|
|
|
|
func TestCreatePodSandbox(t *testing.T) {
|
|
|
|
fakeRuntime, _, m, err := createTestRuntimeManager()
|
2016-11-18 20:50:58 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-10-14 18:52:18 +00:00
|
|
|
UID: "12345678",
|
|
|
|
Name: "bar",
|
|
|
|
Namespace: "new",
|
|
|
|
},
|
2016-11-18 20:50:58 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2016-10-14 18:52:18 +00:00
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Image: "busybox",
|
2016-11-18 20:50:58 +00:00
|
|
|
ImagePullPolicy: v1.PullIfNotPresent,
|
2016-10-14 18:52:18 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fakeOS := m.osInterface.(*containertest.FakeOS)
|
|
|
|
fakeOS.MkdirAllFn = func(path string, perm os.FileMode) error {
|
|
|
|
// Check pod logs root directory is created.
|
|
|
|
assert.Equal(t, filepath.Join(podLogsRootDirectory, "12345678"), path)
|
|
|
|
assert.Equal(t, os.FileMode(0755), perm)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
id, _, err := m.createPodSandbox(pod, 1)
|
|
|
|
assert.NoError(t, err)
|
2017-05-10 01:34:54 +00:00
|
|
|
assert.Contains(t, fakeRuntime.Called, "RunPodSandbox")
|
2017-01-20 01:55:56 +00:00
|
|
|
sandboxes, err := fakeRuntime.ListPodSandbox(&runtimeapi.PodSandboxFilter{Id: id})
|
2016-10-14 18:52:18 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, len(sandboxes), 1)
|
|
|
|
// TODO Check pod sandbox configuration
|
|
|
|
}
|