Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub actions #12

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2024 NVIDIA CORPORATION
#
# 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.

name: Golang

on:
pull_request:
branches:
- main
- release-*
push:
branches:
- main
- release-*

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout code
- name: Get Golang version
id: vars
run: |
GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk )
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: Lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: -v --timeout 5m
skip-cache: true
test:
name: Unit test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get Golang version
id: vars
run: |
GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk )
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- run: make test
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout code
- name: Get Golang version
id: vars
run: |
GOLANG_VERSION=$( grep "GOLANG_VERSION ?=" versions.mk )
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION ?= }" >> $GITHUB_ENV
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- run: make build
80 changes: 80 additions & 0 deletions .github/workflows/images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2024 NVIDIA CORPORATION
#
# 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.

name: Images

# Run this workflow on pull requests
on:
pull_request:
types:
- opened
- synchronize
branches:
- main
- release-*
push:
branches:
- main
- release-*

jobs:
build-image:
# We trigger image builds on push events (MERGED pull requests) or on non-closed PRs that are not created against a fork.
if: |
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
(github.event_name == 'push')
runs-on: ubuntu-latest
strategy:
matrix:
dist: [ubi8]
steps:
- uses: actions/checkout@v4

- name: Calculate build vars
id: vars
run: |
echo "COMMIT_SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
echo "LOWERCASE_REPO_OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | awk '{print tolower($0)}')" >> $GITHUB_ENV
ArangoGutierrez marked this conversation as resolved.
Show resolved Hide resolved
REPO_FULL_NAME="${{ github.event.pull_request.head.repo.full_name }}"
echo "${REPO_FULL_NAME}"
echo "LABEL_IMAGE_SOURCE=https://github.com/${REPO_FULL_NAME}" >> $GITHUB_ENV

GENERATE_ARTIFACTS="false"
if [[ "${{ github.actor }}" == "dependabot[bot]" ]]; then
GENERATE_ARTIFACTS="false"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then
GENERATE_ARTIFACTS="true"
elif [[ "${{ github.event_name }}" == "push" ]]; then
GENERATE_ARTIFACTS="true"
fi
echo "PUSH_ON_BUILD=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV
echo "BUILD_MULTI_ARCH_IMAGES=${GENERATE_ARTIFACTS}" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build image
env:
IMAGE_NAME: ghcr.io/${LOWERCASE_REPO_OWNER}/vgpu-device-manager
ArangoGutierrez marked this conversation as resolved.
Show resolved Hide resolved
VERSION: ${COMMIT_SHORT_SHA}
ArangoGutierrez marked this conversation as resolved.
Show resolved Hide resolved
run: |
echo "${VERSION}"
make -f deployments/container/Makefile build-${{ matrix.dist }}
22 changes: 0 additions & 22 deletions .github/workflows/pre-sanity.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
run:
deadline: 10m

linters:
enable:
- contextcheck
- errcheck
- gocritic
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- staticcheck
- unconvert
disable: []

linters-settings:
goimports:
local-prefixes: github.com/NVIDIA/vgpu-device-manager

issues:
exclude-rules:
# We disable the memory aliasing checks in tests
- path: ".*_test.go"
linters:
- gosec
text: "G601: Implicit memory aliasing in for loop"
# We create world-readable files in tests.
- path: ".*_test.go"
linters:
- gosec
text: "G306: Expect WriteFile permissions to be 0600 or less"
7 changes: 3 additions & 4 deletions api/spec/v1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,21 @@ func (vs *VGPUConfigSpec) MatchesDeviceFilter(deviceID types.DeviceID) bool {

// MatchesAllDevices checks a 'VGPUConfigSpec' to see if it matches on 'all' devices.
func (vs *VGPUConfigSpec) MatchesAllDevices() bool {
switch devices := vs.Devices.(type) {
case string:
if devices, ok := vs.Devices.(string); ok {
return devices == "all"
}
return false
}

// MatchesDevices checks a 'VGPUConfigSpec' to see if it matches on a device at the specified 'index'.
func (vs *VGPUConfigSpec) MatchesDevices(index int) bool {
switch devices := vs.Devices.(type) {
case []int:
if devices, ok := vs.Devices.([]int); ok {
for _, d := range devices {
if index == d {
return true
}
}
}

return vs.MatchesAllDevices()
}
3 changes: 2 additions & 1 deletion api/spec/v1/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package v1

import (
"testing"

"github.com/stretchr/testify/require"
"sigs.k8s.io/yaml"
"testing"
)

func TestSpec(t *testing.T) {
Expand Down
16 changes: 9 additions & 7 deletions cmd/nvidia-k8s-vgpu-dm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func start(c *cli.Context) error {
}
vGPUConfigStateValue := getVGPUConfigStateValue(err)
log.Infof("Setting node label: %s=%s", vGPUConfigStateLabel, vGPUConfigStateValue)
setNodeLabelValue(clientset, vGPUConfigStateLabel, vGPUConfigStateValue)
_ = setNodeLabelValue(clientset, vGPUConfigStateLabel, vGPUConfigStateValue)

// Watch for configuration changes
for {
Expand All @@ -230,7 +230,7 @@ func start(c *cli.Context) error {
}
vGPUConfigStateValue = getVGPUConfigStateValue(err)
log.Infof("Setting node label: %s=%s", vGPUConfigStateLabel, vGPUConfigStateValue)
setNodeLabelValue(clientset, vGPUConfigStateLabel, vGPUConfigStateValue)
_ = setNodeLabelValue(clientset, vGPUConfigStateLabel, vGPUConfigStateValue)
}
}

Expand Down Expand Up @@ -268,7 +268,7 @@ func updateConfig(clientset *kubernetes.Clientset, selectedConfig string) error
log.Info("Asserting that the requested configuration is present in the configuration file")
err := assertValidConfig(selectedConfig)
if err != nil {
return fmt.Errorf("Unable to validate the selected vGPU configuration")
return fmt.Errorf("unable to validate the selected vGPU configuration")
}

log.Info("Checking if the selected vGPU device configuration is currently applied or not")
Expand Down Expand Up @@ -414,8 +414,10 @@ func shutdownGPUOperands(clientset *kubernetes.Clientset) error {
}

func waitForPodDeletion(clientset *kubernetes.Clientset, listOpts metav1.ListOptions) error {
pollFunc := func() (bool, error) {
podList, err := clientset.CoreV1().Pods(namespaceFlag).List(context.TODO(), listOpts)
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
pollFunc := func(context.Context) (bool, error) {
podList, err := clientset.CoreV1().Pods(namespaceFlag).List(ctx, listOpts)
if apierrors.IsNotFound(err) {
log.Infof("Pod was already deleted")
return true, nil
Expand All @@ -429,9 +431,9 @@ func waitForPodDeletion(clientset *kubernetes.Clientset, listOpts metav1.ListOpt
return false, nil
}

err := wait.PollImmediate(1*time.Second, 120*time.Second, pollFunc)
err := wait.PollUntilContextCancel(ctx, 1*time.Second, true, pollFunc)
if err != nil {
return fmt.Errorf("Error deleting pod: %v", err)
return fmt.Errorf("error deleting pod: %v", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/nvidia-vgpu-dm/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *Context) ApplyVGPUConfig() error {
func applyWrapper(c *cli.Context, f *Flags) error {
err := CheckFlags(f)
if err != nil {
cli.ShowSubcommandHelp(c)
_ = cli.ShowSubcommandHelp(c)
return err
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/nvidia-vgpu-dm/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func BuildCommand() *cli.Command {
func assertWrapper(c *cli.Context, f *Flags) error {
err := CheckFlags(f)
if err != nil {
cli.ShowSubcommandHelp(c)
_ = cli.ShowSubcommandHelp(c)
return err
}

Expand Down Expand Up @@ -217,6 +217,7 @@ func WalkSelectedVGPUConfigForEachGPU(vgpuConfig v1.VGPUConfigSpecSlice, f func(

log.Debugf(" GPU %v: %v", i, deviceID)

// nolint: gosec
err = f(&vc, i, deviceID)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/NVIDIA/vgpu-device-manager

go 1.20
go 1.21

require (
github.com/NVIDIA/go-nvlib v0.2.0
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -31,6 +32,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
Expand All @@ -43,6 +45,7 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand All @@ -57,10 +60,13 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down Expand Up @@ -120,6 +126,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package types

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"
)

func TestParseVGPUType(t *testing.T) {
Expand Down
Loading