Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
archlitchi committed Jun 24, 2024
1 parent c2c9dbc commit 9ae56be
Show file tree
Hide file tree
Showing 525 changed files with 637 additions and 85,040 deletions.
11 changes: 0 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@
FROM golang:1.21-bullseye AS GOBUILD
ADD . /device-plugin
ARG GOPROXY=https://goproxy.cn,direct
RUN apt-get update && apt-get -y install libhwloc-dev libdrm-dev
RUN cd /device-plugin && go build -o ./k8s-device-plugin cmd/k8s-device-plugin/main.go

FROM ubuntu:20.04
ENV TZ=Asia/Dubai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get -y install libhwloc-dev libdrm-dev pciutils
ENV LD_LIBRARY_PATH=/opt/hygondriver/hip/lib:/opt/hygondriver/llvm/lib:/opt/hygondriver/lib:/opt/hygondriver/lib64:/opt/hyhal/lib:/opt/hyhal/lib64:/opt/hygondriver/.hyhal/lib:/opt/hygondriver/.hyhal/lib64:
ENV PATH=/opt/hygondriver/bin:/opt/hygondriver/llvm/bin:/opt/hygondriver/hip/bin:/opt/hygondriver/hip/bin/hipify:/opt/hyhal/bin:/opt/hygondriver/.hyhal/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV C_INCLUDE_PATH=/opt/hygondriver/include:/opt/hyhal/include:/opt/hygondriver/llvm/include:/opt/hygondriver/.hyhal/include:
ENV ROCM_PATH=/opt/hygondriver
ENV DTKROOT=/opt/hygondriver
ENV CPLUS_INCLUDE_PATH=/opt/hygondriver/include:/opt/hyhal/include:/opt/hygondriver/llvm/include:/opt/hygondriver/.hyhal/include:
ENV HYHAL_PATH=/opt/hyhal
WORKDIR /root/
COPY --from=GOBUILD /device-plugin/k8s-device-plugin .
CMD ["./k8s-device-plugin", "-logtostderr=true", "-stderrthreshold=INFO", "-v=5"]
84 changes: 5 additions & 79 deletions cmd/k8s-device-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,15 @@ import (
"flag"
"fmt"
"os"
"time"

"github.com/HAMi/dcu-vgpu-device-plugin/internal/pkg/dcu"

"github.com/golang/glog"
"github.com/kubevirt/device-plugin-manager/pkg/dpm"
"github.com/HAMi/mock-device-plugin/internal/pkg/api/device"
)

// Lister serves as an interface between imlementation and Manager machinery. User passes
// implementation of this interface to NewManager function. Manager will use it to obtain resource
// namespace, monitor available resources and instantate a new plugin for them.
type Lister struct {
ResUpdateChan chan dpm.PluginNameList
Heartbeat chan bool
}

// GetResourceNamespace must return namespace (vendor ID) of implemented Lister. e.g. for
// resources in format "color.example.com/<color>" that would be "color.example.com".
func (l *Lister) GetResourceNamespace() string {
return "hygon.com"
}

// Discover notifies manager with a list of currently available resources in its namespace.
// e.g. if "color.example.com/red" and "color.example.com/blue" are available in the system,
// it would pass PluginNameList{"red", "blue"} to given channel. In case list of
// resources is static, it would use the channel only once and then return. In case the list is
// dynamic, it could block and pass a new list each times resources changed. If blocking is
// used, it should check whether the channel is closed, i.e. Discover should stop.
func (l *Lister) Discover(pluginListCh chan dpm.PluginNameList) {
for {
select {
case newResourcesList := <-l.ResUpdateChan: // New resources found
pluginListCh <- newResourcesList
case <-pluginListCh: // Stop message received
// Stop resourceUpdateCh
return
}
}
}

// NewPlugin instantiates a plugin implementation. It is given the last name of the resource,
// e.g. for resource name "color.example.com/red" that would be "red". It must return valid
// implementation of a PluginInterface.
func (l *Lister) NewPlugin(resourceLastName string) dpm.PluginInterface {
return &dcu.Plugin{
Heartbeat: l.Heartbeat,
}
}

var gitDescribe string

func main() {
versions := [...]string{
"DCU device plugin for Kubernetes",
"HAMi mock device plugin for Kubernetes",
fmt.Sprintf("%s version %s", os.Args[0], gitDescribe),
}

Expand All @@ -85,38 +40,9 @@ func main() {
fmt.Fprintln(os.Stderr, "Usage:")
flag.PrintDefaults()
}
var pulse int
flag.IntVar(&pulse, "pulse", 0, "time between health check polling in seconds. Set to 0 to disable.")
// this is also needed to enable glog usage in dpm
device.GlobalFlagSet()
flag.Parse()

for _, v := range versions {
glog.Infof("%s", v)
}

l := Lister{
ResUpdateChan: make(chan dpm.PluginNameList),
Heartbeat: make(chan bool),
}
manager := dpm.NewManager(&l)

if pulse > 0 {
go func() {
glog.Infof("Heart beating every %d seconds", pulse)
for {
time.Sleep(time.Second * time.Duration(pulse))
l.Heartbeat <- true
}
}()
}

go func() {
// /sys/class/kfd only exists if ROCm kernel/driver is installed
var path = "/sys/class/kfd"
if _, err := os.Stat(path); err == nil {
l.ResUpdateChan <- []string{"dcunum"}
}
}()
manager.Run()

device.Initialize()
device.RunManagers()
}
77 changes: 0 additions & 77 deletions cmd/k8s-node-labeller/README.md

This file was deleted.

64 changes: 0 additions & 64 deletions cmd/k8s-node-labeller/controller.go

This file was deleted.

Loading

0 comments on commit 9ae56be

Please sign in to comment.