Skip to content
Permalink
Browse files

Add Extended Resources to core API

Extended resources allows nodes to advertise different resources
with different attributes.
They also allow you to request resources with specific attributes
in your pod spec.

e.g:

apiVersion: v1
kind: Pod
metadata:
  name: gpu-pod-2
spec:
  containers:
    - name: cuda-container
      image: nvidia/cuda:9.0-base
      command: ["sleep"]
      args: ["100000"]
      extendedResourceRequests: ["nvidia-gpu"]
  extendedResources:
    - name: "nvidia-gpu"
      requirements:
        nvidia.com/gpu: 1
      affinity:
        required:
          - key: "nvidia.com/gpu-memory"
            operator: "Gt"
            values: ["8000"]
  • Loading branch information...
RenaudWasTaken committed Apr 23, 2018
1 parent abfbdee commit 355aff2ffc31d6403c78b68d94fa263b0de35188
Showing with 139 additions and 0 deletions.
  1. +70 −0 pkg/apis/core/types.go
  2. +69 −0 staging/src/k8s.io/api/core/v1/types.go
@@ -1985,6 +1985,9 @@ type Container struct {
StdinOnce bool
// +optional
TTY bool
// The names of the requested Extended Resources
// +optional
ExtendedResourceRequests []string
}

// Handler defines a specific action that should be taken
@@ -2379,6 +2382,15 @@ type NodeAffinity struct {
PreferredDuringSchedulingIgnoredDuringExecution []PreferredSchedulingTerm
}

type ResourceSelector NodeSelectorRequirement

// ExtendedResourceAffinity is the affinity used for selecting a device
// You can use this as part of the PodExtendedResource structure.
type ExtendedResourceAffinity struct {
// +optional
Required []ResourceSelector
}

// An empty preferred scheduling term matches all objects with implicit weight 0
// (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op).
type PreferredSchedulingTerm struct {
@@ -2561,6 +2573,9 @@ type PodSpec struct {
// configuration based on DNSPolicy.
// +optional
DNSConfig *PodDNSConfig
// List of Extended resources belonging to the pod.
// +optional
ExtendedResources []PodExtendedResource
}

// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
@@ -3406,6 +3421,9 @@ type NodeStatus struct {
// List of volumes that are attached to the node.
// +optional
VolumesAttached []AttachedVolume
// ExtendedResources is a map of available resources with
// their attributes
ExtendedResources ExtendedResourceMap
}

type UniqueVolumeName string
@@ -3562,6 +3580,54 @@ const (
// ResourceList is a set of (resource name, quantity) pairs.
type ResourceList map[ResourceName]resource.Quantity

const (
// ExtendedResourcesHealthy means that the resource is healthy
ExtendedResourcesHealthy = "Healthy"
// ExtendedResourcesUnhealthy means that the resource is unhealthy
ExtendedResourcesUnhealthy = "Unhealthy"
)

type ExtendedResourceBinding map[string]ExtendedResourceList

type ExtendedResourceMap map[ResourceName]ExtendedResourceDomain

type ExtendedResourceDomain struct {
// Resources is the map of devices owned by a resource
Resources map[string]ExtendedResource
}

type ExtendedResource struct {
// ID is the ID of the device
ID string
// Health is the state of the device
Health string
// Attributes is the map of attributes of the device
Attributes map[string]string
}

type PodExtendedResource struct {
// The name of the Extended Resource
Name string
// Describes the amount of the resource needed can only be one element
// +optional
Resources ResourceRequirements
// The resource Attributes requested
// +optional
Affinity ExtendedResourceAffinity
// The resource Attributes requested
// +optional
Annotations map[string]string
// The assigned resources
// +optional
Assigned []string
}

type ExtendedResourceList struct {
// The ID of the resources assigned to this Extended resource
// +optional
Resources []string
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -3915,6 +3981,10 @@ type ObjectReference struct {
// TODO: this design is not final and this field is subject to change in the future.
// +optional
FieldPath string
// Extended Resources are the resources bound to a pod.
// The mapping is from the pod Extended Resource name to the Resource ID
// +optional
ExtendedResources ExtendedResourceBinding
}

// LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace.
@@ -2199,6 +2199,9 @@ type Container struct {
// Default is false.
// +optional
TTY bool `json:"tty,omitempty" protobuf:"varint,18,opt,name=tty"`
// ExtendedResources is the resources assigned to the container
// +optional
ExtendedResourceRequests []string `json:"extendedResourceRequests,omitempty" protobuf:"bytes,22,opt,name=extendedResourceRequests"`
}

// Handler defines a specific action that should be taken
@@ -2625,6 +2628,15 @@ type NodeAffinity struct {
PreferredDuringSchedulingIgnoredDuringExecution []PreferredSchedulingTerm `json:"preferredDuringSchedulingIgnoredDuringExecution,omitempty" protobuf:"bytes,2,rep,name=preferredDuringSchedulingIgnoredDuringExecution"`
}

type ResourceSelector NodeSelectorRequirement

// ExtendedResourceAffinity is the affinity used for selecting a device
// You can use this as part of the PodExtendedResource structure.
type ExtendedResourceAffinity struct {
// +optional
Required []ResourceSelector `json:"required,omitempty" protobuf:"bytes,1,rep,name=required"`
}

// An empty preferred scheduling term matches all objects with implicit weight 0
// (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op).
type PreferredSchedulingTerm struct {
@@ -2868,6 +2880,9 @@ type PodSpec struct {
// This is an alpha feature introduced in v1.9 and CustomPodDNS feature gate must be enabled to use it.
// +optional
DNSConfig *PodDNSConfig `json:"dnsConfig,omitempty" protobuf:"bytes,26,opt,name=dnsConfig"`
// List of Extended resources belonging to the pod.
// +optional
ExtendedResources []PodExtendedResource `json:"extendedResources,omitempty" protobuf:"bytes,27,opt,name=extendedResources"`
}

// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
@@ -3830,6 +3845,9 @@ type NodeStatus struct {
// List of volumes that are attached to the node.
// +optional
VolumesAttached []AttachedVolume `json:"volumesAttached,omitempty" protobuf:"bytes,10,rep,name=volumesAttached"`
// ExtendedResources is the map of resources
// +optional
ExtendedResources ExtendedResourceMap `json:"extendedResources,omitempty" protobuf:"bytes,11,opt,name=extendedResources"`
}

type UniqueVolumeName string
@@ -3990,6 +4008,54 @@ const (
// ResourceList is a set of (resource name, quantity) pairs.
type ResourceList map[ResourceName]resource.Quantity

const (
// ExtendedResourcesHealthy means that the resource is healthy
ExtendedResourcesHealthy = "Healthy"
// ExtendedResourcesUnhealthy means that the resource is unhealthy
ExtendedResourcesUnhealthy = "Unhealthy"
)

type ExtendedResourceBinding map[string]ExtendedResourceList

type ExtendedResourceMap map[ResourceName]ExtendedResourceDomain

type ExtendedResourceDomain struct {
// Resources is the map of devices owned by a resource
Resources map[string]ExtendedResource `json:"resources,omitempty" protobuf:"bytes,1,opt,name=resources"`
}

type ExtendedResource struct {
// ID is the ID of the device
ID string `json:"id,omitempty" protobuf:"bytes,1,opt,name=id"`
// Health is the state of the device
Health string `json:"health,omitempty" protobuf:"bytes,2,opt,name=health"`
// Attributes is the map of attributes of the device
Attributes map[string]string `json:"attributes,omitempty" protobuf:"bytes,3,opt,name=attributes"`
}

type PodExtendedResource struct {
// The name of the Extended Resource
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
// Describes the amount of the resource needed can only be one element
// +optional
Resources ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,2,opt,name=resources"`
// The resource Attributes requested
// +optional
Affinity ExtendedResourceAffinity `json:"affinity,omitempty" protobuf:"bytes,3,opt,name="`
// The resource Attributes requested
// +optional
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,4,rep,name=annotations"`
// The assigned resources
// +optional
Assigned []string `json:"assigned,omitempty" protobuf:"bytes,5,rep,name=assigned"`
}

type ExtendedResourceList struct {
// The ID of the resources assigned to this Extended resource
// +optional
Resources []string `json:"resources,omitempty" protobuf:"bytes,1,rep,name=resources"`
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -4424,6 +4490,9 @@ type ObjectReference struct {
// TODO: this design is not final and this field is subject to change in the future.
// +optional
FieldPath string `json:"fieldPath,omitempty" protobuf:"bytes,7,opt,name=fieldPath"`
// ExtendedResources refers to the resources bound to the pod
// +optional
ExtendedResources ExtendedResourceBinding `json:"extendedResourceBinding,omitempty" protobuf:"bytes,8,opt,name=extendedResourceBinding"`
}

// LocalObjectReference contains enough information to let you locate the

0 comments on commit 355aff2

Please sign in to comment.
You can’t perform that action at this time.