@@ -18,6 +18,7 @@ package cache
1818
1919import (
2020 "fmt"
21+ "strings"
2122 "time"
2223
2324 jsonpatch "github.com/evanphx/json-patch/v5"
@@ -33,6 +34,7 @@ import (
3334 "k8s.io/apimachinery/pkg/runtime/serializer"
3435 "k8s.io/apimachinery/pkg/types"
3536 "sigs.k8s.io/controller-runtime/pkg/client"
37+ "sigs.k8s.io/kind/pkg/errors"
3638)
3739
3840func (c * cache ) Get (resourceGroup string , objKey client.ObjectKey , obj client.Object ) error {
@@ -123,6 +125,15 @@ func (c *cache) List(resourceGroup string, list client.ObjectList, opts ...clien
123125 listOpts := client.ListOptions {}
124126 listOpts .ApplyOptions (opts )
125127
128+ if listOpts .FieldSelector != nil && ! listOpts .FieldSelector .Empty () {
129+ if gvk != corev1 .SchemeGroupVersion .WithKind ("PodList" ) {
130+ return apierrors .NewInternalError (errors .Errorf ("support for field selectors on %s is not implemented" , gvk .String ()))
131+ }
132+ if ! strings .HasPrefix (listOpts .FieldSelector .String (), "spec.nodeName=" ) {
133+ return apierrors .NewInternalError (errors .Errorf ("support for %s field selector on PodList is not implemented" , listOpts .FieldSelector .String ()))
134+ }
135+ }
136+
126137 for _ , obj := range objects {
127138 if listOpts .Namespace != "" && obj .GetNamespace () != listOpts .Namespace {
128139 continue
@@ -135,7 +146,6 @@ func (c *cache) List(resourceGroup string, list client.ObjectList, opts ...clien
135146 }
136147 }
137148
138- // TODO(killianmuldoon): This only matches the nodeName field for pods. No other fieldSelectors are implemented. This should return an error if another fieldselector is used.
139149 if pod , ok := obj .(* corev1.Pod ); ok {
140150 if listOpts .FieldSelector != nil && ! listOpts .FieldSelector .Empty () {
141151 if ! listOpts .FieldSelector .Matches (fields.Set {"spec.nodeName" : pod .Spec .NodeName }) {
0 commit comments