Skip to content

Commit a343bbf

Browse files
authored
Merge pull request #98 from pfnet/fix-test-cache
Add cache options as well as in test
2 parents 2a81b7d + 59b3fc4 commit a343bbf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/controller/suite_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ import (
3030
. "github.com/onsi/ginkgo/v2"
3131
. "github.com/onsi/gomega"
3232

33+
corev1 "k8s.io/api/core/v1"
34+
"k8s.io/apimachinery/pkg/api/meta"
35+
"k8s.io/apimachinery/pkg/fields"
3336
"k8s.io/client-go/kubernetes/scheme"
3437
"k8s.io/client-go/rest"
3538
ctrl "sigs.k8s.io/controller-runtime"
39+
"sigs.k8s.io/controller-runtime/pkg/cache"
3640
"sigs.k8s.io/controller-runtime/pkg/client"
3741
"sigs.k8s.io/controller-runtime/pkg/envtest"
3842
logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -91,6 +95,21 @@ var _ = BeforeSuite(func() {
9195

9296
k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
9397
Scheme: scheme.Scheme,
98+
Cache: cache.Options{
99+
ByObject: map[client.Object]cache.ByObject{
100+
&corev1.Pod{}: {
101+
Field: fields.OneTermEqualSelector("status.phase", string(corev1.PodPending)),
102+
Transform: func(obj any) (any, error) {
103+
if accessor, err := meta.Accessor(obj); err == nil {
104+
if accessor.GetManagedFields() != nil {
105+
accessor.SetManagedFields(nil)
106+
}
107+
}
108+
return obj, nil
109+
},
110+
},
111+
},
112+
},
94113
})
95114
Expect(err).NotTo(HaveOccurred())
96115

0 commit comments

Comments
 (0)