Skip to content

Commit

Permalink
Merge pull request #77 from VirrageS/januszm-update
Browse files Browse the repository at this point in the history
Update Go version and libraries
  • Loading branch information
rthallisey authored Aug 1, 2023
2 parents 590457e + 9ec06e8 commit c2c8560
Show file tree
Hide file tree
Showing 518 changed files with 73,905 additions and 19,021 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved.
# Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -28,7 +28,7 @@ ARG CUDA_IMAGE=cuda
ARG CUDA_VERSION=12.2.0
ARG BASE_DIST=ubi8

FROM golang:1.18 AS builder
FROM golang:1.20 AS builder

ENV GOOS=linux\
GOARCH=amd64
Expand All @@ -54,7 +54,6 @@ LABEL description="See summary"
RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE

COPY --from=builder /go/src/kubevirt-gpu-device-plugin/nvidia-kubevirt-gpu-device-plugin /usr/bin/

COPY --from=builder /go/src/kubevirt-gpu-device-plugin/utils/pci.ids /usr/pci.ids

RUN yum update -y
Expand Down
27 changes: 12 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@ go 1.18

require (
github.com/NVIDIA/gpu-monitoring-tools v0.0.0-20211102125545-5a2c58442e48
github.com/fsnotify/fsnotify v1.4.9
github.com/golang/glog v1.1.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.7.0
github.com/fsnotify/fsnotify v1.6.0
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.10
google.golang.org/grpc v1.56.2
k8s.io/kubelet v0.19.16
k8s.io/klog/v2 v2.100.1
k8s.io/kubelet v0.21.0
)

require (
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hpcloud/tail v1.0.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230710151506-e685fd7b542b // indirect
golang.org/x/tools v0.11.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230725213213-b022f6e96895 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)

replace (
github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
google.golang.org/protobuf => google.golang.org/protobuf v1.28.0
gopkg.in/yaml.v3 v3.0.1 // indirect
)
257 changes: 195 additions & 62 deletions go.sum

Large diffs are not rendered by default.

42 changes: 20 additions & 22 deletions pkg/device_plugin/device_plugin.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -31,33 +31,32 @@ package device_plugin
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/golang/glog"
klog "k8s.io/klog/v2"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)

const (
nvidiaVendorID = "10de"
)

//Structure to hold details about Nvidia GPU Device
// Structure to hold details about Nvidia GPU Device
type NvidiaGpuDevice struct {
addr string // PCI address of device
}

//Key is iommu group id and value is a list of gpu devices part of the iommu group
// Key is iommu group id and value is a list of gpu devices part of the iommu group
var iommuMap map[string][]NvidiaGpuDevice

//Keys are the distinct Nvidia GPU device ids present on system and value is the list of all iommu group ids which are of that device id
// Keys are the distinct Nvidia GPU device ids present on system and value is the list of all iommu group ids which are of that device id
var deviceMap map[string][]string

//Key is vGPU Type and value is the list of Nvidia vGPUs of that type
// Key is vGPU Type and value is the list of Nvidia vGPUs of that type
var vGpuMap map[string][]NvidiaGpuDevice

// Key is the Nvidia GPU id and value is the list of associated vGPU ids
Expand All @@ -74,7 +73,6 @@ var readGpuIDForVgpu = readGpuIDForVgpuFunc
var startVgpuDevicePlugin = startVgpuDevicePluginFunc
var stop = make(chan struct{})

//
func InitiateDevicePlugin() {
//Identifies GPUs and represents it in appropriate structures
createIommuDeviceMap()
Expand All @@ -84,7 +82,7 @@ func InitiateDevicePlugin() {
createDevicePlugins()
}

//Starts gpu pass through and vGPU device plugin
// Starts gpu pass through and vGPU device plugin
func createDevicePlugins() {
var devicePlugins []*GenericDevicePlugin
var vGpuDevicePlugins []*GenericVGpuDevicePlugin
Expand Down Expand Up @@ -160,7 +158,7 @@ func startVgpuDevicePluginFunc(dp *GenericVGpuDevicePlugin) error {
return dp.Start(stop)
}

//Discovers all Nvidia GPUs which are loaded with VFIO-PCI driver and creates corresponding maps
// Discovers all Nvidia GPUs which are loaded with VFIO-PCI driver and creates corresponding maps
func createIommuDeviceMap() {
iommuMap = make(map[string][]NvidiaGpuDevice)
deviceMap = make(map[string][]string)
Expand Down Expand Up @@ -214,7 +212,7 @@ func createIommuDeviceMap() {
})
}

//Discovers all Nvidia vGPUs configured on a node and creates corresponding maps
// Discovers all Nvidia vGPUs configured on a node and creates corresponding maps
func createVgpuIDMap() {
vGpuMap = make(map[string][]NvidiaGpuDevice)
gpuVgpuMap = make(map[string][]string)
Expand Down Expand Up @@ -248,46 +246,46 @@ func createVgpuIDMap() {
})
}

//Read a file to retrieve ID
// Read a file to retrieve ID
func readIDFromFileFunc(basePath string, deviceAddress string, property string) (string, error) {
data, err := ioutil.ReadFile(filepath.Join(basePath, deviceAddress, property))
data, err := os.ReadFile(filepath.Join(basePath, deviceAddress, property))
if err != nil {
glog.Errorf("Could not read %s for device %s: %s", property, deviceAddress, err)
klog.Errorf("Could not read %s for device %s: %s", property, deviceAddress, err)
return "", err
}
id := strings.Trim(string(data[2:]), "\n")
return id, nil
}

//Read a file link
// Read a file link
func readLinkFunc(basePath string, deviceAddress string, link string) (string, error) {
path, err := os.Readlink(filepath.Join(basePath, deviceAddress, link))
if err != nil {
glog.Errorf("Could not read link %s for device %s: %s", link, deviceAddress, err)
klog.Errorf("Could not read link %s for device %s: %s", link, deviceAddress, err)
return "", err
}
_, file := filepath.Split(path)
return file, nil
}

//Read vGPU type name from the corresponding file
// Read vGPU type name from the corresponding file
func readVgpuIDFromFileFunc(basePath string, deviceAddress string, property string) (string, error) {
reg, _ := regexp.Compile("\\s+")
data, err := ioutil.ReadFile(filepath.Join(basePath, deviceAddress, property))
reg := regexp.MustCompile("\\s+")
data, err := os.ReadFile(filepath.Join(basePath, deviceAddress, property))
if err != nil {
glog.Errorf("Could not read %s for device %s: %s", property, deviceAddress, err)
klog.Errorf("Could not read %s for device %s: %s", property, deviceAddress, err)
return "", err
}
str := strings.Trim(string(data[:]), "\n")
str = reg.ReplaceAllString(str, "_") // Replace all spaces with underscore
return str, nil
}

//Read GPU id for a specific vGPU
// Read GPU id for a specific vGPU
func readGpuIDForVgpuFunc(basePath string, deviceAddress string) (string, error) {
path, err := os.Readlink(filepath.Join(basePath, deviceAddress))
if err != nil {
glog.Errorf("Could not read link for device %s: %s", deviceAddress, err)
klog.Errorf("Could not read link for device %s: %s", deviceAddress, err)
return "", err
}
splitStr := strings.Split(path, "/")
Expand Down
83 changes: 41 additions & 42 deletions pkg/device_plugin/device_plugin_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package device_plugin_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

func TestDevicePlugin(t *testing.T) {
//log.Log.SetIOWriter(GinkgoWriter)
RegisterFailHandler(Fail)
RunSpecs(t, "DevicePlugin Suite")
}
/*
* Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package device_plugin_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestDevicePlugin(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "DevicePlugin Suite")
}
Loading

0 comments on commit c2c8560

Please sign in to comment.