Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
bf7a941b
Commit
bf7a941b
authored
Aug 02, 2016
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kubelet: implement fake runtime/image service
parent
d9ca9e8c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
144 additions
and
12 deletions
+144
-12
fake_image_service.go
pkg/kubelet/api/testing/fake_image_service.go
+86
-12
fake_runtime_service.go
pkg/kubelet/api/testing/fake_runtime_service.go
+0
-0
utils.go
pkg/kubelet/api/testing/utils.go
+31
-0
sliceutils.go
pkg/kubelet/util/sliceutils/sliceutils.go
+27
-0
No files found.
pkg/kubelet/api/testing/fake_image_service.go
View file @
bf7a941b
...
@@ -18,30 +18,104 @@ package testing
...
@@ -18,30 +18,104 @@ package testing
import
(
import
(
"fmt"
"fmt"
"sync"
internalApi
"k8s.io/kubernetes/pkg/kubelet/api"
runtimeApi
"k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
runtimeApi
"k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/util/sliceutils"
)
)
type
fakeImageService
struct
{
var
(
fakeImageSize
uint64
=
1
)
type
FakeImageService
struct
{
sync
.
Mutex
Called
[]
string
Images
map
[
string
]
*
runtimeApi
.
Image
}
func
(
r
*
FakeImageService
)
SetFakeImages
(
images
[]
string
)
{
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Images
=
make
(
map
[
string
]
*
runtimeApi
.
Image
)
for
_
,
image
:=
range
images
{
r
.
Images
[
image
]
=
makeFakeImage
(
image
)
}
}
func
NewFakeImageService
()
*
FakeImageService
{
return
&
FakeImageService
{
Called
:
make
([]
string
,
0
),
Images
:
make
(
map
[
string
]
*
runtimeApi
.
Image
),
}
}
}
func
NewFakeImageService
()
internalApi
.
ImageManagerService
{
func
makeFakeImage
(
image
string
)
*
runtimeApi
.
Image
{
return
&
fakeImageService
{}
return
&
runtimeApi
.
Image
{
Id
:
&
image
,
Size_
:
&
fakeImageSize
,
RepoTags
:
[]
string
{
image
},
}
}
}
func
(
r
*
fakeImageService
)
ListImages
(
filter
*
runtimeApi
.
ImageFilter
)
([]
*
runtimeApi
.
Image
,
error
)
{
func
(
r
*
FakeImageService
)
ListImages
(
filter
*
runtimeApi
.
ImageFilter
)
([]
*
runtimeApi
.
Image
,
error
)
{
return
nil
,
fmt
.
Errorf
(
"not implemented"
)
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Called
=
append
(
r
.
Called
,
"ListImages"
)
images
:=
make
([]
*
runtimeApi
.
Image
,
0
)
for
_
,
img
:=
range
r
.
Images
{
if
filter
!=
nil
&&
filter
.
Image
!=
nil
{
if
!
sliceutils
.
StringInSlice
(
filter
.
Image
.
GetImage
(),
img
.
RepoTags
)
{
continue
}
}
images
=
append
(
images
,
img
)
}
return
images
,
nil
}
}
func
(
r
*
fakeImageService
)
ImageStatus
(
image
*
runtimeApi
.
ImageSpec
)
(
*
runtimeApi
.
Image
,
error
)
{
func
(
r
*
FakeImageService
)
ImageStatus
(
image
*
runtimeApi
.
ImageSpec
)
(
*
runtimeApi
.
Image
,
error
)
{
return
nil
,
fmt
.
Errorf
(
"not implemented"
)
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Called
=
append
(
r
.
Called
,
"ImageStatus"
)
if
img
,
ok
:=
r
.
Images
[
image
.
GetImage
()];
ok
{
return
img
,
nil
}
return
nil
,
fmt
.
Errorf
(
"image %q not found"
,
image
.
GetImage
())
}
}
func
(
r
*
fakeImageService
)
PullImage
(
image
*
runtimeApi
.
ImageSpec
,
auth
*
runtimeApi
.
AuthConfig
)
error
{
func
(
r
*
FakeImageService
)
PullImage
(
image
*
runtimeApi
.
ImageSpec
,
auth
*
runtimeApi
.
AuthConfig
)
error
{
return
fmt
.
Errorf
(
"not implemented"
)
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Called
=
append
(
r
.
Called
,
"PullImage"
)
// ImageID should be randomized for real container runtime, but here just use
// image's name for easily making fake images.
imageID
:=
image
.
GetImage
()
if
_
,
ok
:=
r
.
Images
[
imageID
];
!
ok
{
r
.
Images
[
imageID
]
=
makeFakeImage
(
image
.
GetImage
())
}
return
nil
}
}
func
(
r
*
fakeImageService
)
RemoveImage
(
image
*
runtimeApi
.
ImageSpec
)
error
{
func
(
r
*
FakeImageService
)
RemoveImage
(
image
*
runtimeApi
.
ImageSpec
)
error
{
return
fmt
.
Errorf
(
"not implemented"
)
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Called
=
append
(
r
.
Called
,
"RemoveImage"
)
// Remove the image
delete
(
r
.
Images
,
image
.
GetImage
())
return
nil
}
}
pkg/kubelet/api/testing/fake_runtime_service.go
View file @
bf7a941b
This diff is collapsed.
Click to expand it.
pkg/kubelet/api/testing/utils.go
0 → 100644
View file @
bf7a941b
/*
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
testing
func
filterInLabels
(
filter
,
labels
map
[
string
]
string
)
bool
{
for
k
,
v
:=
range
filter
{
if
value
,
ok
:=
labels
[
k
];
ok
{
if
value
!=
v
{
return
false
}
}
else
{
return
false
}
}
return
true
}
pkg/kubelet/util/sliceutils/sliceutils.go
0 → 100644
View file @
bf7a941b
/*
Copyright 2015 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
sliceutils
func
StringInSlice
(
s
string
,
list
[]
string
)
bool
{
for
_
,
v
:=
range
list
{
if
v
==
s
{
return
true
}
}
return
false
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment