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

clean deprecated code #88

Merged
merged 1 commit into from
Jan 24, 2024
Merged
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
25 changes: 14 additions & 11 deletions pkg/device_plugin/generic_device_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (

"github.com/fsnotify/fsnotify"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)

Expand All @@ -54,7 +55,7 @@ const (

var returnIommuMap = getIommuMap

//Implements the kubernetes device plugin API
// Implements the kubernetes device plugin API
type GenericDevicePlugin struct {
devs []*pluginapi.Device
server *grpc.Server
Expand All @@ -68,7 +69,7 @@ type GenericDevicePlugin struct {
devsHealth []*pluginapi.Device
}

//Returns an initialized instance of GenericDevicePlugin
// Returns an initialized instance of GenericDevicePlugin
func NewGenericDevicePlugin(deviceName string, devicePath string, devices []*pluginapi.Device) *GenericDevicePlugin {
log.Println("Devicename " + deviceName)
serverSock := fmt.Sprintf(pluginapi.DevicePluginPath+"kubevirt-%s.sock", deviceName)
Expand Down Expand Up @@ -103,15 +104,17 @@ func waitForGrpcServer(socketPath string, timeout time.Duration) error {

// dial establishes the gRPC communication with the registered device plugin.
func connect(socketPath string, timeout time.Duration) (*grpc.ClientConn, error) {
c, err := grpc.Dial(socketPath,
grpc.WithInsecure(),
ctx, _ := context.WithTimeout(context.Background(), timeout)
c, err := grpc.DialContext(ctx, socketPath,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithTimeout(timeout),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
if deadline, ok := ctx.Deadline(); ok {
return net.DialTimeout("unix", addr, time.Until(deadline))
}
return net.DialTimeout("unix", addr, connectionTimeout)
}),
)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -213,7 +216,7 @@ func (dpi *GenericDevicePlugin) Register() error {
return nil
}

//ListAndWatch lists devices and update that list according to the health status
// ListAndWatch lists devices and update that list according to the health status
func (dpi *GenericDevicePlugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error {

s.Send(&pluginapi.ListAndWatchResponse{Devices: dpi.devs})
Expand Down Expand Up @@ -244,7 +247,7 @@ func (dpi *GenericDevicePlugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.Dev
}
}

//Performs pre allocation checks and allocates a devices based on the request
// Performs pre allocation checks and allocates a devices based on the request
func (dpi *GenericDevicePlugin) Allocate(ctx context.Context, reqs *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error) {
log.Println("In allocate")
responses := pluginapi.AllocateResponse{}
Expand Down Expand Up @@ -334,7 +337,7 @@ func (dpi *GenericDevicePlugin) GetPreferredAllocation(ctx context.Context, in *
return nil, nil
}

//Health check of GPU devices
// Health check of GPU devices
func (dpi *GenericDevicePlugin) healthCheck() error {
method := fmt.Sprintf("healthCheck(%s)", dpi.deviceName)
log.Printf("%s: invoked", method)
Expand Down