mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-07 16:10:10 +00:00
Add revision to list
This commit is contained in:
4
vendor/github.com/rancher/norman/pkg/api/handler/query.go
generated
vendored
4
vendor/github.com/rancher/norman/pkg/api/handler/query.go
generated
vendored
@@ -11,7 +11,9 @@ func QueryFilter(opts *types.QueryOptions, schema *types.Schema, data types.APIO
|
||||
if opts == nil {
|
||||
opts = &types.QueryOptions{}
|
||||
}
|
||||
return ApplyQueryOptions(opts, schema, data)
|
||||
result := ApplyQueryOptions(opts, schema, data)
|
||||
result.ListRevision = data.ListRevision
|
||||
return result
|
||||
}
|
||||
|
||||
func ApplyQueryOptions(options *types.QueryOptions, schema *types.Schema, data types.APIObject) types.APIObject {
|
||||
|
10
vendor/github.com/rancher/norman/pkg/api/writer/json.go
generated
vendored
10
vendor/github.com/rancher/norman/pkg/api/writer/json.go
generated
vendored
@@ -35,11 +35,15 @@ func (j *EncodingResponseWriter) Body(apiOp *types.APIRequest, writer io.Writer,
|
||||
}
|
||||
|
||||
func (j *EncodingResponseWriter) VersionBody(apiOp *types.APIRequest, writer io.Writer, obj interface{}) error {
|
||||
var output interface{}
|
||||
var (
|
||||
output interface{}
|
||||
revision string
|
||||
)
|
||||
|
||||
builder := builder.NewBuilder(apiOp)
|
||||
if apiObject, ok := obj.(types.APIObject); ok {
|
||||
obj = apiObject.Raw()
|
||||
revision = apiObject.ListRevision
|
||||
}
|
||||
|
||||
switch v := obj.(type) {
|
||||
@@ -59,6 +63,10 @@ func (j *EncodingResponseWriter) VersionBody(apiOp *types.APIRequest, writer io.
|
||||
output = v
|
||||
}
|
||||
|
||||
if list, ok := output.(*types.GenericCollection); ok && revision != "" {
|
||||
list.Revision = revision
|
||||
}
|
||||
|
||||
if output != nil {
|
||||
return j.Encoder(writer, output)
|
||||
}
|
||||
|
21
vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go
generated
vendored
21
vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go
generated
vendored
@@ -1,6 +1,7 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
errors2 "github.com/pkg/errors"
|
||||
@@ -51,12 +52,24 @@ func (s *Store) byID(apiOp *types.APIRequest, schema *types.Schema, id string) (
|
||||
return s.singleResult(apiOp, schema, resp)
|
||||
}
|
||||
|
||||
func max(old int, newInt string) int {
|
||||
v, err := strconv.Atoi(newInt)
|
||||
if err != nil {
|
||||
return old
|
||||
}
|
||||
if v > old {
|
||||
return v
|
||||
}
|
||||
return old
|
||||
}
|
||||
|
||||
func (s *Store) List(apiOp *types.APIRequest, schema *types.Schema, opt *types.QueryOptions) (types.APIObject, error) {
|
||||
resultList := &unstructured.UnstructuredList{}
|
||||
|
||||
var (
|
||||
errGroup errgroup.Group
|
||||
mux sync.Mutex
|
||||
revision int
|
||||
)
|
||||
|
||||
if len(apiOp.Namespaces) <= 1 {
|
||||
@@ -69,6 +82,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.Schema, opt *types.Q
|
||||
if err != nil {
|
||||
return types.APIObject{}, err
|
||||
}
|
||||
revision = max(revision, resultList.GetResourceVersion())
|
||||
} else {
|
||||
allNS := apiOp.Namespaces
|
||||
for _, ns := range allNS {
|
||||
@@ -81,6 +95,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.Schema, opt *types.Q
|
||||
|
||||
mux.Lock()
|
||||
resultList.Items = append(resultList.Items, list.Items...)
|
||||
revision = max(revision, list.GetResourceVersion())
|
||||
mux.Unlock()
|
||||
|
||||
return nil
|
||||
@@ -96,7 +111,11 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.Schema, opt *types.Q
|
||||
result = append(result, s.fromInternal(apiOp, schema, obj.Object))
|
||||
}
|
||||
|
||||
return types.ToAPI(result), nil
|
||||
apiObject := types.ToAPI(result)
|
||||
if revision > 0 {
|
||||
apiObject.ListRevision = strconv.Itoa(revision)
|
||||
}
|
||||
return apiObject, nil
|
||||
}
|
||||
|
||||
func (s *Store) listNamespace(namespace string, apiOp types.APIRequest, schema *types.Schema) (*unstructured.UnstructuredList, error) {
|
||||
|
3
vendor/github.com/rancher/norman/pkg/types/server_types.go
generated
vendored
3
vendor/github.com/rancher/norman/pkg/types/server_types.go
generated
vendored
@@ -214,7 +214,8 @@ type APIEvent struct {
|
||||
}
|
||||
|
||||
type APIObject struct {
|
||||
Object interface{} `json:",inline"`
|
||||
ListRevision string `json:"-"`
|
||||
Object interface{} `json:",inline"`
|
||||
}
|
||||
|
||||
func ToAPI(data interface{}) APIObject {
|
||||
|
1
vendor/github.com/rancher/norman/pkg/types/types.go
generated
vendored
1
vendor/github.com/rancher/norman/pkg/types/types.go
generated
vendored
@@ -13,6 +13,7 @@ type Collection struct {
|
||||
Sort *Sort `json:"sort,omitempty"`
|
||||
Filters map[string][]Condition `json:"filters,omitempty"`
|
||||
ResourceType string `json:"resourceType"`
|
||||
Revision string `json:"revision,omitempty"`
|
||||
}
|
||||
|
||||
type GenericCollection struct {
|
||||
|
Reference in New Issue
Block a user