From 728eec7196f149ecb47aee682c345ffee5e03e34 Mon Sep 17 00:00:00 2001 From: Michael Morello Date: Wed, 16 Jun 2021 08:27:15 +0200 Subject: [PATCH] Return StatusError 404 in fake client when resource is not found Kubernetes-commit: a93ad421ee949ef0ba6e3cd1c701a91dfefa62f6 --- discovery/fake/discovery.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/discovery/fake/discovery.go b/discovery/fake/discovery.go index f0cc2dbf..d3835c9f 100644 --- a/discovery/fake/discovery.go +++ b/discovery/fake/discovery.go @@ -18,9 +18,11 @@ package fake import ( "fmt" + "net/http" openapi_v2 "github.com/googleapis/gnostic/openapiv2" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/version" @@ -49,7 +51,13 @@ func (c *FakeDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*me return resourceList, nil } } - return nil, fmt.Errorf("GroupVersion %q not found", groupVersion) + return nil, &errors.StatusError{ + ErrStatus: metav1.Status{ + Status: metav1.StatusFailure, + Code: http.StatusNotFound, + Reason: metav1.StatusReasonNotFound, + Message: fmt.Sprintf("the server could not find the requested resource, GroupVersion %q not found", groupVersion), + }} } // ServerResources returns the supported resources for all groups and versions.