mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-09 09:00:31 +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 {
|
if opts == nil {
|
||||||
opts = &types.QueryOptions{}
|
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 {
|
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 {
|
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)
|
builder := builder.NewBuilder(apiOp)
|
||||||
if apiObject, ok := obj.(types.APIObject); ok {
|
if apiObject, ok := obj.(types.APIObject); ok {
|
||||||
obj = apiObject.Raw()
|
obj = apiObject.Raw()
|
||||||
|
revision = apiObject.ListRevision
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := obj.(type) {
|
switch v := obj.(type) {
|
||||||
@@ -59,6 +63,10 @@ func (j *EncodingResponseWriter) VersionBody(apiOp *types.APIRequest, writer io.
|
|||||||
output = v
|
output = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if list, ok := output.(*types.GenericCollection); ok && revision != "" {
|
||||||
|
list.Revision = revision
|
||||||
|
}
|
||||||
|
|
||||||
if output != nil {
|
if output != nil {
|
||||||
return j.Encoder(writer, output)
|
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
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
errors2 "github.com/pkg/errors"
|
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)
|
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) {
|
func (s *Store) List(apiOp *types.APIRequest, schema *types.Schema, opt *types.QueryOptions) (types.APIObject, error) {
|
||||||
resultList := &unstructured.UnstructuredList{}
|
resultList := &unstructured.UnstructuredList{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errGroup errgroup.Group
|
errGroup errgroup.Group
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
|
revision int
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(apiOp.Namespaces) <= 1 {
|
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 {
|
if err != nil {
|
||||||
return types.APIObject{}, err
|
return types.APIObject{}, err
|
||||||
}
|
}
|
||||||
|
revision = max(revision, resultList.GetResourceVersion())
|
||||||
} else {
|
} else {
|
||||||
allNS := apiOp.Namespaces
|
allNS := apiOp.Namespaces
|
||||||
for _, ns := range allNS {
|
for _, ns := range allNS {
|
||||||
@@ -81,6 +95,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.Schema, opt *types.Q
|
|||||||
|
|
||||||
mux.Lock()
|
mux.Lock()
|
||||||
resultList.Items = append(resultList.Items, list.Items...)
|
resultList.Items = append(resultList.Items, list.Items...)
|
||||||
|
revision = max(revision, list.GetResourceVersion())
|
||||||
mux.Unlock()
|
mux.Unlock()
|
||||||
|
|
||||||
return nil
|
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))
|
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) {
|
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 {
|
type APIObject struct {
|
||||||
Object interface{} `json:",inline"`
|
ListRevision string `json:"-"`
|
||||||
|
Object interface{} `json:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToAPI(data interface{}) APIObject {
|
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"`
|
Sort *Sort `json:"sort,omitempty"`
|
||||||
Filters map[string][]Condition `json:"filters,omitempty"`
|
Filters map[string][]Condition `json:"filters,omitempty"`
|
||||||
ResourceType string `json:"resourceType"`
|
ResourceType string `json:"resourceType"`
|
||||||
|
Revision string `json:"revision,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenericCollection struct {
|
type GenericCollection struct {
|
||||||
|
Reference in New Issue
Block a user