syntax = "proto3";

package flyteidl.admin;
option go_package = "github.com/lyft/flyteidl/gen/pb-go/flyteidl/admin";

import "flyteidl/admin/common.proto";
import "flyteidl/core/execution.proto";

// Defines a resource that can be configured by customizable Project-, ProjectDomain- or WorkflowAttributes
// based on matching tags.
enum MatchableResource {
  // Applies to customizable task resource requests and limits.
  TASK_RESOURCE = 0;

  // Applies to configuring templated kubernetes cluster resources.
  CLUSTER_RESOURCE = 1;

  // Configures task and dynamic task execution queue assignment.
  EXECUTION_QUEUE = 2;

  // Configures the K8s cluster label to be used for execution to be run
  EXECUTION_CLUSTER_LABEL = 3;

  // Configures default quality of service when undefined in an execution spec.
  QUALITY_OF_SERVICE_SPECIFICATION = 4;

  // Selects configurable plugin implementation behavior for a given task type.
  PLUGIN_OVERRIDE = 5;
}

message TaskResourceSpec {
  string cpu = 1;

  string gpu = 2;

  string memory = 3;

  string storage = 4;  
}

message TaskResourceAttributes {
  TaskResourceSpec defaults = 1;

  TaskResourceSpec limits = 2;
}

message ClusterResourceAttributes {
  // Custom resource attributes which will be applied in cluster resource creation (e.g. quotas).
  // Map keys are the *case-sensitive* names of variables in templatized resource files.
  // Map values should be the custom values which get substituted during resource creation.
  map<string, string> attributes = 1;
}

message ExecutionQueueAttributes {
  // Tags used for assigning execution queues for tasks defined within this project.
  repeated string tags           = 1; 
}

message ExecutionClusterLabel {
  // Label value to determine where the execution will be run
  string value	= 1;
}

// This MatchableAttribute configures selecting alternate plugin implementations for a given task type.
// In addition to an override implementation a selection of fallbacks can be provided or other modes
// for handling cases where the desired plugin override is not enabled in a given Flyte deployment.
message PluginOverride {
  // A predefined yet extensible Task type identifier.
  string task_type = 1;

  // A set of plugin ids which should handle tasks of this type instead of the default registered plugin. The list will be tried in order until a plugin is found with that id.
  repeated string plugin_id = 2;

  enum MissingPluginBehavior {
    FAIL = 0;

    // Uses the system-configured default implementation.
    USE_DEFAULT = 1;
  }
  
  // Defines the behavior when no plugin from the plugin_id list is not found.
  MissingPluginBehavior missing_plugin_behavior = 4;
}


message PluginOverrides {
  repeated PluginOverride overrides = 1;
}

// Generic container for encapsulating all types of the above attributes messages.
message MatchingAttributes {
  oneof target {
    TaskResourceAttributes task_resource_attributes = 1; 

    ClusterResourceAttributes cluster_resource_attributes = 2; 

    ExecutionQueueAttributes execution_queue_attributes = 3;

    ExecutionClusterLabel execution_cluster_label = 4;

    core.QualityOfService quality_of_service = 5;

    PluginOverrides plugin_overrides = 6;
  }
}

// Represents a custom set of attributes applied for either a domain; a domain and project; or
// domain, project and workflow name.
message MatchableAttributesConfiguration {
    MatchingAttributes attributes = 1;

    string domain = 2;

    string project = 3;

    string workflow = 4;

    string launch_plan = 5;
}

// Request all matching resource attributes.
message ListMatchableAttributesRequest {
    MatchableResource resource_type = 1;
}

// Response for a request for all matching resource attributes.
message ListMatchableAttributesResponse {
    repeated MatchableAttributesConfiguration configurations = 1;
}
