github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/plugins/drivers/proto/driver.proto (about) 1 syntax = "proto3"; 2 package hashicorp.nomad.plugins.drivers.proto; 3 option go_package = "proto"; 4 5 import "google/protobuf/duration.proto"; 6 import "google/protobuf/timestamp.proto"; 7 8 import "plugins/shared/hclspec/hcl_spec.proto"; 9 import "plugins/shared/structs/proto/attribute.proto"; 10 11 // Driver service defines RPCs used to communicate with a nomad runtime driver. 12 // Some rpcs may not be implemented by the driver based on it's capabilities. 13 service Driver { 14 15 // TaskConfigSchema returns the schema for parsing the driver 16 // configuration of a task. 17 rpc TaskConfigSchema(TaskConfigSchemaRequest) returns (TaskConfigSchemaResponse) {} 18 19 // Capabilities returns a set of features which the driver implements. Some 20 // RPCs are not possible to implement on some runtimes, this allows the 21 // driver to indicate if it doesn't support these RPCs and features. 22 rpc Capabilities(CapabilitiesRequest) returns (CapabilitiesResponse) {} 23 24 // Fingerprint starts a stream which emits information about the driver 25 // including whether the driver healthy and able to function in the 26 // existing environment. 27 // 28 // The driver should immediately stream a FingerprintResponse when the RPC 29 // is initially called, then send any additional responses if there is a 30 // change in the driver's state. 31 rpc Fingerprint(FingerprintRequest) returns (stream FingerprintResponse) {} 32 33 // RecoverTask is used when a task has been started but the driver may not 34 // know about it. Such is the case if the driver restarts or is upgraded. 35 rpc RecoverTask(RecoverTaskRequest) returns (RecoverTaskResponse) {} 36 37 // StartTask starts and tracks the task on the implemented runtime 38 rpc StartTask(StartTaskRequest) returns (StartTaskResponse) {} 39 40 // WaitTask blocks until the given task exits, returning the result of the 41 // task. It may be called after the task has exited, but before the task is 42 // destroyed. 43 rpc WaitTask(WaitTaskRequest) returns (WaitTaskResponse) {} 44 45 // StopTask stops a given task by sending the desired signal to the process. 46 // If the task does not exit on its own within the given timeout, it will be 47 // forcefully killed. 48 rpc StopTask(StopTaskRequest) returns (StopTaskResponse) {} 49 50 // DestroyTask removes the task from the driver's internal state and cleans 51 // up any additional resources created by the driver. It cannot be called 52 // on a running task, unless force is set to true. 53 rpc DestroyTask(DestroyTaskRequest) returns (DestroyTaskResponse) {} 54 55 // InspectTask returns detailed information for the given task 56 rpc InspectTask(InspectTaskRequest) returns (InspectTaskResponse) {} 57 58 // TaskStats collects and returns runtime metrics for the given task 59 rpc TaskStats(TaskStatsRequest) returns (stream TaskStatsResponse) {} 60 61 // TaskEvents starts a streaming RPC where all task events emitted by the 62 // driver are streamed to the caller. 63 rpc TaskEvents(TaskEventsRequest) returns (stream 64 // buf:lint:ignore RPC_RESPONSE_STANDARD_NAME 65 DriverTaskEvent) {} 66 67 // The following RPCs are only implemented if the driver sets the 68 // corresponding capability. 69 70 // SignalTask sends a signal to the task 71 rpc SignalTask(SignalTaskRequest) returns (SignalTaskResponse) {} 72 73 // ExecTask executes a command inside the tasks execution context 74 rpc ExecTask(ExecTaskRequest) returns (ExecTaskResponse) {} 75 76 // ExecTaskStreaming executes a command inside the tasks execution context 77 // and streams back results 78 // buf:lint:ignore RPC_REQUEST_RESPONSE_UNIQUE 79 rpc ExecTaskStreaming(stream ExecTaskStreamingRequest) returns (stream ExecTaskStreamingResponse) {} 80 81 // CreateNetwork is implemented when the driver needs to create the network 82 // namespace instead of allowing the Nomad client to do. 83 rpc CreateNetwork(CreateNetworkRequest) returns (CreateNetworkResponse) {} 84 85 // DestroyNetwork destroys a previously created network. This rpc is only 86 // implemented if the driver needs to manage network namespace creation. 87 rpc DestroyNetwork(DestroyNetworkRequest) returns (DestroyNetworkResponse) {} 88 } 89 90 message TaskConfigSchemaRequest {} 91 92 message TaskConfigSchemaResponse { 93 94 // Spec is the configuration schema for the job driver config stanza 95 hashicorp.nomad.plugins.shared.hclspec.Spec spec = 1; 96 } 97 98 message CapabilitiesRequest {} 99 100 message CapabilitiesResponse { 101 102 // Capabilities provides a way for the driver to denote if it implements 103 // non-core RPCs. Some Driver service RPCs expose additional information 104 // or functionality outside of the core task management functions. These 105 // RPCs are only implemented if the driver sets the corresponding capability. 106 DriverCapabilities capabilities = 1; 107 } 108 109 message FingerprintRequest {} 110 111 message FingerprintResponse { 112 113 114 // Attributes are key/value pairs that annotate the nomad client and can be 115 // used in scheduling constraints and affinities. 116 map<string, hashicorp.nomad.plugins.shared.structs.Attribute> attributes = 1; 117 118 enum HealthState { 119 UNDETECTED = 0; 120 UNHEALTHY = 1; 121 HEALTHY = 2; 122 123 } 124 125 // Health is used to determine the state of the health the driver is in. 126 // Health can be one of the following states: 127 // * UNDETECTED: driver dependencies are not met and the driver can not start 128 // * UNHEALTHY: driver dependencies are met but the driver is unable to 129 // perform operations due to some other problem 130 // * HEALTHY: driver is able to perform all operations 131 HealthState health = 2; 132 133 // HealthDescription is a human readable message describing the current 134 // state of driver health 135 string health_description = 3; 136 } 137 138 message RecoverTaskRequest { 139 140 // TaskId is the ID of the target task 141 string task_id = 1; 142 143 // Handle is the TaskHandle returned from StartTask 144 TaskHandle handle = 2; 145 } 146 147 message RecoverTaskResponse {} 148 149 message StartTaskRequest { 150 151 // Task configuration to launch 152 TaskConfig task = 1; 153 154 } 155 156 message StartTaskResponse { 157 158 enum Result { 159 SUCCESS = 0; 160 RETRY = 1; 161 FATAL = 2; 162 } 163 164 // Result is set depending on the type of error that occurred while starting 165 // a task: 166 // 167 // * SUCCESS: No error occurred, handle is set 168 // * RETRY: An error occurred, but is recoverable and the RPC should be retried 169 // * FATAL: A fatal error occurred and is not likely to succeed if retried 170 // 171 // If Result is not successful, the DriverErrorMsg will be set. 172 Result result = 1; 173 174 // DriverErrorMsg is set if an error occurred 175 string driver_error_msg = 2; 176 177 // Handle is opaque to the client, but must be stored in order to recover 178 // the task. 179 TaskHandle handle = 3; 180 181 // NetworkOverride is set if the driver sets network settings and the service ip/port 182 // needs to be set differently. 183 NetworkOverride network_override = 4; 184 } 185 186 message WaitTaskRequest { 187 188 // TaskId is the ID of the target task 189 string task_id = 1; 190 } 191 192 message WaitTaskResponse { 193 194 // Result is the exit status of the task 195 ExitResult result = 1; 196 // Err is set if any driver error occurred while waiting for the task 197 string err = 2; 198 } 199 200 message StopTaskRequest { 201 202 // TaskId is the ID of the target task 203 string task_id = 1; 204 205 // Timeout defines the amount of time to wait before forcefully killing 206 // the task. For example, on Unix clients, this means sending a SIGKILL to 207 // the process. 208 google.protobuf.Duration timeout = 2; 209 210 // Signal can be set to override the Task's configured shutdown signal 211 string signal = 3; 212 } 213 214 message StopTaskResponse {} 215 216 message DestroyTaskRequest { 217 218 // TaskId is the ID of the target task 219 string task_id = 1; 220 221 // Force destroys the task even if it is still in a running state 222 bool force = 2; 223 } 224 225 message DestroyTaskResponse {} 226 227 message InspectTaskRequest { 228 229 // TaskId is the ID of the target task 230 string task_id = 1; 231 } 232 233 message InspectTaskResponse { 234 235 // Task details 236 TaskStatus task = 1; 237 238 // Driver details for task 239 TaskDriverStatus driver = 2; 240 241 // NetworkOverride info if set 242 NetworkOverride network_override = 3; 243 } 244 245 message TaskStatsRequest { 246 247 // TaskId is the ID of the target task 248 string task_id = 1; 249 250 // CollectionInterval is the interval at which to stream stats to the caller 251 google.protobuf.Duration collection_interval = 2; 252 } 253 254 message TaskStatsResponse { 255 256 // Stats for the task 257 TaskStats stats = 1; 258 } 259 260 message TaskEventsRequest {} 261 262 message SignalTaskRequest { 263 264 // TaskId is the ID of the target task 265 string task_id = 1; 266 267 // Signal is the operating system signal to send to the task. Ex: SIGHUP 268 string signal = 2; 269 } 270 271 message SignalTaskResponse {} 272 273 message ExecTaskRequest { 274 275 // TaskId is the ID of the target task 276 string task_id = 1; 277 278 // Command is the command to execute in the task environment 279 repeated string command = 2; 280 281 // Timeout is the amount of time to wait for the command to stop. 282 // Defaults to 0 (run forever) 283 google.protobuf.Duration timeout = 3; 284 } 285 286 message ExecTaskResponse { 287 288 // Stdout from the exec 289 bytes stdout = 1; 290 291 // Stderr from the exec 292 bytes stderr = 2; 293 294 // Result from the exec 295 ExitResult result = 3; 296 } 297 298 message ExecTaskStreamingIOOperation { 299 bytes data = 1; 300 bool close = 2; 301 } 302 303 message ExecTaskStreamingRequest { 304 message Setup { 305 string task_id = 1; 306 repeated string command = 2; 307 bool tty = 3; 308 } 309 310 message TerminalSize { 311 int32 height = 1; 312 int32 width = 2; 313 } 314 315 Setup setup = 1; 316 TerminalSize tty_size = 2; 317 ExecTaskStreamingIOOperation stdin = 3; 318 } 319 320 message ExecTaskStreamingResponse { 321 ExecTaskStreamingIOOperation stdout = 1; 322 ExecTaskStreamingIOOperation stderr = 2; 323 324 bool exited = 3; 325 ExitResult result = 4; 326 } 327 328 message CreateNetworkRequest { 329 330 // AllocID of the allocation the network is associated with 331 string alloc_id = 1; 332 } 333 334 message CreateNetworkResponse { 335 336 NetworkIsolationSpec isolation_spec = 1; 337 338 // created indicates that the network namespace is newly created 339 // as a result of this request. if false, the NetworkIsolationSpec 340 // value returned is an existing spec. 341 bool created = 2; 342 } 343 344 message DestroyNetworkRequest { 345 346 // AllocID of the allocation the network is associated with 347 string alloc_id = 1; 348 349 NetworkIsolationSpec isolation_spec = 2; 350 } 351 352 message DestroyNetworkResponse {} 353 354 message DriverCapabilities { 355 356 // SendSignals indicates that the driver can send process signals (ex. SIGUSR1) 357 // to the task. 358 bool send_signals = 1; 359 360 // Exec indicates that the driver supports executing arbitrary commands 361 // in the task's execution environment. 362 bool exec = 2; 363 364 enum FSIsolation { 365 NONE = 0; 366 CHROOT = 1; 367 IMAGE = 2; 368 } 369 // FsIsolation indicates what kind of filesystem isolation a driver supports. 370 FSIsolation fs_isolation = 3; 371 372 repeated NetworkIsolationSpec.NetworkIsolationMode network_isolation_modes = 4; 373 374 bool must_create_network = 5; 375 376 enum MountConfigs { 377 // buf:lint:ignore ENUM_NO_ALLOW_ALIAS 378 option allow_alias = true; 379 UNKNOWN_MOUNTS = 0; // treated as ANY_MOUNTS for backwards compatibility 380 ANY_MOUNTS = 0; 381 NO_MOUNTS = 1; 382 } 383 // MountConfigs indicates whether the driver supports mount configurations. 384 MountConfigs mount_configs = 6; 385 } 386 387 message NetworkIsolationSpec { 388 enum NetworkIsolationMode { 389 HOST = 0; 390 GROUP = 1; 391 TASK = 2; 392 NONE = 3; 393 } 394 NetworkIsolationMode mode = 1; 395 396 string path = 2; 397 398 map<string,string> labels = 3; 399 } 400 401 message DNSConfig { 402 repeated string servers = 1; 403 repeated string searches = 2; 404 repeated string options = 3; 405 } 406 407 message TaskConfig { 408 409 // Id of the task, recommended to the globally unique, must be unique to the driver. 410 string id = 1; 411 412 // Name of the task 413 string name = 2; 414 415 // MsgpackDriverConfig is the encoded driver configuation of the task 416 bytes msgpack_driver_config = 3; 417 418 // Env is the a set of key/value pairs to be set as environment variables 419 map<string, string> env = 4; 420 421 // DeviceEnv is the set of environment variables that are defined by device 422 // plugins. This allows the driver to differentiate environment variables 423 // set by the device plugins and those by the user. When populating the 424 // task's environment env should be used. 425 map<string, string> device_env = 5; 426 427 // Resources defines the resources to isolate 428 Resources resources = 6; 429 430 // Mounts is a list of targets to bind mount into the task directory 431 repeated Mount mounts = 7; 432 433 // Devices is a list of system devices to mount into the task's execution 434 // environment. 435 repeated Device devices = 8; 436 437 // User defines the operating system user the tasks should run as 438 string user = 9; 439 440 // AllocDir is the directory on the host where the allocation directory 441 // exists. 442 string alloc_dir = 10; 443 444 // StdoutPath is the path to the file to open and write task stdout to 445 string stdout_path = 11; 446 447 // StderrPath is the path to the file to open and write task stderr to 448 string stderr_path = 12; 449 450 // TaskGroupName is the name of the task group which this task is a member of 451 string task_group_name = 13; 452 453 // JobName is the name of the job of which this task is part of 454 string job_name = 14; 455 456 // AllocId is the ID of the associated allocation 457 string alloc_id = 15; 458 459 // NetworkIsolationSpec specifies the configuration for the network namespace 460 // to use for the task. *Only supported on Linux 461 NetworkIsolationSpec network_isolation_spec = 16; 462 463 // DNSConfig is the configuration for task DNS resolvers and other options 464 DNSConfig dns = 17; 465 } 466 467 message Resources { 468 469 // AllocatedResources are the resources set for the task 470 AllocatedTaskResources allocated_resources = 1; 471 472 // LinuxResources are the computed values to set for specific Linux features 473 LinuxResources linux_resources = 2; 474 475 // Ports are the allocated port mappings for the allocation. 476 // A task may use these to manually configure port mapping if shared network namespaces aren't being used. 477 repeated PortMapping ports = 3; 478 } 479 480 message AllocatedTaskResources { 481 AllocatedCpuResources cpu = 1; 482 AllocatedMemoryResources memory = 2; 483 repeated NetworkResource networks = 5; 484 } 485 486 message AllocatedCpuResources { 487 int64 cpu_shares = 1; 488 } 489 490 message AllocatedMemoryResources { 491 int64 memory_mb = 2; 492 } 493 494 message NetworkResource { 495 string device = 1; 496 string cidr = 2; 497 string ip = 3; 498 int32 mbits = 4; 499 repeated NetworkPort reserved_ports = 5; 500 repeated NetworkPort dynamic_ports = 6; 501 } 502 503 message NetworkPort { 504 string label = 1; 505 int32 value = 2; 506 } 507 508 message PortMapping { 509 string label = 1; 510 int32 value = 2; 511 int32 to = 3; 512 string host_ip = 4; 513 } 514 515 message LinuxResources { 516 517 // CPU CFS (Completely Fair Scheduler) period. Default: 0 (not specified) 518 int64 cpu_period = 1; 519 // CPU CFS (Completely Fair Scheduler) quota. Default: 0 (not specified) 520 int64 cpu_quota = 2; 521 // CPU shares (relative weight vs. other containers). Default: 0 (not specified) 522 int64 cpu_shares = 3; 523 // Memory limit in bytes. Default: 0 (not specified) 524 int64 memory_limit_bytes = 4; 525 // OOMScoreAdj adjusts the oom-killer score. Default: 0 (not specified) 526 int64 oom_score_adj = 5; 527 // CpusetCpus constrains the allowed set of logical CPUs. Default: "" (not specified) 528 string cpuset_cpus = 6; 529 // CpusetMems constrains the allowed set of memory nodes. Default: "" (not specified) 530 string cpuset_mems = 7; 531 // PercentTicks is a compatibility option for docker and should not be used 532 // buf:lint:ignore FIELD_LOWER_SNAKE_CASE 533 double PercentTicks = 8; 534 } 535 536 message Mount { 537 538 // TaskPath is the file path within the task directory to mount to 539 string task_path = 1; 540 541 // HostPath is the file path on the host to mount from 542 string host_path = 2; 543 544 // Readonly if set true, mounts the path in readonly mode 545 bool readonly = 3; 546 } 547 548 message Device { 549 550 // TaskPath is the file path within the task to mount the device to 551 string task_path = 1; 552 553 // HostPath is the path on the host to the source device 554 string host_path = 2; 555 556 // CgroupPermissions defines the Cgroup permissions of the device. 557 // One or more of the following options can be set: 558 // * r - allows the task to read from the specified device. 559 // * w - allows the task to write to the specified device. 560 // * m - allows the task to create device files that do not yet exist. 561 // 562 // Example: "rw" 563 string cgroup_permissions = 3; 564 } 565 566 enum TaskState { 567 UNKNOWN = 0; 568 RUNNING = 1; 569 EXITED = 2; 570 } 571 572 // TaskHandle is created when starting a task and is used to recover task 573 message TaskHandle { 574 575 // Version is used by the driver to version the DriverState schema. 576 // Version 0 is reserved by Nomad and should not be used. 577 int32 version = 1; 578 579 // Config is the TaskConfig for the task 580 TaskConfig config = 2; 581 582 // State is the state of the task's execution 583 TaskState state = 3; 584 585 // DriverState is the encoded state for the specific driver 586 bytes driver_state = 4; 587 } 588 589 // NetworkOverride contains network settings which the driver may override 590 // for the task, such as when the driver is setting up the task's network. 591 message NetworkOverride { 592 593 // PortMap can be set to replace ports with driver-specific mappings 594 map<string,int32> port_map = 1; 595 596 // Addr is the IP address for the task created by the driver 597 string addr = 2; 598 599 // AutoAdvertise indicates whether the driver thinks services that choose 600 // to auto_advertise_addresses should use this IP instead of the host's. 601 bool auto_advertise = 3; 602 } 603 604 // ExitResult contains information about the exit status of a task 605 message ExitResult { 606 607 // ExitCode returned from the task on exit 608 int32 exit_code = 1; 609 610 // Signal is set if a signal was sent to the task 611 int32 signal = 2; 612 613 // OomKilled is true if the task exited as a result of the OOM Killer 614 bool oom_killed = 3; 615 616 } 617 618 // TaskStatus includes information of a specific task 619 message TaskStatus { 620 string id = 1; 621 string name = 2; 622 623 // State is the state of the task's execution 624 TaskState state = 3; 625 626 // StartedAt is the timestamp when the task was started 627 google.protobuf.Timestamp started_at = 4; 628 629 // CompletedAt is the timestamp when the task exited. 630 // If the task is still running, CompletedAt will not be set 631 google.protobuf.Timestamp completed_at = 5; 632 633 // Result is set when CompletedAt is set. 634 ExitResult result = 6; 635 } 636 637 message TaskDriverStatus { 638 639 // Attributes is a set of string/string key value pairs specific to the 640 // implementing driver 641 map<string, string> attributes = 1; 642 } 643 644 message TaskStats { 645 646 // Id of the task 647 string id = 1; 648 649 // Timestamp for which the stats were collected 650 google.protobuf.Timestamp timestamp = 2; 651 652 // AggResourceUsage is the aggreate usage of all processes 653 TaskResourceUsage agg_resource_usage = 3; 654 655 // ResourceUsageByPid breaks the usage stats by process 656 map<string, TaskResourceUsage> resource_usage_by_pid = 4; 657 } 658 659 message TaskResourceUsage { 660 661 // CPU usage stats 662 CPUUsage cpu = 1; 663 664 // Memory usage stats 665 MemoryUsage memory = 2; 666 } 667 668 message CPUUsage { 669 670 double system_mode = 1; 671 double user_mode = 2; 672 double total_ticks = 3; 673 uint64 throttled_periods = 4; 674 uint64 throttled_time = 5; 675 double percent = 6; 676 677 enum Fields { 678 SYSTEM_MODE = 0; 679 USER_MODE = 1; 680 TOTAL_TICKS = 2; 681 THROTTLED_PERIODS = 3; 682 THROTTLED_TIME = 4; 683 PERCENT = 5; 684 } 685 // MeasuredFields indicates which fields were actually sampled 686 repeated Fields measured_fields = 7; 687 } 688 689 message MemoryUsage { 690 uint64 rss = 1; 691 uint64 cache = 2; 692 uint64 max_usage = 3; 693 uint64 kernel_usage = 4; 694 uint64 kernel_max_usage = 5; 695 uint64 usage = 7; 696 uint64 swap = 8; 697 698 enum Fields { 699 RSS = 0; 700 CACHE = 1; 701 MAX_USAGE = 2; 702 KERNEL_USAGE = 3; 703 KERNEL_MAX_USAGE = 4; 704 USAGE = 5; 705 SWAP = 6; 706 } 707 // MeasuredFields indicates which fields were actually sampled 708 repeated Fields measured_fields = 6; 709 } 710 711 message DriverTaskEvent { 712 713 // TaskId is the id of the task for the event 714 string task_id = 1; 715 716 // AllocId of the task for the event 717 string alloc_id = 2; 718 719 // TaskName is the name of the task for the event 720 string task_name = 3; 721 722 // Timestamp when the event occurred 723 google.protobuf.Timestamp timestamp = 4; 724 725 // Message is the body of the event 726 string message = 5; 727 728 // Annotations allows for additional key/value data to be sent along with the event 729 map<string,string> annotations = 6; 730 }