Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion test/infrastructure/inmemory/pkg/runtime/cache/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cache

import (
"fmt"
"strings"
"time"

jsonpatch "github.com/evanphx/json-patch/v5"
Expand All @@ -33,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/kind/pkg/errors"
)

func (c *cache) Get(resourceGroup string, objKey client.ObjectKey, obj client.Object) error {
Expand Down Expand Up @@ -123,6 +125,15 @@ func (c *cache) List(resourceGroup string, list client.ObjectList, opts ...clien
listOpts := client.ListOptions{}
listOpts.ApplyOptions(opts)

if listOpts.FieldSelector != nil && !listOpts.FieldSelector.Empty() {
if gvk != corev1.SchemeGroupVersion.WithKind("PodList") {
return apierrors.NewInternalError(errors.Errorf("support for field selectors on %s is not implemented", gvk.String()))
}
if !strings.HasPrefix(listOpts.FieldSelector.String(), "spec.nodeName=") {
return apierrors.NewInternalError(errors.Errorf("support for %s field selector on PodList is not implemented", listOpts.FieldSelector.String()))
}
}

for _, obj := range objects {
if listOpts.Namespace != "" && obj.GetNamespace() != listOpts.Namespace {
continue
Expand All @@ -135,7 +146,6 @@ func (c *cache) List(resourceGroup string, list client.ObjectList, opts ...clien
}
}

// 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.
if pod, ok := obj.(*corev1.Pod); ok {
if listOpts.FieldSelector != nil && !listOpts.FieldSelector.Empty() {
if !listOpts.FieldSelector.Matches(fields.Set{"spec.nodeName": pod.Spec.NodeName}) {
Expand Down
1 change: 0 additions & 1 deletion test/infrastructure/inmemory/pkg/server/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ func (h *apiServerHandler) v1List(ctx context.Context, req *restful.Request, gvk
listOpts = append(listOpts, client.InNamespace(req.PathParameter("namespace")))
}

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