func (m *ENIDevicePlugin) Allocate(ctx context.Context, r *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error) {
	response := pluginapi.AllocateResponse{
		ContainerResponses: []*pluginapi.ContainerAllocateResponse{},
	}
	log.Infof("Request Containers: %v", r.GetContainerRequests())
	for range r.GetContainerRequests() {
		response.ContainerResponses = append(response.ContainerResponses,
			&pluginapi.ContainerAllocateResponse{},
		)
	}
	return &response, nil
}
Allocate which return list of devices.
package deviceplugin
import (
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"path"
	"regexp"
	"sync"
	"syscall"
	"time"
	log "github.com/sirupsen/logrus"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"k8s.io/apimachinery/pkg/util/wait"
	pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)
const (
	ENITypeENI    = "eni"
	ENITypeMember = "member"
	ENIResName       = "aliyun/eni"
	MemberENIResName = "aliyun/member-eni"
)
type eniRes struct {
	resName string
	re      *regexp.Regexp
	sock    string
}
var eniMap = map[string]eniRes{
	ENITypeENI: {
		resName: ENIResName,
		re:      regexp.MustCompile("^.*" + "-eni.sock"),
		sock:    pluginapi.DevicePluginPath + "%d-" + "eni.sock",
	},
	ENITypeMember: {
		resName: MemberENIResName,
		re:      regexp.MustCompile("^.*" + "-member-eni.sock"),
		sock:    pluginapi.DevicePluginPath + "%d-" + "member-eni.sock",
	},
}
type ENIDevicePlugin struct {
	socket string
	server *grpc.Server
	count  int
	stop   chan struct{}
	eniRes eniRes
	sync.Locker
}
func NewENIDevicePlugin(count int, eniType string) *ENIDevicePlugin {
	res, ok := eniMap[eniType]
	if !ok {
		panic("unsupported eni type " + eniType)
	}
	pluginEndpoint := fmt.Sprintf(res.sock, time.Now().Unix())
	return &ENIDevicePlugin{
		socket: pluginEndpoint,
		count:  count,
		eniRes: res,
	}
}
func dial(unixSocketPath string, timeout time.Duration) (*grpc.ClientConn, func(), error) {
	timeoutCtx, cancel := context.WithTimeout(context.Background(), timeout)
	c, err := grpc.DialContext(timeoutCtx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(),
		grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
			return net.DialTimeout("unix", addr, timeout)
		}),
	)
	if err != nil {
		cancel()
		return nil, nil, err
	}
	return c, func() {
		err = c.Close()
		cancel()
	}, nil
}
func (m *ENIDevicePlugin) Start() error {
	if m.server != nil {
		close(m.stop)
		m.server.Stop()
	}
	err := m.cleanup()
	if err != nil {
		return err
	}
	sock, err := net.Listen("unix", m.socket)
	if err != nil {
		return err
	}
	m.server = grpc.NewServer([]grpc.ServerOption{}...)
	pluginapi.RegisterDevicePluginServer(m.server, m)
	m.stop = make(chan struct{}, 1)
	go func() {
		err := m.server.Serve(sock)
		if err != nil {
			log.Errorf("error start device plugin server, %+v", err)
		}
	}()
	_, closeConn, err := dial(m.socket, 5*time.Second)
	if err != nil {
		return err
	}
	closeConn()
	return nil
}
func (m *ENIDevicePlugin) GetDevicePluginOptions(context.Context, *pluginapi.Empty) (*pluginapi.DevicePluginOptions, error) {
	return &pluginapi.DevicePluginOptions{}, nil
}
func (m *ENIDevicePlugin) PreStartContainer(context.Context, *pluginapi.PreStartContainerRequest) (*pluginapi.PreStartContainerResponse, error) {
	return &pluginapi.PreStartContainerResponse{}, nil
}
func (m *ENIDevicePlugin) Stop() error {
	if m.server == nil {
		return nil
	}
	m.server.Stop()
	m.server = nil
	close(m.stop)
	return m.cleanup()
}
func (m *ENIDevicePlugin) Register(request pluginapi.RegisterRequest) error {
	conn, closeConn, err := dial(pluginapi.KubeletSocket, 5*time.Second)
	if err != nil {
		return err
	}
	defer closeConn()
	client := pluginapi.NewRegistrationClient(conn)
	_, err = client.Register(context.Background(), &request)
	if err != nil {
		return err
	}
	return nil
}
func (m *ENIDevicePlugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error {
	var devs []*pluginapi.Device
	for i := 0; i < m.count; i++ {
		devs = append(devs, &pluginapi.Device{ID: fmt.Sprintf("eni-%d", i), Health: pluginapi.Healthy})
	}
	err := s.Send(&pluginapi.ListAndWatchResponse{Devices: devs})
	if err != nil {
		return err
	}
	ticker := time.NewTicker(time.Second * 5)
	for {
		select {
		case <-ticker.C:
			log.Debugf("send list and watch res: %+v", devs)
			err := s.Send(&pluginapi.ListAndWatchResponse{Devices: devs})
			if err != nil {
				log.Errorf("error send device informance: error: %v", err)
			}
		case <-m.stop:
			return nil
		}
	}
}
func (m *ENIDevicePlugin) GetPreferredAllocation(context.Context, *pluginapi.PreferredAllocationRequest) (*pluginapi.PreferredAllocationResponse, error) {
	return nil, fmt.Errorf("unsupported")
}