mirror of
https://github.com/rancher/types.git
synced 2025-07-03 00:36:12 +00:00
Update vendor
This commit is contained in:
parent
93e27221b2
commit
be0508647d
@ -1,7 +1,8 @@
|
||||
# package
|
||||
github.com/rancher/types
|
||||
|
||||
k8s.io/kubernetes v1.8.3 transitive=true,staging=true
|
||||
bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git
|
||||
github.com/rancher/norman 76d825608521a24007cfdb110d9b88d45c50d9c5
|
||||
golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5
|
||||
k8s.io/kubernetes v1.8.3 transitive=true,staging=true
|
||||
bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git
|
||||
golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5
|
||||
|
||||
github.com/rancher/norman 0d8fd60120040ffc232e303b8e260be02ca623c3
|
||||
|
42
vendor/github.com/rancher/norman/condition/condition.go
generated
vendored
42
vendor/github.com/rancher/norman/condition/condition.go
generated
vendored
@ -61,14 +61,23 @@ func (c Cond) Reason(obj runtime.Object, reason string) {
|
||||
getFieldValue(cond, "Reason").SetString(reason)
|
||||
}
|
||||
|
||||
func (c Cond) SetMessageIfBlank(obj runtime.Object, message string) {
|
||||
if c.GetMessage(obj) == "" {
|
||||
c.Message(obj, message)
|
||||
}
|
||||
}
|
||||
|
||||
func (c Cond) Message(obj runtime.Object, message string) {
|
||||
cond := findOrCreateCond(obj, string(c))
|
||||
setValue(cond, "Message", message)
|
||||
}
|
||||
|
||||
func (c Cond) GetMessage(obj runtime.Object) string {
|
||||
cond := findOrCreateCond(obj, string(c))
|
||||
return getFieldValue(cond, "Message").String()
|
||||
cond := findOrNotCreateCond(obj, string(c))
|
||||
if cond == nil {
|
||||
return ""
|
||||
}
|
||||
return getFieldValue(*cond, "Message").String()
|
||||
}
|
||||
|
||||
func (c Cond) ReasonAndMessageFromError(obj runtime.Object, err error) {
|
||||
@ -85,8 +94,11 @@ func (c Cond) ReasonAndMessageFromError(obj runtime.Object, err error) {
|
||||
}
|
||||
|
||||
func (c Cond) GetReason(obj runtime.Object) string {
|
||||
cond := findOrCreateCond(obj, string(c))
|
||||
return getFieldValue(cond, "Reason").String()
|
||||
cond := findOrNotCreateCond(obj, string(c))
|
||||
if cond == nil {
|
||||
return ""
|
||||
}
|
||||
return getFieldValue(*cond, "Reason").String()
|
||||
}
|
||||
|
||||
func (c Cond) Once(obj runtime.Object, f func() (runtime.Object, error)) (runtime.Object, error) {
|
||||
@ -162,8 +174,11 @@ func touchTS(value reflect.Value) {
|
||||
}
|
||||
|
||||
func getStatus(obj interface{}, condName string) string {
|
||||
cond := findOrCreateCond(obj, condName)
|
||||
return getFieldValue(cond, "Status").String()
|
||||
cond := findOrNotCreateCond(obj, condName)
|
||||
if cond == nil {
|
||||
return ""
|
||||
}
|
||||
return getFieldValue(*cond, "Status").String()
|
||||
}
|
||||
|
||||
func setTS(obj interface{}, condName, ts string) {
|
||||
@ -172,8 +187,11 @@ func setTS(obj interface{}, condName, ts string) {
|
||||
}
|
||||
|
||||
func getTS(obj interface{}, condName string) string {
|
||||
cond := findOrCreateCond(obj, condName)
|
||||
return getFieldValue(cond, "LastUpdateTime").String()
|
||||
cond := findOrNotCreateCond(obj, condName)
|
||||
if cond == nil {
|
||||
return ""
|
||||
}
|
||||
return getFieldValue(*cond, "LastUpdateTime").String()
|
||||
}
|
||||
|
||||
func setStatus(obj interface{}, condName, status string) {
|
||||
@ -189,6 +207,11 @@ func setValue(cond reflect.Value, fieldName, newValue string) {
|
||||
}
|
||||
}
|
||||
|
||||
func findOrNotCreateCond(obj interface{}, condName string) *reflect.Value {
|
||||
condSlice := getValue(obj, "Status", "Conditions")
|
||||
return findCond(condSlice, condName)
|
||||
}
|
||||
|
||||
func findOrCreateCond(obj interface{}, condName string) reflect.Value {
|
||||
condSlice := getValue(obj, "Status", "Conditions")
|
||||
cond := findCond(condSlice, condName)
|
||||
@ -216,6 +239,9 @@ func findCond(val reflect.Value, name string) *reflect.Value {
|
||||
}
|
||||
|
||||
func getValue(obj interface{}, name ...string) reflect.Value {
|
||||
if obj == nil {
|
||||
return reflect.Value{}
|
||||
}
|
||||
v := reflect.ValueOf(obj)
|
||||
t := v.Type()
|
||||
if t.Kind() == reflect.Ptr {
|
||||
|
12
vendor/github.com/rancher/norman/controller/generic_controller.go
generated
vendored
12
vendor/github.com/rancher/norman/controller/generic_controller.go
generated
vendored
@ -6,6 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/juju/ratelimit"
|
||||
"github.com/rancher/norman/clientbase"
|
||||
"github.com/rancher/norman/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -53,11 +54,16 @@ func NewGenericController(name string, objectClient *clientbase.ObjectClient) Ge
|
||||
},
|
||||
objectClient.Factory.Object(), resyncPeriod, cache.Indexers{})
|
||||
|
||||
rl := workqueue.NewMaxOfRateLimiter(
|
||||
workqueue.NewItemExponentialFailureRateLimiter(500*time.Millisecond, 1000*time.Second),
|
||||
// 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
|
||||
&workqueue.BucketRateLimiter{Bucket: ratelimit.NewBucketWithRate(float64(10), int64(100))},
|
||||
)
|
||||
|
||||
return &genericController{
|
||||
informer: informer,
|
||||
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(),
|
||||
name),
|
||||
name: name,
|
||||
queue: workqueue.NewNamedRateLimitingQueue(rl, name),
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
|
19
vendor/github.com/rancher/norman/types/convert/convert.go
generated
vendored
19
vendor/github.com/rancher/norman/types/convert/convert.go
generated
vendored
@ -1,6 +1,7 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -85,6 +86,18 @@ func ToNumber(value interface{}) (int64, error) {
|
||||
if ok {
|
||||
return i, nil
|
||||
}
|
||||
f, ok := value.(float64)
|
||||
if ok {
|
||||
return int64(f), nil
|
||||
}
|
||||
if n, ok := value.(json.Number); ok {
|
||||
i, err := n.Int64()
|
||||
if err == nil {
|
||||
return i, nil
|
||||
}
|
||||
f, err := n.Float64()
|
||||
return int64(f), err
|
||||
}
|
||||
return strconv.ParseInt(ToString(value), 10, 64)
|
||||
}
|
||||
|
||||
@ -185,10 +198,12 @@ func ToObj(data interface{}, into interface{}) error {
|
||||
}
|
||||
|
||||
func EncodeToMap(obj interface{}) (map[string]interface{}, error) {
|
||||
bytes, err := json.Marshal(obj)
|
||||
b, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := map[string]interface{}{}
|
||||
return result, json.Unmarshal(bytes, &result)
|
||||
dec := json.NewDecoder(bytes.NewBuffer(b))
|
||||
dec.UseNumber()
|
||||
return result, dec.Decode(&result)
|
||||
}
|
||||
|
21
vendor/github.com/rancher/norman/types/server_types.go
generated
vendored
21
vendor/github.com/rancher/norman/types/server_types.go
generated
vendored
@ -1,6 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -54,6 +55,8 @@ type Validator func(request *APIContext, schema *Schema, data map[string]interfa
|
||||
|
||||
type Formatter func(request *APIContext, resource *RawResource)
|
||||
|
||||
type CollectionFormatter func(request *APIContext, collection *GenericCollection)
|
||||
|
||||
type ErrorHandler func(request *APIContext, err error)
|
||||
|
||||
type SubContextAttributeProvider interface {
|
||||
@ -100,6 +103,23 @@ type APIContext struct {
|
||||
Response http.ResponseWriter
|
||||
}
|
||||
|
||||
type apiContextKey struct{}
|
||||
|
||||
func NewAPIContext(req *http.Request, resp http.ResponseWriter, schemas *Schemas) *APIContext {
|
||||
apiCtx := &APIContext{
|
||||
Response: resp,
|
||||
Schemas: schemas,
|
||||
}
|
||||
ctx := context.WithValue(req.Context(), apiContextKey{}, apiCtx)
|
||||
apiCtx.Request = req.WithContext(ctx)
|
||||
return apiCtx
|
||||
}
|
||||
|
||||
func GetAPIContext(ctx context.Context) *APIContext {
|
||||
apiContext, _ := ctx.Value(apiContextKey{}).(*APIContext)
|
||||
return apiContext
|
||||
}
|
||||
|
||||
func (r *APIContext) WriteResponse(code int, obj interface{}) {
|
||||
r.ResponseWriter.Write(r, code, obj)
|
||||
}
|
||||
@ -148,6 +168,7 @@ type ReferenceValidator interface {
|
||||
type URLBuilder interface {
|
||||
Current() string
|
||||
Collection(schema *Schema, versionOverride *APIVersion) string
|
||||
CollectionAction(schema *Schema, versionOverride *APIVersion, action string) string
|
||||
SubContextCollection(subContext *Schema, contextName string, schema *Schema) string
|
||||
SchemaLink(schema *Schema) string
|
||||
ResourceLink(resource *RawResource) string
|
||||
|
29
vendor/github.com/rancher/norman/types/types.go
generated
vendored
29
vendor/github.com/rancher/norman/types/types.go
generated
vendored
@ -103,18 +103,19 @@ type Schema struct {
|
||||
CollectionFilters map[string]Filter `json:"collectionFilters,omitempty"`
|
||||
Scope TypeScope `json:"-"`
|
||||
|
||||
InternalSchema *Schema `json:"-"`
|
||||
Mapper Mapper `json:"-"`
|
||||
ActionHandler ActionHandler `json:"-"`
|
||||
LinkHandler RequestHandler `json:"-"`
|
||||
ListHandler RequestHandler `json:"-"`
|
||||
CreateHandler RequestHandler `json:"-"`
|
||||
DeleteHandler RequestHandler `json:"-"`
|
||||
UpdateHandler RequestHandler `json:"-"`
|
||||
Formatter Formatter `json:"-"`
|
||||
ErrorHandler ErrorHandler `json:"-"`
|
||||
Validator Validator `json:"-"`
|
||||
Store Store `json:"-"`
|
||||
InternalSchema *Schema `json:"-"`
|
||||
Mapper Mapper `json:"-"`
|
||||
ActionHandler ActionHandler `json:"-"`
|
||||
LinkHandler RequestHandler `json:"-"`
|
||||
ListHandler RequestHandler `json:"-"`
|
||||
CreateHandler RequestHandler `json:"-"`
|
||||
DeleteHandler RequestHandler `json:"-"`
|
||||
UpdateHandler RequestHandler `json:"-"`
|
||||
Formatter Formatter `json:"-"`
|
||||
CollectionFormatter CollectionFormatter `json:"-"`
|
||||
ErrorHandler ErrorHandler `json:"-"`
|
||||
Validator Validator `json:"-"`
|
||||
Store Store `json:"-"`
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
@ -148,3 +149,7 @@ type Filter struct {
|
||||
type ListOpts struct {
|
||||
Filters map[string]interface{}
|
||||
}
|
||||
|
||||
func (c *Collection) AddAction(apiContext *APIContext, name string) {
|
||||
c.Actions[name] = apiContext.URLBuilder.CollectionAction(apiContext.Schema, nil, name)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user