Skip to content

Commit 4acab3c

Browse files
authored
Merge pull request #13306 from fabriziopandini/inmemory-api-server-unsupported-field-selectors
🌱 Inmemory APIserver fails for unsupported fieldSelectors
2 parents 37aa69a + 62caa0a commit 4acab3c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

test/infrastructure/inmemory/pkg/runtime/cache/client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cache
1818

1919
import (
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

3840
func (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}) {

test/infrastructure/inmemory/pkg/server/api/handler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ func (h *apiServerHandler) v1List(ctx context.Context, req *restful.Request, gvk
359359
listOpts = append(listOpts, client.InNamespace(req.PathParameter("namespace")))
360360
}
361361

362-
// TODO: The only field Selector which works is for `spec.nodeName` on pods.
363362
fieldSelector, err := fields.ParseSelector(req.QueryParameter("fieldSelector"))
364363
if err != nil {
365364
return nil, err

0 commit comments

Comments
 (0)