response actual resource list type
Signed-off-by: lizhen6 <lizhen6@360.cn>
This commit is contained in:
parent
66475089d9
commit
47b0551a56
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
@ -20,6 +21,7 @@ import (
|
|||
type SearchREST struct {
|
||||
multiClusterInformerManager genericmanager.MultiClusterInformerManager
|
||||
clusterLister clusterlister.ClusterLister
|
||||
restMapper meta.RESTMapper
|
||||
|
||||
// add needed parameters here
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue