func()

in pkg/nitro_enclaves_device_plugin/device_plugin.go [84:125]


func (nedp *NitroEnclavesDevicePlugin) register(kubeletEndpoint, resourceName string) error {
	glog.V(0).Infof("Attempting %v device plugin to connect to kubelet...", nedp.ResourceName())
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	opts := []grpc.DialOption{
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		//lint:ignore SA1019 grpc.WithBlock is deprecated, not supported by grpc.NewClient
		grpc.WithBlock(),
		grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
			return net.DialUnix("unix", nil, &net.UnixAddr{Name: addr, Net: "unix"})
		}),
	}

	//lint:ignore SA1019 grpc.DialContext is deprecated // todo replace by grpc.NewClient
	conn, err := grpc.DialContext(
		ctx,
		kubeletEndpoint,
		opts...,
	)
	defer func(conn *grpc.ClientConn) {
		err := conn.Close()
		if err != nil {
			glog.Errorf("Error closing connection to kubelet: %s", err)
		}
	}(conn)

	if err != nil {
		glog.Errorf("Couldn't connect to kubelet! (Reason: %s)", err)
		return err
	}
	glog.V(0).Infof("Connected %v device plugin to kubelet", nedp.ResourceName())

	client := pluginapi.NewRegistrationClient(conn)
	_, err = client.Register(ctx, &pluginapi.RegisterRequest{
		Version:      pluginapi.Version,
		Endpoint:     path.Base(nedp.pdef.socketPath()),
		ResourceName: resourceName,
	})

	return err
}