Skip to content

Commit 85e4e38

Browse files
authored
Merge pull request kubernetes#137171 from liggitt/component-helpers-deps
Clean up direct external dependencies from component-helpers
2 parents 60433d4 + 4ab6ae2 commit 85e4e38

File tree

19 files changed

+249
-479
lines changed

19 files changed

+249
-479
lines changed

pkg/kubelet/kubelet_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ import (
3232
"testing"
3333
"time"
3434

35-
"github.com/stretchr/testify/mock"
36-
3735
sdktrace "go.opentelemetry.io/otel/sdk/trace"
3836
"go.opentelemetry.io/otel/sdk/trace/tracetest"
3937
oteltrace "go.opentelemetry.io/otel/trace"
4038
noopoteltrace "go.opentelemetry.io/otel/trace/noop"
39+
4140
"k8s.io/component-base/metrics/legacyregistry"
4241

4342
cadvisorapi "github.com/google/cadvisor/info/v1"
@@ -4768,13 +4767,12 @@ func TestSyncPodNodeDeclaredFeaturesUpdate(t *testing.T) {
47684767
newPod.Spec.Containers[0].Resources.Requests[v1.ResourceCPU] = cpu2000m
47694768
createMockFeature := func(t *testing.T, name string, inferForUpdate bool, maxVersionStr string) *ndftesting.MockFeature {
47704769
m := ndftesting.NewMockFeature(t)
4771-
m.EXPECT().Name().Return(name).Maybe()
4772-
m.EXPECT().InferForUpdate(mock.Anything, mock.Anything).Return(inferForUpdate).Maybe()
4770+
m.SetName(name)
4771+
m.SetInferForUpdate(func(_, _ *ndf.PodInfo) bool { return inferForUpdate })
47734772
if maxVersionStr != "" {
4774-
maxVersionStr := utilversion.MustParseSemantic(maxVersionStr)
4775-
m.EXPECT().MaxVersion().Return(maxVersionStr).Maybe()
4773+
m.SetMaxVersion(utilversion.MustParseSemantic(maxVersionStr))
47764774
} else {
4777-
m.EXPECT().MaxVersion().Return(nil).Maybe()
4775+
m.SetMaxVersion(nil)
47784776
}
47794777
return m
47804778
}

pkg/kubelet/lifecycle/handlers_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"time"
3030

3131
"github.com/google/go-cmp/cmp"
32-
"github.com/stretchr/testify/mock"
3332
"github.com/stretchr/testify/require"
33+
3434
v1 "k8s.io/api/core/v1"
3535
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3636
"k8s.io/apimachinery/pkg/types"
@@ -847,13 +847,12 @@ func TestDeclaredFeaturesAdmitHandler(t *testing.T) {
847847
}
848848
createMockFeature := func(t *testing.T, name string, inferForSched bool, maxVersionStr string) *ndftesting.MockFeature {
849849
m := ndftesting.NewMockFeature(t)
850-
m.EXPECT().Name().Return(name).Maybe()
851-
m.EXPECT().InferForScheduling(mock.Anything).Return(inferForSched).Maybe()
850+
m.SetName(name)
851+
m.SetInferForScheduling(func(podInfo *ndf.PodInfo) bool { return inferForSched })
852852
if maxVersionStr != "" {
853-
maxVersionStr := version.MustParseSemantic(maxVersionStr)
854-
m.EXPECT().MaxVersion().Return(maxVersionStr).Maybe()
853+
m.SetMaxVersion(version.MustParseSemantic(maxVersionStr))
855854
} else {
856-
m.EXPECT().MaxVersion().Return(nil).Maybe()
855+
m.SetMaxVersion(nil)
857856
}
858857
return m
859858
}

pkg/scheduler/framework/plugins/nodedeclaredfeatures/nodedeclaredfeatures_test.go

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/google/go-cmp/cmp"
25-
"github.com/stretchr/testify/mock"
25+
2626
v1 "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/util/version"
2828
"k8s.io/klog/v2/ktesting"
@@ -40,13 +40,12 @@ import (
4040
// createMockFeature is a helper function to create and configure a MockFeature.
4141
func createMockFeature(t *testing.T, name string, infer bool, maxVersionStr string) *ndftesting.MockFeature {
4242
m := ndftesting.NewMockFeature(t)
43-
m.EXPECT().Name().Return(name).Maybe()
44-
m.EXPECT().InferForScheduling(mock.Anything).Return(infer).Maybe()
43+
m.SetName(name)
44+
m.SetInferForScheduling(func(podInfo *ndf.PodInfo) bool { return infer })
4545
if maxVersionStr != "" {
46-
minVersion := version.MustParseSemantic(maxVersionStr)
47-
m.EXPECT().MaxVersion().Return(minVersion).Maybe()
46+
m.SetMaxVersion(version.MustParseSemantic(maxVersionStr))
4847
} else {
49-
m.EXPECT().MaxVersion().Return(nil).Maybe()
48+
m.SetMaxVersion(nil)
5049
}
5150
return m
5251
}
@@ -342,10 +341,21 @@ func TestEnqueueExtensionsPodUpdate(t *testing.T) {
342341
newPod: st.MakePod().Name(targetPodName).UID(targetPodUID).Label("foo", "bar").Obj(),
343342
componenetVersion: version.MustParseSemantic("1.35.0"),
344343
setupMock: func(m *ndftesting.MockFeature) {
345-
m.EXPECT().InferForScheduling(mock.Anything).Return(false).Once()
346-
m.EXPECT().InferForScheduling(mock.Anything).Return(true).Once()
347-
m.EXPECT().Name().Return("TestFeature").Maybe()
348-
m.EXPECT().MaxVersion().Return(nil).Maybe()
344+
i := 0
345+
m.SetInferForScheduling(func(podInfo *ndf.PodInfo) bool {
346+
switch i {
347+
case 0:
348+
i++
349+
return false
350+
case 1:
351+
i++
352+
return true
353+
default:
354+
panic("unexpected calls to SetInferForScheduling")
355+
}
356+
})
357+
m.SetName("TestFeature")
358+
m.SetMaxVersion(nil)
349359
},
350360
expectedHint: fwk.Queue,
351361
},
@@ -355,10 +365,21 @@ func TestEnqueueExtensionsPodUpdate(t *testing.T) {
355365
newPod: st.MakePod().Name(targetPodName).UID(targetPodUID).Obj(),
356366
componenetVersion: version.MustParseSemantic("1.35.0"),
357367
setupMock: func(m *ndftesting.MockFeature) {
358-
m.EXPECT().InferForScheduling(mock.Anything).Return(true).Once()
359-
m.EXPECT().InferForScheduling(mock.Anything).Return(false).Once()
360-
m.EXPECT().Name().Return("TestFeature").Maybe()
361-
m.EXPECT().MaxVersion().Return(nil).Maybe()
368+
i := 0
369+
m.SetInferForScheduling(func(podInfo *ndf.PodInfo) bool {
370+
switch i {
371+
case 0:
372+
i++
373+
return true
374+
case 1:
375+
i++
376+
return false
377+
default:
378+
panic("unexpected calls to SetInferForScheduling")
379+
}
380+
})
381+
m.SetName("TestFeature")
382+
m.SetMaxVersion(nil)
362383
},
363384
expectedHint: fwk.Queue,
364385
},
@@ -368,9 +389,9 @@ func TestEnqueueExtensionsPodUpdate(t *testing.T) {
368389
newPod: st.MakePod().Name(targetPodName).UID(targetPodUID).Obj(),
369390
componenetVersion: version.MustParseSemantic("1.35.0"),
370391
setupMock: func(m *ndftesting.MockFeature) {
371-
m.EXPECT().InferForScheduling(mock.Anything).Return(false)
372-
m.EXPECT().Name().Return("TestFeature").Maybe()
373-
m.EXPECT().MaxVersion().Return(nil).Maybe()
392+
m.SetInferForScheduling(func(podInfo *ndf.PodInfo) bool { return false })
393+
m.SetName("TestFeature")
394+
m.SetMaxVersion(nil)
374395
},
375396
expectedHint: fwk.QueueSkip,
376397
},
@@ -380,9 +401,9 @@ func TestEnqueueExtensionsPodUpdate(t *testing.T) {
380401
newPod: st.MakePod().Name("another-test-pod").UID("456").Obj(),
381402
componenetVersion: version.MustParseSemantic("1.35.0"),
382403
setupMock: func(m *ndftesting.MockFeature) {
383-
m.EXPECT().InferForScheduling(mock.Anything).Return(false).Maybe()
384-
m.EXPECT().Name().Return("TestFeature").Maybe()
385-
m.EXPECT().MaxVersion().Return(nil).Maybe()
404+
m.SetInferForScheduling(func(podInfo *ndf.PodInfo) bool { return false })
405+
m.SetName("TestFeature")
406+
m.SetMaxVersion(nil)
386407
},
387408
expectedHint: fwk.QueueSkip,
388409
},
@@ -392,9 +413,9 @@ func TestEnqueueExtensionsPodUpdate(t *testing.T) {
392413
newPod: st.MakePod().Name(targetPodName).UID(targetPodUID).Label("foo", "bar").Obj(),
393414
componenetVersion: nil,
394415
setupMock: func(m *ndftesting.MockFeature) {
395-
m.EXPECT().InferForScheduling(mock.Anything).Return(true).Maybe()
396-
m.EXPECT().Name().Return("TestFeature").Maybe()
397-
m.EXPECT().MaxVersion().Return(nil).Maybe()
416+
m.SetInferForScheduling(func(podInfo *ndf.PodInfo) bool { return true })
417+
m.SetName("TestFeature")
418+
m.SetMaxVersion(nil)
398419
},
399420
expectedHint: fwk.Queue, // Queued again in case of error
400421
expectedErr: "target version cannot be nil",

plugin/pkg/admission/nodedeclaredfeatures/admission_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222

2323
"github.com/stretchr/testify/assert"
24-
"github.com/stretchr/testify/mock"
2524
"github.com/stretchr/testify/require"
2625

2726
v1 "k8s.io/api/core/v1"
@@ -85,13 +84,12 @@ func TestAdmission(t *testing.T) {
8584

8685
createMockFeature := func(t *testing.T, name string, inferForUpdate bool, maxVersionStr string) *ndftesting.MockFeature {
8786
m := ndftesting.NewMockFeature(t)
88-
m.EXPECT().Name().Return(name).Maybe()
89-
m.EXPECT().InferForUpdate(mock.Anything, mock.Anything).Return(inferForUpdate).Maybe()
87+
m.SetName(name)
88+
m.SetInferForUpdate(func(_, _ *ndf.PodInfo) bool { return inferForUpdate })
9089
if maxVersionStr != "" {
91-
minVersion := version.MustParseSemantic(maxVersionStr)
92-
m.EXPECT().MaxVersion().Return(minVersion).Maybe()
90+
m.SetMaxVersion(version.MustParseSemantic(maxVersionStr))
9391
} else {
94-
m.EXPECT().MaxVersion().Return(nil).Maybe()
92+
m.SetMaxVersion(nil)
9593
}
9694
return m
9795
}

staging/src/k8s.io/component-helpers/apimachinery/lease/controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"testing"
2424
"time"
2525

26-
"github.com/google/go-cmp/cmp"
2726
coordinationv1 "k8s.io/api/coordination/v1"
2827
corev1 "k8s.io/api/core/v1"
2928
apiequality "k8s.io/apimachinery/pkg/api/equality"
@@ -253,7 +252,7 @@ func TestNewNodeLease(t *testing.T) {
253252
t.Fatalf("the new lease must be newly allocated, but got same address as base")
254253
}
255254
if !apiequality.Semantic.DeepEqual(tc.expect, newLease) {
256-
t.Errorf("unexpected result from newLease: %s", cmp.Diff(tc.expect, newLease))
255+
t.Errorf("expected %#v, got %#v", tc.expect, newLease)
257256
}
258257
})
259258
}

staging/src/k8s.io/component-helpers/auth/rbac/reconciliation/reconcile_role_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package reconciliation
1919
import (
2020
"testing"
2121

22-
"github.com/google/go-cmp/cmp"
2322
rbacv1 "k8s.io/api/rbac/v1"
2423
apiequality "k8s.io/apimachinery/pkg/api/equality"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -392,7 +391,7 @@ func TestComputeReconciledRoleAggregationRules(t *testing.T) {
392391
continue
393392
}
394393
if reconciliationNeeded && !apiequality.Semantic.DeepEqual(result.Role.(ClusterRoleRuleOwner).ClusterRole, tc.expectedReconciledRole) {
395-
t.Errorf("%s: %v", k, cmp.Diff(tc.expectedReconciledRole, result.Role.(ClusterRoleRuleOwner).ClusterRole))
394+
t.Errorf("%s: expected %#v, got %#v", k, tc.expectedReconciledRole, result.Role.(ClusterRoleRuleOwner).ClusterRole)
396395
}
397396
}
398397
}

staging/src/k8s.io/component-helpers/go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ go 1.25.0
77
godebug default=go1.25
88

99
require (
10-
github.com/google/go-cmp v0.7.0
11-
github.com/stretchr/testify v1.11.1
1210
k8s.io/api v0.0.0
1311
k8s.io/apimachinery v0.0.0
1412
k8s.io/client-go v0.0.0
@@ -33,7 +31,6 @@ require (
3331
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
3432
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3533
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
36-
github.com/stretchr/objx v0.5.2 // indirect
3734
github.com/x448/float16 v0.8.4 // indirect
3835
go.yaml.in/yaml/v2 v2.4.3 // indirect
3936
go.yaml.in/yaml/v3 v3.0.4 // indirect

staging/src/k8s.io/component-helpers/node/util/sysctl/sysctl_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package sysctl
1818

1919
import (
2020
"testing"
21-
22-
"github.com/stretchr/testify/assert"
2321
)
2422

2523
// TestConvertSysctlVariableToDotsSeparator tests whether the sysctl variable
@@ -41,6 +39,8 @@ func TestConvertSysctlVariableToDotsSeparator(t *testing.T) {
4139

4240
for _, test := range valid {
4341
convertSysctlVal := NormalizeName(test.in)
44-
assert.Equalf(t, test.out, convertSysctlVal, "The sysctl variable was not converted correctly. got: %s, want: %s", convertSysctlVal, test.out)
42+
if test.out != convertSysctlVal {
43+
t.Errorf("The sysctl variable was not converted correctly. got: %s, want: %s", convertSysctlVal, test.out)
44+
}
4545
}
4646
}

staging/src/k8s.io/component-helpers/nodedeclaredfeatures/.mockery.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

staging/src/k8s.io/component-helpers/nodedeclaredfeatures/features/inplacepodresize/guaranteed_cpu_resize_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package inplacepodresize
1919
import (
2020
"testing"
2121

22-
"github.com/stretchr/testify/assert"
2322
v1 "k8s.io/api/core/v1"
2423
"k8s.io/apimachinery/pkg/api/resource"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -64,21 +63,25 @@ func TestGuaranteedQoSPodCPUResizeFeature_Discover(t *testing.T) {
6463
for _, tc := range testCases {
6564
t.Run(tc.name, func(t *testing.T) {
6665
mockFG := test.NewMockFeatureGate(t)
67-
mockFG.EXPECT().Enabled(IPPRExclusiveCPUsFeatureGate).Return(tc.gateEnabled)
66+
mockFG.SetEnabled(IPPRExclusiveCPUsFeatureGate, tc.gateEnabled)
6867

6968
config := &nodedeclaredfeatures.NodeConfiguration{
7069
FeatureGates: mockFG,
7170
StaticConfig: nodedeclaredfeatures.StaticConfiguration{CPUManagerPolicy: tc.cpuManagerPolicy},
7271
}
7372
enabled := feature.Discover(config)
74-
assert.Equal(t, tc.expected, enabled)
73+
if tc.expected != enabled {
74+
t.Fatalf("expected %v, got %v", tc.expected, enabled)
75+
}
7576
})
7677
}
7778
}
7879

7980
func TestGuaranteedQoSPodCPUResizeFeature_InferForScheduling(t *testing.T) {
8081
feature := &guaranteedQoSPodCPUResizeFeature{}
81-
assert.False(t, feature.InferForScheduling(&nodedeclaredfeatures.PodInfo{Spec: &v1.PodSpec{}, Status: &v1.PodStatus{}}), "InferForScheduling should always be false")
82+
if feature.InferForScheduling(&nodedeclaredfeatures.PodInfo{Spec: &v1.PodSpec{}, Status: &v1.PodStatus{}}) {
83+
t.Fatalf("InferForScheduling should always be false")
84+
}
8285
}
8386

8487
func TestGuaranteedQoSPodCPUResizeFeature_InferFromUpdate(t *testing.T) {
@@ -147,7 +150,9 @@ func TestGuaranteedQoSPodCPUResizeFeature_InferFromUpdate(t *testing.T) {
147150
t.Run(tc.name, func(t *testing.T) {
148151
oldPodInfo := &nodedeclaredfeatures.PodInfo{Spec: &tc.oldPod.Spec, Status: &tc.oldPod.Status}
149152
newPodInfo := &nodedeclaredfeatures.PodInfo{Spec: &tc.newPod.Spec, Status: &tc.newPod.Status}
150-
assert.Equal(t, tc.expected, feature.InferForUpdate(oldPodInfo, newPodInfo))
153+
if want, got := tc.expected, feature.InferForUpdate(oldPodInfo, newPodInfo); want != got {
154+
t.Fatalf("want=%v,got=%v", want, got)
155+
}
151156
})
152157
}
153158
}

0 commit comments

Comments
 (0)