k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/apis/resource/namedresources.go (about)

     1  /*
     2  Copyright 2024 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 resource
    18  
    19  import "k8s.io/apimachinery/pkg/api/resource"
    20  
    21  // NamedResourcesResources is used in ResourceModel.
    22  type NamedResourcesResources struct {
    23  	// The list of all individual resources instances currently available.
    24  	Instances []NamedResourcesInstance
    25  }
    26  
    27  // NamedResourcesInstance represents one individual hardware instance that can be selected based
    28  // on its attributes.
    29  type NamedResourcesInstance struct {
    30  	// Name is unique identifier among all resource instances managed by
    31  	// the driver on the node. It must be a DNS subdomain.
    32  	Name string
    33  
    34  	// Attributes defines the attributes of this resource instance.
    35  	// The name of each attribute must be unique.
    36  	Attributes []NamedResourcesAttribute
    37  }
    38  
    39  // NamedResourcesAttribute is a combination of an attribute name and its value.
    40  type NamedResourcesAttribute struct {
    41  	// Name is unique identifier among all resource instances managed by
    42  	// the driver on the node. It must be a DNS subdomain.
    43  	Name string
    44  
    45  	NamedResourcesAttributeValue
    46  }
    47  
    48  // NamedResourcesAttributeValue must have one and only one field set.
    49  type NamedResourcesAttributeValue struct {
    50  	// QuantityValue is a quantity.
    51  	QuantityValue *resource.Quantity
    52  	// BoolValue is a true/false value.
    53  	BoolValue *bool
    54  	// IntValue is a 64-bit integer.
    55  	IntValue *int64
    56  	// IntSliceValue is an array of 64-bit integers.
    57  	IntSliceValue *NamedResourcesIntSlice
    58  	// StringValue is a string.
    59  	StringValue *string
    60  	// StringSliceValue is an array of strings.
    61  	StringSliceValue *NamedResourcesStringSlice
    62  	// VersionValue is a semantic version according to semver.org spec 2.0.0.
    63  	VersionValue *string
    64  }
    65  
    66  // NamedResourcesIntSlice contains a slice of 64-bit integers.
    67  type NamedResourcesIntSlice struct {
    68  	// Ints is the slice of 64-bit integers.
    69  	Ints []int64
    70  }
    71  
    72  // NamedResourcesStringSlice contains a slice of strings.
    73  type NamedResourcesStringSlice struct {
    74  	// Strings is the slice of strings.
    75  	Strings []string
    76  }
    77  
    78  // NamedResourcesRequest is used in ResourceRequestModel.
    79  type NamedResourcesRequest struct {
    80  	// Selector is a CEL expression which must evaluate to true if a
    81  	// resource instance is suitable. The language is as defined in
    82  	// https://kubernetes.io/docs/reference/using-api/cel/
    83  	//
    84  	// In addition, for each type NamedResourcesin AttributeValue there is a map that
    85  	// resolves to the corresponding value of the instance under evaluation.
    86  	// For example:
    87  	//
    88  	//    attributes.quantity["a"].isGreaterThan(quantity("0")) &&
    89  	//    attributes.stringslice["b"].isSorted()
    90  	Selector string
    91  }
    92  
    93  // NamedResourcesFilter is used in ResourceFilterModel.
    94  type NamedResourcesFilter 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 in NamedResourcesAttributeValue 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
   106  }
   107  
   108  // NamedResourcesAllocationResult is used in AllocationResultModel.
   109  type NamedResourcesAllocationResult struct {
   110  	// Name is the name of the selected resource instance.
   111  	Name string
   112  }