@@ -238,6 +238,8 @@ func resourceSlice(driverName, nodeName string, capacity int) *resourceapi.Resou
238
238
Capacity : map [resourceapi.QualifiedName ]resourceapi.DeviceCapacity {
239
239
"memory" : {Value : resource .MustParse ("1Gi" )},
240
240
},
241
+ // These fields are only used when the "BindingConditions" feature gate is enabled.
242
+ // When the feature gate is off, these fields are stripped to ensure backward compatibility.
241
243
UsageRestrictedToNode : ptr .To (true ),
242
244
BindingConditions : []string {"DeviceAttached" },
243
245
BindingFailureConditions : []string {"AttachmentFailed" },
@@ -372,14 +374,28 @@ claims:
372
374
}
373
375
}
374
376
377
+ // updateDeviceConditionsOp defines an op where device conditions are updated.
378
+ // This is used to test the device binding conditions.
379
+ // The conditions are set on the device status of the resource claim.
375
380
type updateDeviceConditionsOp struct {
376
- Opcode operationCode
377
- Namespace string
378
- ConditionTypeParam string
381
+ // Must be updateDeviceConditionsOpcode.
382
+ Opcode operationCode
383
+ // Namespace where the claims are located.
384
+ Namespace string
385
+ // Conditions to set on the devices.
386
+ ConditionTypeParam string
387
+ // ConditionStatusParam is the parameter for the condition status.
388
+ // The condition status must be one of "True", "False", or "Unknown".
379
389
ConditionStatusParam string
380
- Conditions []metav1.Condition
381
- Duration metav1.Duration
382
- DurationParam string
390
+ // Conditions to set on the devices. This is parameterized through
391
+ // ConditionTypeParam and ConditionStatusParam.
392
+ Conditions []metav1.Condition
393
+ // Duration for the test.
394
+ Duration metav1.Duration
395
+ // DurationParam is the parameter for the duration.
396
+ // If set, the duration is parameterized through this parameter.
397
+ // The duration is used to wait for the conditions to be set.
398
+ DurationParam string
383
399
}
384
400
385
401
func (op * updateDeviceConditionsOp ) isValid (allowParameterization bool ) error {
@@ -389,12 +405,13 @@ func (op *updateDeviceConditionsOp) isValid(allowParameterization bool) error {
389
405
if op .Conditions == nil && (op .ConditionTypeParam == "" || op .ConditionStatusParam == "" ) {
390
406
return fmt .Errorf ("conditions must be set" )
391
407
}
392
- if op .Namespace == "" || op .ConditionTypeParam == "" {
393
- return fmt .Errorf ("namespace and conditions must be set" )
408
+ if op .ConditionStatusParam != "" && op .ConditionTypeParam == "" {
409
+ return fmt .Errorf ("ConditionStatusParam must be set together with ConditionTypeParam " )
394
410
}
395
- if op .Namespace == "" || op .ConditionTypeParam == "" {
396
- return fmt .Errorf ("namespace and conditions must be set" )
411
+ if op .ConditionTypeParam != "" && op .ConditionStatusParam == "" {
412
+ return fmt .Errorf ("ConditionTypeParam must be set together with ConditionStatusParam " )
397
413
}
414
+
398
415
return nil
399
416
}
400
417
@@ -532,12 +549,26 @@ func makeBindingConditions(driver, pool, device, condition string, status metav1
532
549
}
533
550
}
534
551
552
+ // checkPodScheduledOp defines an op that checks if all pods in a namespace are scheduled
553
+ // or unscheduled. This is used to test the device binding conditions.
554
+ // The check is done by listing all pods in the namespace and checking their status.
535
555
type checkPodScheduledOp struct {
536
- Opcode operationCode
537
- Namespace string
538
- Duration metav1.Duration
539
- DurationParam string
540
- ScheduledParam string
556
+ // Must be checkPodScheduledOpcode.
557
+ Opcode operationCode
558
+ // Namespace where the pods are located.
559
+ Namespace string
560
+ // Duration for the test.
561
+ Duration metav1.Duration
562
+ // DurationParam is the parameter for the duration.
563
+ // If set, the duration is parameterized through this parameter.
564
+ DurationParam string
565
+ // ScheduledParam is the parameter for the expected scheduled state.
566
+ // If set, the expected scheduled state is parameterized through this parameter.
567
+ ScheduledParam string
568
+ // ExpectedScheduled is the expected scheduled state.
569
+ // If true, the op checks if all pods are scheduled.
570
+ // If false, the op checks if all pods are unscheduled.
571
+ // This is used to test the device binding conditions.
541
572
ExpectedScheduled bool
542
573
}
543
574
0 commit comments