Skip to content

Commit

Permalink
Merge pull request #3312 from tedli/kindlist
Browse files Browse the repository at this point in the history
response actual resource list from search api
  • Loading branch information
karmada-bot authored Mar 23, 2023
2 parents 4429ffc + 47b0551 commit 861bc7a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pkg/registry/search/storage/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ func (r *SearchREST) newCacheHandler(info *genericrequest.RequestInfo, responder
// TODO: process opts.Limit to prevent the client from being unable to process the response
// due to the large size of the response body.
objItems := r.getObjectItemsFromClusters(clusters, resourceGVR, info.Namespace, info.Name, label)
kind, err := r.restMapper.KindFor(resourceGVR)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
klog.Errorf("Failed to find kind, resource: %s, %v", resourceGVR.Resource, err)
_ = enc.Encode(errorResponse{Error: err.Error()})
return
}
rr := reqResponse{
TypeMeta: metav1.TypeMeta{
APIVersion: resourceGVR.GroupVersion().String(),
Kind: "List", // TODO: obtains the kind type of the actual resource list.
Kind: kind.Kind + "List",
},
Items: objItems,
}
rw.Header().Set("Content-Type", "application/json; charset=utf-8")
_ = enc.Encode(rr)
}), nil
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/registry/search/storage/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"strings"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
genericrequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
Expand All @@ -20,6 +21,7 @@ import (
type SearchREST struct {
multiClusterInformerManager genericmanager.MultiClusterInformerManager
clusterLister clusterlister.ClusterLister
restMapper meta.RESTMapper

// add needed parameters here
}
Expand All @@ -31,10 +33,12 @@ var _ rest.Connecter = &SearchREST{}
// NewSearchREST returns a RESTStorage object that will work against search.
func NewSearchREST(
multiClusterInformerManager genericmanager.MultiClusterInformerManager,
clusterLister clusterlister.ClusterLister) *SearchREST {
clusterLister clusterlister.ClusterLister,
restMapper meta.RESTMapper) *SearchREST {
return &SearchREST{
multiClusterInformerManager: multiClusterInformerManager,
clusterLister: clusterLister,
restMapper: restMapper,
}
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/search/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ func (c completedConfig) New() (*APIServer, error) {
v1alpha1search["resourceregistries/status"] = resourceRegistryStorage.Status

if c.ExtraConfig.Controller != nil {
searchREST := searchstorage.NewSearchREST(c.ExtraConfig.Controller.InformerManager, c.ExtraConfig.Controller.clusterLister)
searchREST := searchstorage.NewSearchREST(
c.ExtraConfig.Controller.InformerManager,
c.ExtraConfig.Controller.clusterLister,
c.ExtraConfig.Controller.restMapper)
v1alpha1search["search"] = searchREST
}

Expand Down

0 comments on commit 861bc7a

Please sign in to comment.