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
0ec6bdd2
Commit
0ec6bdd2
authored
Jan 30, 2019
by
vikaschoudhary16
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add image for sample-device-plugin
parent
bbfc3be5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
183 additions
and
0 deletions
+183
-0
BUILD
test/images/BUILD
+1
-0
BASEIMAGE
test/images/sample-device-plugin/BASEIMAGE
+5
-0
BUILD
test/images/sample-device-plugin/BUILD
+35
-0
Dockerfile
test/images/sample-device-plugin/Dockerfile
+17
-0
Makefile
test/images/sample-device-plugin/Makefile
+25
-0
VERSION
test/images/sample-device-plugin/VERSION
+1
-0
sampledeviceplugin.go
test/images/sample-device-plugin/sampledeviceplugin.go
+99
-0
No files found.
test/images/BUILD
View file @
0ec6bdd2
...
@@ -31,6 +31,7 @@ filegroup(
...
@@ -31,6 +31,7 @@ filegroup(
"//test/images/porter:all-srcs",
"//test/images/porter:all-srcs",
"//test/images/resource-consumer:all-srcs",
"//test/images/resource-consumer:all-srcs",
"//test/images/sample-apiserver:all-srcs",
"//test/images/sample-apiserver:all-srcs",
"//test/images/sample-device-plugin:all-srcs",
"//test/images/serve-hostname:all-srcs",
"//test/images/serve-hostname:all-srcs",
"//test/images/test-webserver:all-srcs",
"//test/images/test-webserver:all-srcs",
"//test/images/webhook:all-srcs",
"//test/images/webhook:all-srcs",
...
...
test/images/sample-device-plugin/BASEIMAGE
0 → 100644
View file @
0ec6bdd2
amd64=alpine:3.8
arm=arm32v6/alpine:3.8
arm64=arm64v8/alpine:3.8
ppc64le=ppc64le/alpine:3.8
s390x=s390x/alpine:3.8
test/images/sample-device-plugin/BUILD
0 → 100644
View file @
0ec6bdd2
package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "go_default_library",
srcs = ["sampledeviceplugin.go"],
importpath = "k8s.io/kubernetes/test/images/sample-device-plugin",
visibility = ["//visibility:private"],
deps = [
"//pkg/kubelet/apis/deviceplugin/v1beta1:go_default_library",
"//pkg/kubelet/cm/devicemanager:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)
go_binary(
name = "sample-device-plugin",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
test/images/sample-device-plugin/Dockerfile
0 → 100644
View file @
0ec6bdd2
# Copyright 2018 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.
FROM
BASEIMAGE
ADD
sampledeviceplugin /sampledeviceplugin
ENTRYPOINT
["/sampledeviceplugin", "-alsologtostderr"]
test/images/sample-device-plugin/Makefile
0 → 100644
View file @
0ec6bdd2
# Copyright 2018 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.
SRCS
=
sampledeviceplugin
ARCH
?=
amd64
TARGET
?=
$(CURDIR)
GOLANG_VERSION
?=
latest
SRC_DIR
=
$
(
notdir
$(
shell
pwd
)
)
export
bin
:
../image-util.sh bin
$(SRCS)
.PHONY
:
bin
test/images/sample-device-plugin/VERSION
0 → 100644
View file @
0ec6bdd2
1.0
test/images/sample-device-plugin/sampledeviceplugin.go
0 → 100755
View file @
0ec6bdd2
/*
Copyright 2018 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
main
import
(
"fmt"
"os"
"path/filepath"
"time"
"k8s.io/klog"
pluginapi
"k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
dm
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager"
)
const
(
resourceName
=
"example.com/resource"
)
// stubAllocFunc creates and returns allocation response for the input allocate request
func
stubAllocFunc
(
r
*
pluginapi
.
AllocateRequest
,
devs
map
[
string
]
pluginapi
.
Device
)
(
*
pluginapi
.
AllocateResponse
,
error
)
{
var
responses
pluginapi
.
AllocateResponse
for
_
,
req
:=
range
r
.
ContainerRequests
{
response
:=
&
pluginapi
.
ContainerAllocateResponse
{}
for
_
,
requestID
:=
range
req
.
DevicesIDs
{
dev
,
ok
:=
devs
[
requestID
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid allocation request with non-existing device %s"
,
requestID
)
}
if
dev
.
Health
!=
pluginapi
.
Healthy
{
return
nil
,
fmt
.
Errorf
(
"invalid allocation request with unhealthy device: %s"
,
requestID
)
}
// create fake device file
fpath
:=
filepath
.
Join
(
"/tmp"
,
dev
.
ID
)
// clean first
if
err
:=
os
.
RemoveAll
(
fpath
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to clean fake device file from previous run: %s"
,
err
)
}
f
,
err
:=
os
.
Create
(
fpath
)
if
err
!=
nil
&&
!
os
.
IsExist
(
err
)
{
return
nil
,
fmt
.
Errorf
(
"failed to create fake device file: %s"
,
err
)
}
f
.
Close
()
response
.
Mounts
=
append
(
response
.
Mounts
,
&
pluginapi
.
Mount
{
ContainerPath
:
fpath
,
HostPath
:
fpath
,
})
}
responses
.
ContainerResponses
=
append
(
responses
.
ContainerResponses
,
response
)
}
return
&
responses
,
nil
}
func
main
()
{
devs
:=
[]
*
pluginapi
.
Device
{
{
ID
:
"Dev-1"
,
Health
:
pluginapi
.
Healthy
},
{
ID
:
"Dev-2"
,
Health
:
pluginapi
.
Healthy
},
}
pluginSocksDir
:=
os
.
Getenv
(
"PLUGIN_SOCK_DIR"
)
klog
.
Infof
(
"pluginSocksDir: %s"
,
pluginSocksDir
)
if
pluginSocksDir
==
""
{
klog
.
Errorf
(
"Empty pluginSocksDir"
)
return
}
socketPath
:=
pluginSocksDir
+
"/dp."
+
fmt
.
Sprintf
(
"%d"
,
time
.
Now
()
.
Unix
())
dp1
:=
dm
.
NewDevicePluginStub
(
devs
,
socketPath
,
resourceName
,
false
)
if
err
:=
dp1
.
Start
();
err
!=
nil
{
panic
(
err
)
}
dp1
.
SetAllocFunc
(
stubAllocFunc
)
if
err
:=
dp1
.
Register
(
pluginapi
.
KubeletSocket
,
resourceName
,
pluginapi
.
DevicePluginPath
);
err
!=
nil
{
panic
(
err
)
}
select
{}
}
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