pkg/kubelet/rktshim: deprecate kubelet/container API usage

This commit is contained in:
Tamer Tas 2016-08-12 21:49:11 +03:00
parent 72f41ff8cf
commit 70b5ed2665
2 changed files with 36 additions and 31 deletions

View File

@ -19,7 +19,7 @@ package rktshim
import ( import (
"errors" "errors"
"k8s.io/kubernetes/pkg/kubelet/container" runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
) )
// TODO(tmrts): Move these errors to the container API for code re-use. // TODO(tmrts): Move these errors to the container API for code re-use.
@ -27,7 +27,7 @@ var (
ErrImageNotFound = errors.New("rktshim: image not found") ErrImageNotFound = errors.New("rktshim: image not found")
) )
var _ container.ImageService = (*ImageStore)(nil) // var _ kubeletApi.ImageManagerService = (*ImageStore)(nil)
// ImageStore supports CRUD operations for images. // ImageStore supports CRUD operations for images.
type ImageStore struct{} type ImageStore struct{}
@ -36,26 +36,26 @@ type ImageStore struct{}
type ImageStoreConfig struct{} type ImageStoreConfig struct{}
// NewImageStore creates an image storage that allows CRUD operations for images. // NewImageStore creates an image storage that allows CRUD operations for images.
func NewImageStore(ImageStoreConfig) (container.ImageService, error) { func NewImageStore(ImageStoreConfig) (*ImageStore, error) {
return &ImageStore{}, nil return &ImageStore{}, nil
} }
// List lists the images residing in the image store. // List lists the images residing in the image store.
func (*ImageStore) List() ([]container.Image, error) { func (*ImageStore) List() ([]runtimeApi.Image, error) {
panic("not implemented") panic("not implemented")
} }
// Pull pulls an image into the image store and uses the given authentication method. // Pull pulls an image into the image store and uses the given authentication method.
func (*ImageStore) Pull(container.ImageSpec, container.AuthConfig, *container.PodSandboxConfig) error { func (*ImageStore) Pull(runtimeApi.ImageSpec, runtimeApi.AuthConfig, *runtimeApi.PodSandboxConfig) error {
panic("not implemented") panic("not implemented")
} }
// Remove removes the image from the image store. // Remove removes the image from the image store.
func (*ImageStore) Remove(container.ImageSpec) error { func (*ImageStore) Remove(runtimeApi.ImageSpec) error {
panic("not implemented") panic("not implemented")
} }
// Status returns the status of the image. // Status returns the status of the image.
func (*ImageStore) Status(container.ImageSpec) (container.Image, error) { func (*ImageStore) Status(runtimeApi.ImageSpec) (runtimeApi.Image, error) {
panic("not implemented") panic("not implemented")
} }

View File

@ -21,72 +21,77 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/kubernetes/pkg/kubelet/container" runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
) )
var ( var (
emptyImgStoreConfig = ImageStoreConfig{} emptyImgStoreConfig = ImageStoreConfig{}
// TODO(tmrts): fill the pod configuration // TODO(tmrts): fill the pod configuration
testPodConfig *container.PodSandboxConfig = nil testPodConfig *runtimeApi.PodSandboxConfig = nil
) )
type imageTestCase struct { type imageTestCase struct {
Spec *container.ImageSpec Spec *runtimeApi.ImageSpec
ExpectedStatus *container.Image ExpectedStatus *runtimeApi.Image
} }
func compareContainerImages(got, expected container.Image) error { func compareContainerImages(got, expected runtimeApi.Image) error {
if got.ID != expected.ID { if got.Id != expected.Id {
return fmt.Errorf("mismatching IDs -> expected %q, got %q", got.ID, expected.ID) return fmt.Errorf("mismatching Ids -> expected %q, got %q", got.Id, expected.Id)
} }
if !reflect.DeepEqual(got.RepoTags, expected.RepoTags) { if !reflect.DeepEqual(got.RepoTags, expected.RepoTags) {
return fmt.Errorf("mismatching RepoTags -> expected %q, got %q", got.ID, expected.ID) return fmt.Errorf("mismatching RepoTags -> expected %q, got %q", got.Id, expected.Id)
} }
if !reflect.DeepEqual(got.RepoDigests, expected.RepoDigests) { if !reflect.DeepEqual(got.RepoDigests, expected.RepoDigests) {
return fmt.Errorf("mismatching RepoDigests -> expected %q, got %q", got.ID, expected.ID) return fmt.Errorf("mismatching RepoDigests -> expected %q, got %q", got.Id, expected.Id)
} }
if got.Size != expected.Size { if got.Size_ != expected.Size_ {
return fmt.Errorf("mismatching Sizes -> expected %q, got %q", got.ID, expected.ID) return fmt.Errorf("mismatching Sizes -> expected %q, got %q", got.Id, expected.Id)
} }
return nil return nil
} }
var (
busyboxStr = "busybox"
gibberishStr = "XXXX_GIBBERISH_XXXX"
)
var testImgSpecs = map[string]imageTestCase{ var testImgSpecs = map[string]imageTestCase{
"non-existent-image": { "non-existent-image": {
&container.ImageSpec{ &runtimeApi.ImageSpec{
Image: "XXXX_GIBBERISH_XXXX", Image: &gibberishStr,
}, },
nil, nil,
}, },
"busybox": { "busybox": {
&container.ImageSpec{ &runtimeApi.ImageSpec{
Image: "busybox", Image: &busyboxStr,
}, },
&container.Image{ &runtimeApi.Image{
ID: "", Id: nil,
RepoTags: []string{}, RepoTags: []string{},
RepoDigests: []string{}, RepoDigests: []string{},
Size: 0, Size_: nil,
}, },
}, },
} }
var testAuthConfig = map[string]container.AuthConfig{ var testAuthConfig = map[string]runtimeApi.AuthConfig{
"no-auth": {}, "no-auth": {},
} }
func testNewImageStore(t *testing.T, cfg ImageStoreConfig) container.ImageService { func testNewImageStore(t *testing.T, cfg ImageStoreConfig) *ImageStore {
imgStore, err := NewImageStore(cfg) s, err := NewImageStore(cfg)
if err != nil { if err != nil {
// TODO(tmrts): Implement stringer for rktshim.ImageStoreConfig for test readability. // TODO(tmrts): Implement stringer for rktshim.ImageStoreConfig for test readability.
t.Fatalf("rktshim.NewImageStore(%s) got error %q", cfg, err) t.Fatalf("rktshim.NewImageStore(%s) got error %q", cfg, err)
} }
return imgStore return s
} }
func TestPullsImageWithoutAuthentication(t *testing.T) { func TestPullsImageWithoutAuthentication(t *testing.T) {
@ -196,10 +201,10 @@ func TestListsImages(t *testing.T) {
} }
for _, img := range imgs { for _, img := range imgs {
expectedImg := *testImgSpecs[img.ID].ExpectedStatus expectedImg := *testImgSpecs[*img.Id].ExpectedStatus
if err := compareContainerImages(img, expectedImg); err != nil { if err := compareContainerImages(img, expectedImg); err != nil {
t.Errorf("rktshim.ImageStore.List() for %q, %v", img.ID, err) t.Errorf("rktshim.ImageStore.List() for %q, %v", img.Id, err)
} }
} }
} }