api.proto 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // To regenerate api.pb.go run hack/update-device-plugin.sh
  2. syntax = 'proto3';
  3. package v1beta1;
  4. import "github.com/gogo/protobuf/gogoproto/gogo.proto";
  5. option (gogoproto.goproto_stringer_all) = false;
  6. option (gogoproto.stringer_all) = true;
  7. option (gogoproto.goproto_getters_all) = true;
  8. option (gogoproto.marshaler_all) = true;
  9. option (gogoproto.sizer_all) = true;
  10. option (gogoproto.unmarshaler_all) = true;
  11. option (gogoproto.goproto_unrecognized_all) = false;
  12. // Registration is the service advertised by the Kubelet
  13. // Only when Kubelet answers with a success code to a Register Request
  14. // may Device Plugins start their service
  15. // Registration may fail when device plugin version is not supported by
  16. // Kubelet or the registered resourceName is already taken by another
  17. // active device plugin. Device plugin is expected to terminate upon registration failure
  18. service Registration {
  19. rpc Register(RegisterRequest) returns (Empty) {}
  20. }
  21. message DevicePluginOptions {
  22. // Indicates if PreStartContainer call is required before each container start
  23. bool pre_start_required = 1;
  24. }
  25. message RegisterRequest {
  26. // Version of the API the Device Plugin was built against
  27. string version = 1;
  28. // Name of the unix socket the device plugin is listening on
  29. // PATH = path.Join(DevicePluginPath, endpoint)
  30. string endpoint = 2;
  31. // Schedulable resource name. As of now it's expected to be a DNS Label
  32. string resource_name = 3;
  33. // Options to be communicated with Device Manager
  34. DevicePluginOptions options = 4;
  35. }
  36. message Empty {
  37. }
  38. // DevicePlugin is the service advertised by Device Plugins
  39. service DevicePlugin {
  40. // GetDevicePluginOptions returns options to be communicated with Device
  41. // Manager
  42. rpc GetDevicePluginOptions(Empty) returns (DevicePluginOptions) {}
  43. // ListAndWatch returns a stream of List of Devices
  44. // Whenever a Device state change or a Device disappears, ListAndWatch
  45. // returns the new list
  46. rpc ListAndWatch(Empty) returns (stream ListAndWatchResponse) {}
  47. // Allocate is called during container creation so that the Device
  48. // Plugin can run device specific operations and instruct Kubelet
  49. // of the steps to make the Device available in the container
  50. rpc Allocate(AllocateRequest) returns (AllocateResponse) {}
  51. // PreStartContainer is called, if indicated by Device Plugin during registeration phase,
  52. // before each container start. Device plugin can run device specific operations
  53. // such as reseting the device before making devices available to the container
  54. rpc PreStartContainer(PreStartContainerRequest) returns (PreStartContainerResponse) {}
  55. }
  56. // ListAndWatch returns a stream of List of Devices
  57. // Whenever a Device state change or a Device disappears, ListAndWatch
  58. // returns the new list
  59. message ListAndWatchResponse {
  60. repeated Device devices = 1;
  61. }
  62. /* E.g:
  63. * struct Device {
  64. * ID: "GPU-fef8089b-4820-abfc-e83e-94318197576e",
  65. * State: "Healthy",
  66. *} */
  67. message Device {
  68. // A unique ID assigned by the device plugin used
  69. // to identify devices during the communication
  70. // Max length of this field is 63 characters
  71. string ID = 1;
  72. // Health of the device, can be healthy or unhealthy, see constants.go
  73. string health = 2;
  74. }
  75. // - PreStartContainer is expected to be called before each container start if indicated by plugin during registration phase.
  76. // - PreStartContainer allows kubelet to pass reinitialized devices to containers.
  77. // - PreStartContainer allows Device Plugin to run device specific operations on
  78. // the Devices requested
  79. message PreStartContainerRequest {
  80. repeated string devicesIDs = 1;
  81. }
  82. // PreStartContainerResponse will be send by plugin in response to PreStartContainerRequest
  83. message PreStartContainerResponse {
  84. }
  85. // - Allocate is expected to be called during pod creation since allocation
  86. // failures for any container would result in pod startup failure.
  87. // - Allocate allows kubelet to exposes additional artifacts in a pod's
  88. // environment as directed by the plugin.
  89. // - Allocate allows Device Plugin to run device specific operations on
  90. // the Devices requested
  91. message AllocateRequest {
  92. repeated ContainerAllocateRequest container_requests = 1;
  93. }
  94. message ContainerAllocateRequest {
  95. repeated string devicesIDs = 1;
  96. }
  97. // AllocateResponse includes the artifacts that needs to be injected into
  98. // a container for accessing 'deviceIDs' that were mentioned as part of
  99. // 'AllocateRequest'.
  100. // Failure Handling:
  101. // if Kubelet sends an allocation request for dev1 and dev2.
  102. // Allocation on dev1 succeeds but allocation on dev2 fails.
  103. // The Device plugin should send a ListAndWatch update and fail the
  104. // Allocation request
  105. message AllocateResponse {
  106. repeated ContainerAllocateResponse container_responses = 1;
  107. }
  108. message ContainerAllocateResponse {
  109. // List of environment variable to be set in the container to access one of more devices.
  110. map<string, string> envs = 1;
  111. // Mounts for the container.
  112. repeated Mount mounts = 2;
  113. // Devices for the container.
  114. repeated DeviceSpec devices = 3;
  115. // Container annotations to pass to the container runtime
  116. map<string, string> annotations = 4;
  117. }
  118. // Mount specifies a host volume to mount into a container.
  119. // where device library or tools are installed on host and container
  120. message Mount {
  121. // Path of the mount within the container.
  122. string container_path = 1;
  123. // Path of the mount on the host.
  124. string host_path = 2;
  125. // If set, the mount is read-only.
  126. bool read_only = 3;
  127. }
  128. // DeviceSpec specifies a host device to mount into a container.
  129. message DeviceSpec {
  130. // Path of the device within the container.
  131. string container_path = 1;
  132. // Path of the device on the host.
  133. string host_path = 2;
  134. // Cgroups permissions of the device, candidates are one or more of
  135. // * r - allows container to read from the specified device.
  136. // * w - allows container to write to the specified device.
  137. // * m - allows container to create device files that do not yet exist.
  138. string permissions = 3;
  139. }