Skip to content

Commit c3ef9ed

Browse files
committed
rework cel expr builder
Signed-off-by: Varun Ramachandra Sekar <vsekar@nvidia.com>
1 parent 2f2d15b commit c3ef9ed

File tree

19 files changed

+1567
-585
lines changed

19 files changed

+1567
-585
lines changed

api/apps/v1alpha1/common_types.go

Lines changed: 0 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
autoscalingv2 "k8s.io/api/autoscaling/v2"
2222
corev1 "k8s.io/api/core/v1"
2323
networkingv1 "k8s.io/api/networking/v1"
24-
apiresource "k8s.io/apimachinery/pkg/api/resource"
2524
"k8s.io/utils/ptr"
2625
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2726
)
@@ -329,216 +328,3 @@ type PersistentVolumeClaim struct {
329328
// Annotations for the PVC
330329
Annotations map[string]string `json:"annotations,omitempty"`
331330
}
332-
333-
// DRAResource references exactly one ResourceClaim, either directly
334-
// or by naming a ResourceClaimTemplate which is then turned into a ResourceClaim.
335-
//
336-
// When creating the NIMService pods, it adds a name (`DNS_LABEL` format) to it
337-
// that uniquely identifies the DRA resource.
338-
// +kubebuilder:validation:XValidation:rule="(has(self.resourceClaimName) ? 1 : 0) + (has(self.resourceClaimTemplateName) ? 1 : 0) + (has(self.claimSpec) ? 1 : 0) == 1",message="exactly one of spec.resourceClaimName, spec.resourceClaimTemplateName, or spec.claimSpec must be set."
339-
type DRAResource struct {
340-
// ResourceClaimName is the name of a DRA resource claim object in the same
341-
// namespace as the NIMService.
342-
//
343-
// Exactly one of ResourceClaimName and ResourceClaimTemplateName must
344-
// be set.
345-
//
346-
// +kubebuilder:validation:MinLength=1
347-
// +kubebuilder:validation:MaxLength=253
348-
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`
349-
ResourceClaimName *string `json:"resourceClaimName,omitempty"`
350-
351-
// ResourceClaimTemplateName is the name of a DRA resource claim template
352-
// object in the same namespace as the pods for this NIMService.
353-
//
354-
// The template will be used to create a new DRA resource claim, which will
355-
// be bound to the pods created for this NIMService.
356-
//
357-
// Exactly one of ResourceClaimName and ResourceClaimTemplateName must
358-
// be set.
359-
//
360-
// +kubebuilder:validation:MinLength=1
361-
// +kubebuilder:validation:MaxLength=253
362-
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`
363-
ResourceClaimTemplateName *string `json:"resourceClaimTemplateName,omitempty"`
364-
365-
// ClaimSpec is the spec to auto-generate a DRA resource claim/resource claim template. Only one of ClaimSpec, ResourceClaimName or ResourceClaimTemplateName must be specified.
366-
ClaimSpec *DRAClaimSpec `json:"claimSpec,omitempty"`
367-
368-
// Requests is the list of requests in the referenced DRA resource claim/resource claim template
369-
// to be made available to the model container of the NIMService pods.
370-
//
371-
// If empty, everything from the claim is made available, otherwise
372-
// only the result of this subset of requests.
373-
//
374-
// +kubebuilder:validation:items:MinLength=1
375-
Requests []string `json:"requests,omitempty"`
376-
}
377-
378-
// DRADeviceAttributeMatcherValue defines the value of a device attribute to match.
379-
// Exactly one of the fields must be set.
380-
type DRADeviceAttributeMatcherValue struct {
381-
// BoolValue is a true/false value.
382-
BoolValue *bool `json:"boolValue,omitempty"`
383-
// IntValue is a number.
384-
IntValue *int32 `json:"intValue,omitempty"`
385-
// StringValue is a string value.
386-
// +kubebuilder:validation:MaxLength=64
387-
StringValue *string `json:"stringValue,omitempty"`
388-
// VersionValue is a semantic version according to semver.org spec 2.0.0.
389-
// +kubebuilder:validation:MaxLength=64
390-
VersionValue *string `json:"versionValue,omitempty"`
391-
}
392-
393-
// DRADeviceAttributeMatcherOp defines the operator to use for matching a device attribute.
394-
type DRADeviceAttributeMatcherOp string
395-
396-
const (
397-
DRADeviceAttributeMatcherOpEqual DRADeviceAttributeMatcherOp = "Equal"
398-
DRADeviceAttributeMatcherOpNotEqual DRADeviceAttributeMatcherOp = "NotEqual"
399-
DRADeviceAttributeMatcherOpGreaterThan DRADeviceAttributeMatcherOp = "GreaterThan"
400-
DRADeviceAttributeMatcherOpGreaterThanOrEqual DRADeviceAttributeMatcherOp = "GreaterThanOrEqual"
401-
DRADeviceAttributeMatcherOpLessThan DRADeviceAttributeMatcherOp = "LessThan"
402-
DRADeviceAttributeMatcherOpLessThanOrEqual DRADeviceAttributeMatcherOp = "LessThanOrEqual"
403-
)
404-
405-
// DRADeviceAttributeMatcher defines the matcher expression for a DRA device attribute.
406-
type DRADeviceAttributeMatcher struct {
407-
// Key is the name of the device attribute to match.
408-
// This is either a qualified name or a simple name.
409-
// If it is a simple name, then it is assumed to be prefixed with the DRA driver name.
410-
// Eg: "gpu.nvidia.com/productName" is equivalent to "productName" if the driver name is "gpu.nvidia.com". Otherwise they're treated as 2 different attributes.
411-
// +kubebuilder:validation:MaxLength=64
412-
Key string `json:"key"`
413-
// Op is the operator to use for matching the device attribute. Supported operators are:
414-
// * Equal: The device attribute value must be equal to the value specified in the matcher.
415-
// * NotEqual: The device attribute value must not be equal to the value specified in the matcher.
416-
// * GreaterThan: The device attribute value must be greater than the value specified in the matcher.
417-
// * GreaterThanOrEqual: The device attribute value must be greater than or equal to the value specified in the matcher.
418-
// * LessThan: The device attribute value must be less than the value specified in the matcher.
419-
// * LessThanOrEqual: The device attribute value must be less than or equal to the value specified in the matcher.
420-
//
421-
// +kubebuilder:validation:Enum=Equal;NotEqual;GreaterThan;GreaterThanOrEqual;LessThan;LessThanOrEqual
422-
// +kubebuilder:default=Equal
423-
Op DRADeviceAttributeMatcherOp `json:"op"`
424-
// Value is the value to match the device attribute against.
425-
Value *DRADeviceAttributeMatcherValue `json:"value,omitempty"`
426-
}
427-
428-
// DRAResourceQuantityMatcherOp defines the operator to use for matching a resource quantity.
429-
type DRAResourceQuantityMatcherOp string
430-
431-
const (
432-
DRAResourceQuantityMatcherOpEqual DRAResourceQuantityMatcherOp = "Equal"
433-
)
434-
435-
// DRAResourceQuantityMatcher defines the matcher expression for a DRA device capacity.
436-
type DRAResourceQuantityMatcher struct {
437-
// Key is the name of the resource quantity to match.
438-
// This is either a qualified name or a simple name.
439-
// If it is a simple name, then it is assumed to be prefixed with the DRA driver name.
440-
// Eg: "gpu.nvidia.com/memory" is equivalent to "memory" if the driver name is "gpu.nvidia.com". Otherwise they're treated as 2 different attributes.
441-
// +kubebuilder:validation:MaxLength=64
442-
Key string `json:"key"`
443-
// Op is the operator to use for matching the device capacity. Supported operators are:
444-
// * Equal: The resource quantity value must be equal to the value specified in the matcher.
445-
//
446-
// +kubebuilder:validation:Enum=Equal
447-
// +kubebuilder:default=Equal
448-
Op DRAResourceQuantityMatcherOp `json:"op"`
449-
// Value is the quantity to match the device capacity against.
450-
Value *apiresource.Quantity `json:"value,omitempty"`
451-
}
452-
453-
type DRADeviceSpec struct {
454-
// Name is the name of the device request to use in the generated claim spec.
455-
// Must be a valid DNS_LABEL.
456-
// +kubebuilder:validation:MinLength=1
457-
// +kubebuilder:validation:MaxLength=253
458-
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`
459-
Name string `json:"name"`
460-
// Count is the number of devices to request.
461-
// +kubebuilder:default=1
462-
Count uint32 `json:"count"`
463-
// DeviceClassName references a specific DeviceClass to inherit configuration and selectors from.
464-
// +kubebuilder:default=gpu.nvidia.com
465-
DeviceClassName string `json:"deviceClassName"`
466-
// DriverName is the name of the DRA driver providing the capacity information.
467-
// Must be a DNS subdomain.
468-
//
469-
// +kubebuilder:validation:MaxLength=253
470-
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`
471-
// +kubebuilder:default=gpu.nvidia.com
472-
DriverName string `json:"driverName,omitempty"`
473-
// MatchAttributes defines the criteria which must be satisfied by the device attributes of a device.
474-
// +kubebuilder:validation:MaxSize=20
475-
MatchAttributes []DRADeviceAttributeMatcher `json:"matchAttributes,omitempty"`
476-
// MatchCapacity defines the criteria which must be satisfied by the device capacity of a device.
477-
// +kubebuilder:validation:MaxSize=12
478-
MatchCapacity []DRAResourceQuantityMatcher `json:"matchCapacity,omitempty"`
479-
}
480-
481-
// DRAClaimSpec defines the spec for generating a DRA resource claim/resource claim template.
482-
type DRAClaimSpec struct {
483-
// GenerateName is an optional name prefix to use for generating the resource claim/resource claim template.
484-
// +kubebuilder:validation:MinLength=1
485-
// +kubebuilder:validation:MaxLength=16
486-
GenerateName string `json:"generateName,omitempty"`
487-
// +kubebuilder:validation:MinSize=1
488-
Devices []DRADeviceSpec `json:"devices"`
489-
// TODO: Warn that if set to false, then this NIMService cannot be scaled up.
490-
IsTemplate *bool `json:"isTemplate,omitempty"`
491-
}
492-
493-
func (d *DRAClaimSpec) IsTemplateSpec() bool {
494-
return d.IsTemplate != nil && *d.IsTemplate
495-
}
496-
497-
func (d *DRAClaimSpec) GetNamePrefix() string {
498-
namePrefix := d.GenerateName
499-
if namePrefix != "" {
500-
return namePrefix
501-
}
502-
if d.IsTemplateSpec() {
503-
return "claimtemplate"
504-
}
505-
return "claim"
506-
}
507-
508-
// DRAResourceStatus defines the status of the DRAResource.
509-
// +kubebuilder:validation:XValidation:rule="has(self.resourceClaimStatus) != has(self.resourceClaimTemplateStatus)",message="exactly one of resourceClaimStatus and resourceClaimTemplateStatus must be set."
510-
type DRAResourceStatus struct {
511-
// Name is the pod claim name referenced in the pod spec as `spec.resourceClaims[].name` for this DRA resource.
512-
Name string `json:"name"`
513-
// ResourceClaimStatus is the status of the resource claim in this DRA resource.
514-
//
515-
// Exactly one of resourceClaimStatus and resourceClaimTemplateStatus will be set.
516-
ResourceClaimStatus *DRAResourceClaimStatusInfo `json:"resourceClaimStatus,omitempty"`
517-
// ResourceClaimTemplateStatus is the status of the resource claim template in this DRA resource.
518-
//
519-
// Exactly one of resourceClaimStatus and resourceClaimTemplateStatus will be set.
520-
ResourceClaimTemplateStatus *DRAResourceClaimTemplateStatusInfo `json:"resourceClaimTemplateStatus,omitempty"`
521-
}
522-
523-
// DRAResourceClaimStatusInfo defines the status of a ResourceClaim referenced in the DRAResource.
524-
type DRAResourceClaimStatusInfo struct {
525-
// Name is the name of the ResourceClaim.
526-
Name string `json:"name"`
527-
// State is the state of the ResourceClaim.
528-
// * pending: the resource claim is pending allocation.
529-
// * deleted: the resource claim has a deletion timestamp set but is not yet finalized.
530-
// * allocated: the resource claim is allocated to a pod.
531-
// * reserved: the resource claim is consumed by a pod.
532-
// This field will have one or more of the above values depending on the status of the resource claim.
533-
//
534-
// +kubebuilder:validation:default=pending
535-
State string `json:"state"`
536-
}
537-
538-
// DRAResourceClaimTemplateStatusInfo defines the status of a ResourceClaimTemplate referenced in the DRAResource.
539-
type DRAResourceClaimTemplateStatusInfo struct {
540-
// Name is the name of the resource claim template.
541-
Name string `json:"name"`
542-
// ResourceClaimStatuses is the statuses of the generated resource claims from this resource claim template.
543-
ResourceClaimStatuses []DRAResourceClaimStatusInfo `json:"resourceClaimStatuses,omitempty"`
544-
}

0 commit comments

Comments
 (0)