mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Adding/updating kubelet/kuberuntime tests
This commit is contained in:
parent
03479e4d12
commit
90367729a3
@ -25,7 +25,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/client-go/util/flowcontrol"
|
"k8s.io/client-go/util/flowcontrol"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
@ -300,6 +300,13 @@ func (f *FakeRuntime) PullImage(image kubecontainer.ImageSpec, pullSecrets []v1.
|
|||||||
defer f.Unlock()
|
defer f.Unlock()
|
||||||
|
|
||||||
f.CalledFunctions = append(f.CalledFunctions, "PullImage")
|
f.CalledFunctions = append(f.CalledFunctions, "PullImage")
|
||||||
|
if f.Err == nil {
|
||||||
|
i := kubecontainer.Image{
|
||||||
|
ID: image.Image,
|
||||||
|
Spec: image,
|
||||||
|
}
|
||||||
|
f.ImageList = append(f.ImageList, i)
|
||||||
|
}
|
||||||
return image.Image, f.Err
|
return image.Image, f.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
"k8s.io/apimachinery/pkg/util/clock"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
@ -202,3 +202,48 @@ func TestApplyDefaultImageTag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPullAndListImageWithPodAnnotations(t *testing.T) {
|
||||||
|
pod := &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "test_pod",
|
||||||
|
Namespace: "test-ns",
|
||||||
|
UID: "bar",
|
||||||
|
ResourceVersion: "42",
|
||||||
|
SelfLink: "/api/v1/pods/foo",
|
||||||
|
Annotations: map[string]string{
|
||||||
|
"kubernetes.io/runtimehandler": "handler_name",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
c := pullerTestCase{ // pull missing image
|
||||||
|
containerImage: "missing_image",
|
||||||
|
policy: v1.PullIfNotPresent,
|
||||||
|
inspectErr: nil,
|
||||||
|
pullerErr: nil,
|
||||||
|
expected: []pullerExpects{
|
||||||
|
{[]string{"GetImageRef", "PullImage"}, nil},
|
||||||
|
}}
|
||||||
|
|
||||||
|
useSerializedEnv := true
|
||||||
|
puller, fakeClock, fakeRuntime, container := pullerTestEnv(c, useSerializedEnv)
|
||||||
|
fakeRuntime.CalledFunctions = nil
|
||||||
|
fakeRuntime.ImageList = []Image{}
|
||||||
|
fakeClock.Step(time.Second)
|
||||||
|
|
||||||
|
_, _, err := puller.EnsureImageExists(pod, container, nil, nil)
|
||||||
|
assert.NoError(t, fakeRuntime.AssertCalls(c.expected[0].calls), "tick=%d", 0)
|
||||||
|
assert.Equal(t, c.expected[0].err, err, "tick=%d", 0)
|
||||||
|
|
||||||
|
images, _ := fakeRuntime.ListImages()
|
||||||
|
assert.Equal(t, 1, len(images), "ListImages() count")
|
||||||
|
|
||||||
|
image := images[0]
|
||||||
|
assert.Equal(t, "missing_image:latest", image.ID, "Image ID")
|
||||||
|
|
||||||
|
expectedAnnotations := []Annotation{
|
||||||
|
{
|
||||||
|
Name: "kubernetes.io/runtimehandler",
|
||||||
|
Value: "handler_name",
|
||||||
|
}}
|
||||||
|
assert.Equal(t, expectedAnnotations, image.Spec.Annotations, "image spec annotations")
|
||||||
|
}
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
"k8s.io/kubernetes/pkg/credentialprovider"
|
"k8s.io/kubernetes/pkg/credentialprovider"
|
||||||
@ -168,6 +168,26 @@ func TestPullWithSecrets(t *testing.T) {
|
|||||||
|
|
||||||
_, err = fakeManager.PullImage(kubecontainer.ImageSpec{Image: test.imageName}, test.passedSecrets, nil)
|
_, err = fakeManager.PullImage(kubecontainer.ImageSpec{Image: test.imageName}, test.passedSecrets, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
fakeImageService.AssertImagePulledWithAuth(t, &runtimeapi.ImageSpec{Image: test.imageName}, test.expectedAuth, description)
|
fakeImageService.AssertImagePulledWithAuth(t, &runtimeapi.ImageSpec{Image: test.imageName, Annotations: make(map[string]string)}, test.expectedAuth, description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPullThenListWithAnnotations(t *testing.T) {
|
||||||
|
_, _, fakeManager, err := createTestRuntimeManager()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
imageSpec := kubecontainer.ImageSpec{
|
||||||
|
Image: "12345",
|
||||||
|
Annotations: []kubecontainer.Annotation{
|
||||||
|
{Name: "kubernetes.io/runtimehandler", Value: "handler_name"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = fakeManager.PullImage(imageSpec, nil, nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
images, err := fakeManager.ListImages()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 1, len(images))
|
||||||
|
assert.Equal(t, images[0].Spec, imageSpec)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user