github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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 // Hostname of the network namespace 334 string hostname = 2; 335 } 336 337 message CreateNetworkResponse { 338 339 NetworkIsolationSpec isolation_spec = 1; 340 341 // created indicates that the network namespace is newly created 342 // as a result of this request. if false, the NetworkIsolationSpec 343 // value returned is an existing spec. 344 bool created = 2; 345 } 346 347 message DestroyNetworkRequest { 348 349 // AllocID of the allocation the network is associated with 350 string alloc_id = 1; 351 352 NetworkIsolationSpec isolation_spec = 2; 353 } 354 355 message DestroyNetworkResponse {} 356 357 message DriverCapabilities { 358 359 // SendSignals indicates that the driver can send process signals (ex. SIGUSR1) 360 // to the task. 361 bool send_signals = 1; 362 363 // Exec indicates that the driver supports executing arbitrary commands 364 // in the task's execution environment. 365 bool exec = 2; 366 367 enum FSIsolation { 368 NONE = 0; 369 CHROOT = 1; 370 IMAGE = 2; 371 } 372 // FsIsolation indicates what kind of filesystem isolation a driver supports. 373 FSIsolation fs_isolation = 3; 374 375 repeated NetworkIsolationSpec.NetworkIsolationMode network_isolation_modes = 4; 376 377 bool must_create_network = 5; 378 379 enum MountConfigs { 380 // buf:lint:ignore ENUM_NO_ALLOW_ALIAS 381 option allow_alias = true; 382 UNKNOWN_MOUNTS = 0; // treated as ANY_MOUNTS for backwards compatibility 383 ANY_MOUNTS = 0; 384 NO_MOUNTS = 1; 385 } 386 // MountConfigs indicates whether the driver supports mount configurations. 387 MountConfigs mount_configs = 6; 388 389 // remote_tasks indicates whether the driver executes tasks remotely such 390 // on cloud runtimes like AWS ECS. 391 bool remote_tasks = 7; 392 } 393 394 message NetworkIsolationSpec { 395 enum NetworkIsolationMode { 396 HOST = 0; 397 GROUP = 1; 398 TASK = 2; 399 NONE = 3; 400 } 401 NetworkIsolationMode mode = 1; 402 403 string path = 2; 404 405 map<string,string> labels = 3; 406 407 HostsConfig hostsConfig = 4; 408 } 409 410 message HostsConfig { 411 string hostname = 1; 412 string address = 2; 413 } 414 415 message DNSConfig { 416 repeated string servers = 1; 417 repeated string searches = 2; 418 repeated string options = 3; 419 } 420 421 message TaskConfig { 422 423 // Id of the task, recommended to the globally unique, must be unique to the driver. 424 string id = 1; 425 426 // Name of the task 427 string name = 2; 428 429 // MsgpackDriverConfig is the encoded driver configuation of the task 430 bytes msgpack_driver_config = 3; 431 432 // Env is the a set of key/value pairs to be set as environment variables 433 map<string, string> env = 4; 434 435 // DeviceEnv is the set of environment variables that are defined by device 436 // plugins. This allows the driver to differentiate environment variables 437 // set by the device plugins and those by the user. When populating the 438 // task's environment env should be used. 439 map<string, string> device_env = 5; 440 441 // Resources defines the resources to isolate 442 Resources resources = 6; 443 444 // Mounts is a list of targets to bind mount into the task directory 445 repeated Mount mounts = 7; 446 447 // Devices is a list of system devices to mount into the task's execution 448 // environment. 449 repeated Device devices = 8; 450 451 // User defines the operating system user the tasks should run as 452 string user = 9; 453 454 // AllocDir is the directory on the host where the allocation directory 455 // exists. 456 string alloc_dir = 10; 457 458 // StdoutPath is the path to the file to open and write task stdout to 459 string stdout_path = 11; 460 461 // StderrPath is the path to the file to open and write task stderr to 462 string stderr_path = 12; 463 464 // TaskGroupName is the name of the task group which this task is a member of 465 string task_group_name = 13; 466 467 // JobName is the name of the job of which this task is part of 468 string job_name = 14; 469 470 // AllocId is the ID of the associated allocation 471 string alloc_id = 15; 472 473 // NetworkIsolationSpec specifies the configuration for the network namespace 474 // to use for the task. *Only supported on Linux 475 NetworkIsolationSpec network_isolation_spec = 16; 476 477 // DNSConfig is the configuration for task DNS resolvers and other options 478 DNSConfig dns = 17; 479 } 480 481 message Resources { 482 483 // AllocatedResources are the resources set for the task 484 AllocatedTaskResources allocated_resources = 1; 485 486 // LinuxResources are the computed values to set for specific Linux features 487 LinuxResources linux_resources = 2; 488 489 // Ports are the allocated port mappings for the allocation. 490 // A task may use these to manually configure port mapping if shared network namespaces aren't being used. 491 repeated PortMapping ports = 3; 492 } 493 494 message AllocatedTaskResources { 495 AllocatedCpuResources cpu = 1; 496 AllocatedMemoryResources memory = 2; 497 repeated NetworkResource networks = 5; 498 } 499 500 message AllocatedCpuResources { 501 int64 cpu_shares = 1; 502 } 503 504 message AllocatedMemoryResources { 505 int64 memory_mb = 2; 506 int64 memory_max_mb = 3; 507 } 508 509 message NetworkResource { 510 string device = 1; 511 string cidr = 2; 512 string ip = 3; 513 int32 mbits = 4; 514 repeated NetworkPort reserved_ports = 5; 515 repeated NetworkPort dynamic_ports = 6; 516 } 517 518 message NetworkPort { 519 string label = 1; 520 int32 value = 2; 521 } 522 523 message PortMapping { 524 string label = 1; 525 int32 value = 2; 526 int32 to = 3; 527 string host_ip = 4; 528 } 529 530 message LinuxResources { 531 532 // CPU CFS (Completely Fair Scheduler) period. Default: 0 (not specified) 533 int64 cpu_period = 1; 534 // CPU CFS (Completely Fair Scheduler) quota. Default: 0 (not specified) 535 int64 cpu_quota = 2; 536 // CPU shares (relative weight vs. other containers). Default: 0 (not specified) 537 int64 cpu_shares = 3; 538 // Memory limit in bytes. Default: 0 (not specified) 539 int64 memory_limit_bytes = 4; 540 // OOMScoreAdj adjusts the oom-killer score. Default: 0 (not specified) 541 int64 oom_score_adj = 5; 542 543 // CpusetCpus constrains the allowed set of logical CPUs. Default: "" (not specified) 544 // This field exists to support drivers which can't set a cgroup path. 545 string cpuset_cpus = 6; 546 // Previously cpuset_mems fields never set by the Nomad client 547 reserved 7; 548 reserved "cpuset_mems"; 549 // CpusetCgroup is the path to the cpuset cgroup managed by the client 550 string cpuset_cgroup = 9; 551 552 // PercentTicks is a compatibility option for docker and should not be used 553 // buf:lint:ignore FIELD_LOWER_SNAKE_CASE 554 double PercentTicks = 8; 555 } 556 557 message Mount { 558 559 // TaskPath is the file path within the task directory to mount to 560 string task_path = 1; 561 562 // HostPath is the file path on the host to mount from 563 string host_path = 2; 564 565 // Readonly if set true, mounts the path in readonly mode 566 bool readonly = 3; 567 568 // Propagation mode for the mount. Not exactly the same as the unix mount 569 // propagation flags. See callsite usage for details. 570 string propagation_mode = 4; 571 } 572 573 message Device { 574 575 // TaskPath is the file path within the task to mount the device to 576 string task_path = 1; 577 578 // HostPath is the path on the host to the source device 579 string host_path = 2; 580 581 // CgroupPermissions defines the Cgroup permissions of the device. 582 // One or more of the following options can be set: 583 // * r - allows the task to read from the specified device. 584 // * w - allows the task to write to the specified device. 585 // * m - allows the task to create device files that do not yet exist. 586 // 587 // Example: "rw" 588 string cgroup_permissions = 3; 589 } 590 591 enum TaskState { 592 UNKNOWN = 0; 593 RUNNING = 1; 594 EXITED = 2; 595 } 596 597 // TaskHandle is created when starting a task and is used to recover task 598 message TaskHandle { 599 600 // Version is used by the driver to version the DriverState schema. 601 // Version 0 is reserved by Nomad and should not be used. 602 int32 version = 1; 603 604 // Config is the TaskConfig for the task 605 TaskConfig config = 2; 606 607 // State is the state of the task's execution 608 TaskState state = 3; 609 610 // DriverState is the encoded state for the specific driver 611 bytes driver_state = 4; 612 } 613 614 // NetworkOverride contains network settings which the driver may override 615 // for the task, such as when the driver is setting up the task's network. 616 message NetworkOverride { 617 618 // PortMap can be set to replace ports with driver-specific mappings 619 map<string,int32> port_map = 1; 620 621 // Addr is the IP address for the task created by the driver 622 string addr = 2; 623 624 // AutoAdvertise indicates whether the driver thinks services that choose 625 // to auto_advertise_addresses should use this IP instead of the host's. 626 bool auto_advertise = 3; 627 } 628 629 // ExitResult contains information about the exit status of a task 630 message ExitResult { 631 632 // ExitCode returned from the task on exit 633 int32 exit_code = 1; 634 635 // Signal is set if a signal was sent to the task 636 int32 signal = 2; 637 638 // OomKilled is true if the task exited as a result of the OOM Killer 639 bool oom_killed = 3; 640 641 } 642 643 // TaskStatus includes information of a specific task 644 message TaskStatus { 645 string id = 1; 646 string name = 2; 647 648 // State is the state of the task's execution 649 TaskState state = 3; 650 651 // StartedAt is the timestamp when the task was started 652 google.protobuf.Timestamp started_at = 4; 653 654 // CompletedAt is the timestamp when the task exited. 655 // If the task is still running, CompletedAt will not be set 656 google.protobuf.Timestamp completed_at = 5; 657 658 // Result is set when CompletedAt is set. 659 ExitResult result = 6; 660 } 661 662 message TaskDriverStatus { 663 664 // Attributes is a set of string/string key value pairs specific to the 665 // implementing driver 666 map<string, string> attributes = 1; 667 } 668 669 message TaskStats { 670 671 // Id of the task 672 string id = 1; 673 674 // Timestamp for which the stats were collected 675 google.protobuf.Timestamp timestamp = 2; 676 677 // AggResourceUsage is the aggreate usage of all processes 678 TaskResourceUsage agg_resource_usage = 3; 679 680 // ResourceUsageByPid breaks the usage stats by process 681 map<string, TaskResourceUsage> resource_usage_by_pid = 4; 682 } 683 684 message TaskResourceUsage { 685 686 // CPU usage stats 687 CPUUsage cpu = 1; 688 689 // Memory usage stats 690 MemoryUsage memory = 2; 691 } 692 693 message CPUUsage { 694 695 double system_mode = 1; 696 double user_mode = 2; 697 double total_ticks = 3; 698 uint64 throttled_periods = 4; 699 uint64 throttled_time = 5; 700 double percent = 6; 701 702 enum Fields { 703 SYSTEM_MODE = 0; 704 USER_MODE = 1; 705 TOTAL_TICKS = 2; 706 THROTTLED_PERIODS = 3; 707 THROTTLED_TIME = 4; 708 PERCENT = 5; 709 } 710 // MeasuredFields indicates which fields were actually sampled 711 repeated Fields measured_fields = 7; 712 } 713 714 message MemoryUsage { 715 uint64 rss = 1; 716 uint64 cache = 2; 717 uint64 max_usage = 3; 718 uint64 kernel_usage = 4; 719 uint64 kernel_max_usage = 5; 720 uint64 usage = 7; 721 uint64 swap = 8; 722 723 enum Fields { 724 RSS = 0; 725 CACHE = 1; 726 MAX_USAGE = 2; 727 KERNEL_USAGE = 3; 728 KERNEL_MAX_USAGE = 4; 729 USAGE = 5; 730 SWAP = 6; 731 } 732 // MeasuredFields indicates which fields were actually sampled 733 repeated Fields measured_fields = 6; 734 } 735 736 message DriverTaskEvent { 737 738 // TaskId is the id of the task for the event 739 string task_id = 1; 740 741 // AllocId of the task for the event 742 string alloc_id = 2; 743 744 // TaskName is the name of the task for the event 745 string task_name = 3; 746 747 // Timestamp when the event occurred 748 google.protobuf.Timestamp timestamp = 4; 749 750 // Message is the body of the event 751 string message = 5; 752 753 // Annotations allows for additional key/value data to be sent along with the event 754 map<string,string> annotations = 6; 755 }