1 /* 2 Copyright 2023 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha2 18 19 import ( 20 "k8s.io/apimachinery/pkg/api/resource" 21 ) 22 23 // NamedResourcesResources is used in ResourceModel. 24 type NamedResourcesResources struct { 25 // The list of all individual resources instances currently available. 26 // 27 // +listType=atomic 28 Instances []NamedResourcesInstance `json:"instances" protobuf:"bytes,1,name=instances"` 29 } 30 31 // NamedResourcesInstance represents one individual hardware instance that can be selected based 32 // on its attributes. 33 type NamedResourcesInstance struct { 34 // Name is unique identifier among all resource instances managed by 35 // the driver on the node. It must be a DNS subdomain. 36 Name string `json:"name" protobuf:"bytes,1,name=name"` 37 38 // Attributes defines the attributes of this resource instance. 39 // The name of each attribute must be unique. 40 // 41 // +listType=atomic 42 // +optional 43 Attributes []NamedResourcesAttribute `json:"attributes,omitempty" protobuf:"bytes,2,opt,name=attributes"` 44 } 45 46 // NamedResourcesAttribute is a combination of an attribute name and its value. 47 type NamedResourcesAttribute struct { 48 // Name is unique identifier among all resource instances managed by 49 // the driver on the node. It must be a DNS subdomain. 50 Name string `json:"name" protobuf:"bytes,1,name=name"` 51 52 NamedResourcesAttributeValue `json:",inline" protobuf:"bytes,2,opt,name=attributeValue"` 53 } 54 55 // The Go field names below have a Value suffix to avoid a conflict between the 56 // field "String" and the corresponding method. That method is required. 57 // The Kubernetes API is defined without that suffix to keep it more natural. 58 59 // NamedResourcesAttributeValue must have one and only one field set. 60 type NamedResourcesAttributeValue struct { 61 // QuantityValue is a quantity. 62 QuantityValue *resource.Quantity `json:"quantity,omitempty" protobuf:"bytes,6,opt,name=quantity"` 63 // BoolValue is a true/false value. 64 BoolValue *bool `json:"bool,omitempty" protobuf:"bytes,2,opt,name=bool"` 65 // IntValue is a 64-bit integer. 66 IntValue *int64 `json:"int,omitempty" protobuf:"varint,7,opt,name=int"` 67 // IntSliceValue is an array of 64-bit integers. 68 IntSliceValue *NamedResourcesIntSlice `json:"intSlice,omitempty" protobuf:"varint,8,rep,name=intSlice"` 69 // StringValue is a string. 70 StringValue *string `json:"string,omitempty" protobuf:"bytes,5,opt,name=string"` 71 // StringSliceValue is an array of strings. 72 StringSliceValue *NamedResourcesStringSlice `json:"stringSlice,omitempty" protobuf:"bytes,9,rep,name=stringSlice"` 73 // VersionValue is a semantic version according to semver.org spec 2.0.0. 74 VersionValue *string `json:"version,omitempty" protobuf:"bytes,10,opt,name=version"` 75 } 76 77 // NamedResourcesIntSlice contains a slice of 64-bit integers. 78 type NamedResourcesIntSlice struct { 79 // Ints is the slice of 64-bit integers. 80 // 81 // +listType=atomic 82 Ints []int64 `json:"ints" protobuf:"bytes,1,opt,name=ints"` 83 } 84 85 // NamedResourcesStringSlice contains a slice of strings. 86 type NamedResourcesStringSlice struct { 87 // Strings is the slice of strings. 88 // 89 // +listType=atomic 90 Strings []string `json:"strings" protobuf:"bytes,1,opt,name=strings"` 91 } 92 93 // NamedResourcesRequest is used in ResourceRequestModel. 94 type NamedResourcesRequest struct { 95 // Selector is a CEL expression which must evaluate to true if a 96 // resource instance is suitable. The language is as defined in 97 // https://kubernetes.io/docs/reference/using-api/cel/ 98 // 99 // In addition, for each type NamedResourcesin AttributeValue there is a map that 100 // resolves to the corresponding value of the instance under evaluation. 101 // For example: 102 // 103 // attributes.quantity["a"].isGreaterThan(quantity("0")) && 104 // attributes.stringslice["b"].isSorted() 105 Selector string `json:"selector" protobuf:"bytes,1,name=selector"` 106 } 107 108 // NamedResourcesFilter is used in ResourceFilterModel. 109 type NamedResourcesFilter struct { 110 // Selector is a CEL expression which must evaluate to true if a 111 // resource instance is suitable. The language is as defined in 112 // https://kubernetes.io/docs/reference/using-api/cel/ 113 // 114 // In addition, for each type NamedResourcesin AttributeValue there is a map that 115 // resolves to the corresponding value of the instance under evaluation. 116 // For example: 117 // 118 // attributes.quantity["a"].isGreaterThan(quantity("0")) && 119 // attributes.stringslice["b"].isSorted() 120 Selector string `json:"selector" protobuf:"bytes,1,name=selector"` 121 } 122 123 // NamedResourcesAllocationResult is used in AllocationResultModel. 124 type NamedResourcesAllocationResult struct { 125 // Name is the name of the selected resource instance. 126 Name string `json:"name" protobuf:"bytes,1,name=name"` 127 } 128