diff --git a/vendor/github.com/rancher/norman/pkg/api/handler/query.go b/vendor/github.com/rancher/norman/pkg/api/handler/query.go index 14c047e..51bee75 100644 --- a/vendor/github.com/rancher/norman/pkg/api/handler/query.go +++ b/vendor/github.com/rancher/norman/pkg/api/handler/query.go @@ -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 { diff --git a/vendor/github.com/rancher/norman/pkg/api/writer/json.go b/vendor/github.com/rancher/norman/pkg/api/writer/json.go index 8d86c77..98ecb64 100644 --- a/vendor/github.com/rancher/norman/pkg/api/writer/json.go +++ b/vendor/github.com/rancher/norman/pkg/api/writer/json.go @@ -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) } diff --git a/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go b/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go index 9feac7b..affd4fc 100644 --- a/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go +++ b/vendor/github.com/rancher/norman/pkg/store/proxy/proxy_store.go @@ -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) { diff --git a/vendor/github.com/rancher/norman/pkg/types/server_types.go b/vendor/github.com/rancher/norman/pkg/types/server_types.go index a234138..bcd7665 100644 --- a/vendor/github.com/rancher/norman/pkg/types/server_types.go +++ b/vendor/github.com/rancher/norman/pkg/types/server_types.go @@ -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 { diff --git a/vendor/github.com/rancher/norman/pkg/types/types.go b/vendor/github.com/rancher/norman/pkg/types/types.go index 8409355..1c28463 100644 --- a/vendor/github.com/rancher/norman/pkg/types/types.go +++ b/vendor/github.com/rancher/norman/pkg/types/types.go @@ -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 {