Skip to content

Commit a18354c

Browse files
committed
DRA API: fix DeviceTaintRule REST storage test
The defaulting of TimeAdded randomly broke some of the tests: TestList: resttest.go:1393: expected: []runtime.Object{(*resource.DeviceTaintRule)(0xc000b83080), (*resource.DeviceTaintRule)(0xc000b831e0)}, got: []runtime.Object{(*resource.DeviceTaintRule)(0xc0003db608), (*resource.DeviceTaintRule)(0xc0003db750)} ... TestCreate: resttest.go:346: unexpected obj: &resource.DeviceTaintRule{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"foo2", GenerateName:"", Namespace:"", SelfLink:"", UID:"18d3084d-7d11-4575-8730-4650b81cf1a7", ResourceVersion:"8", Generation:1, CreationTimestamp:time.Date(2025, time.March, 21, 8, 27, 23, 0, time.Local), DeletionTimestamp:<nil>, DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Finalizers:[]string(nil), ManagedFields:[]v1.ManagedFieldsEntry(nil)}, Spec:resource.DeviceTaintRuleSpec{DeviceSelector:(*resource.DeviceTaintSelector)(nil), Taint:resource.DeviceTaint{Key:"example.com/taint", Value:"", Effect:"NoExecute", TimeAdded:time.Date(2025, time.March, 21, 8, 27, 23, 0, time.Local)}}}, expected &resource.DeviceTaintRule{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"foo2", GenerateName:"", Namespace:"", SelfLink:"", UID:"18d3084d-7d11-4575-8730-4650b81cf1a7", ResourceVersion:"8", Generation:1, CreationTimestamp:time.Date(2025, time.March, 21, 8, 27, 23, 0, time.Local), DeletionTimestamp:<nil>, DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Finalizers:[]string(nil), ManagedFields:[]v1.ManagedFieldsEntry(nil)}, Spec:resource.DeviceTaintRuleSpec{DeviceSelector:(*resource.DeviceTaintSelector)(nil), Taint:resource.DeviceTaint{Key:"example.com/taint", Value:"", Effect:"NoExecute", TimeAdded:time.Date(2025, time.March, 21, 8, 27, 24, 0, time.Local)}}} Failure rate before: 3m40s: 1332 runs so far, 7 failures (0.53%) It's not obvious from the test failure, but the difference is the TimeAdded. Setting it beforehand to a value that can be encoded (i.e. truncated to seconds) fixes the flake. Failure rate after: 5m0s: 1825 runs so far, 0 failures
1 parent 473533a commit a18354c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/registry/resource/devicetaintrule/storage/storage_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package storage
1818

1919
import (
2020
"testing"
21+
"time"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/fields"
@@ -53,8 +54,9 @@ func validNewDeviceTaint(name string) *resource.DeviceTaintRule {
5354
},
5455
Spec: resource.DeviceTaintRuleSpec{
5556
Taint: resource.DeviceTaint{
56-
Key: "example.com/taint",
57-
Effect: resource.DeviceTaintEffectNoExecute,
57+
Key: "example.com/taint",
58+
Effect: resource.DeviceTaintEffectNoExecute,
59+
TimeAdded: &metav1.Time{Time: time.Now().Truncate(time.Second)}, // Must know in advance what will be stored.
5860
},
5961
},
6062
}

0 commit comments

Comments
 (0)