diff --git a/vendor.conf b/vendor.conf index e2b04cd9..5f691494 100644 --- a/vendor.conf +++ b/vendor.conf @@ -5,4 +5,4 @@ k8s.io/kubernetes v1.8.3 bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5 -github.com/rancher/norman e6973cb055f2390e8814884353981ffa5496e30c +github.com/rancher/norman 79b91ea33c9ce18094018b26e86fa2577cac2bdd diff --git a/vendor/github.com/rancher/norman/clientbase/ops.go b/vendor/github.com/rancher/norman/clientbase/ops.go index b96d1760..740ea5c4 100644 --- a/vendor/github.com/rancher/norman/clientbase/ops.go +++ b/vendor/github.com/rancher/norman/clientbase/ops.go @@ -285,6 +285,10 @@ func (a *APIOperations) doAction( var input io.Reader + if debug { + fmt.Println("POST " + actionURL) + } + if inputObject != nil { bodyContent, err := json.Marshal(inputObject) if err != nil { @@ -325,5 +329,8 @@ func (a *APIOperations) doAction( fmt.Println("Response <= " + string(byteContent)) } - return json.Unmarshal(byteContent, respObject) + if nil != respObject { + return json.Unmarshal(byteContent, respObject) + } + return nil } diff --git a/vendor/github.com/rancher/norman/controller/cluster_check.go b/vendor/github.com/rancher/norman/controller/cluster_check.go index a548f96c..0389ddfd 100644 --- a/vendor/github.com/rancher/norman/controller/cluster_check.go +++ b/vendor/github.com/rancher/norman/controller/cluster_check.go @@ -39,6 +39,11 @@ func ObjectInCluster(cluster string, obj interface{}) bool { } } } + if clusterName == "" { + if c := getValue(obj, "Namespace"); c.IsValid() { + clusterName = c.String() + } + } return clusterName == cluster } diff --git a/vendor/github.com/rancher/norman/generator/generator.go b/vendor/github.com/rancher/norman/generator/generator.go index c4ae7259..5d340a85 100644 --- a/vendor/github.com/rancher/norman/generator/generator.go +++ b/vendor/github.com/rancher/norman/generator/generator.go @@ -78,6 +78,8 @@ func getTypeString(nullable bool, typeName string, schema *types.Schema, schemas return "intstr.IntOrString" case "dnsLabel": return "string" + case "hostname": + return "string" default: if schema != nil && schemas != nil { otherSchema := schemas.Schema(&schema.Version, typeName) diff --git a/vendor/github.com/rancher/norman/types/condition.go b/vendor/github.com/rancher/norman/types/condition.go index 64dbd433..9be6210b 100644 --- a/vendor/github.com/rancher/norman/types/condition.go +++ b/vendor/github.com/rancher/norman/types/condition.go @@ -39,35 +39,44 @@ type QueryCondition struct { left, right *QueryCondition } -func (q *QueryCondition) Valid(data map[string]interface{}) bool { +func (q *QueryCondition) Valid(schema *Schema, data map[string]interface{}) bool { switch q.conditionType { case CondAnd: if q.left == nil || q.right == nil { return false } - return q.left.Valid(data) && q.right.Valid(data) + return q.left.Valid(schema, data) && q.right.Valid(schema, data) case CondOr: if q.left == nil || q.right == nil { return false } - return q.left.Valid(data) || q.right.Valid(data) + return q.left.Valid(schema, data) || q.right.Valid(schema, data) case CondEQ: - return q.Value == convert.ToString(data[q.Field]) + return q.Value == convert.ToString(valueOrDefault(schema, data, q)) case CondNE: - return q.Value != convert.ToString(data[q.Field]) + return q.Value != convert.ToString(valueOrDefault(schema, data, q)) case CondIn: - return q.Values[convert.ToString(data[q.Field])] + return q.Values[convert.ToString(valueOrDefault(schema, data, q))] case CondNotIn: - return !q.Values[convert.ToString(data[q.Field])] + return !q.Values[convert.ToString(valueOrDefault(schema, data, q))] case CondNotNull: - return convert.ToString(data[q.Field]) != "" + return convert.ToString(valueOrDefault(schema, data, q)) != "" case CondNull: - return convert.ToString(data[q.Field]) == "" + return convert.ToString(valueOrDefault(schema, data, q)) == "" } return false } +func valueOrDefault(schema *Schema, data map[string]interface{}, q *QueryCondition) interface{} { + value := data[q.Field] + if value == nil { + value = schema.ResourceFields[q.Field].Default + } + + return value +} + func (q *QueryCondition) ToCondition() Condition { cond := Condition{ Modifier: q.conditionType.Name, diff --git a/vendor/github.com/rancher/norman/types/reflection.go b/vendor/github.com/rancher/norman/types/reflection.go index fe240cac..cf70770e 100644 --- a/vendor/github.com/rancher/norman/types/reflection.go +++ b/vendor/github.com/rancher/norman/types/reflection.go @@ -48,6 +48,10 @@ func (s *Schemas) AddMapperForType(version *APIVersion, obj interface{}, mapper } func (s *Schemas) MustImport(version *APIVersion, obj interface{}, externalOverrides ...interface{}) *Schemas { + if reflect.ValueOf(obj).Kind() == reflect.Ptr { + panic(fmt.Errorf("obj cannot be a pointer")) + } + if _, err := s.Import(version, obj, externalOverrides...); err != nil { panic(err) } @@ -97,6 +101,8 @@ func (s *Schemas) setupFilters(schema *Schema) { mods = []ModifierType{ModifierEQ, ModifierNE, ModifierIn, ModifierNotIn} case "dnsLabel": fallthrough + case "hostname": + fallthrough case "string": mods = []ModifierType{ModifierEQ, ModifierNE, ModifierIn, ModifierNotIn} case "int": diff --git a/vendor/github.com/rancher/norman/types/server_types.go b/vendor/github.com/rancher/norman/types/server_types.go index 74f27d7b..3b11ead7 100644 --- a/vendor/github.com/rancher/norman/types/server_types.go +++ b/vendor/github.com/rancher/norman/types/server_types.go @@ -49,7 +49,7 @@ type ActionHandler func(actionName string, action *Action, request *APIContext) type RequestHandler func(request *APIContext, next RequestHandler) error -type QueryFilter func(opts *QueryOptions, data []map[string]interface{}) []map[string]interface{} +type QueryFilter func(opts *QueryOptions, schema *Schema, data []map[string]interface{}) []map[string]interface{} type Validator func(request *APIContext, schema *Schema, data map[string]interface{}) error @@ -127,25 +127,25 @@ func (r *APIContext) WriteResponse(code int, obj interface{}) { r.ResponseWriter.Write(r, code, obj) } -func (r *APIContext) FilterList(opts *QueryOptions, obj []map[string]interface{}) []map[string]interface{} { - return r.QueryFilter(opts, obj) +func (r *APIContext) FilterList(opts *QueryOptions, schema *Schema, obj []map[string]interface{}) []map[string]interface{} { + return r.QueryFilter(opts, schema, obj) } -func (r *APIContext) FilterObject(opts *QueryOptions, obj map[string]interface{}) map[string]interface{} { +func (r *APIContext) FilterObject(opts *QueryOptions, schema *Schema, obj map[string]interface{}) map[string]interface{} { opts.Pagination = nil - result := r.QueryFilter(opts, []map[string]interface{}{obj}) + result := r.QueryFilter(opts, schema, []map[string]interface{}{obj}) if len(result) == 0 { return nil } return result[0] } -func (r *APIContext) Filter(opts *QueryOptions, obj interface{}) interface{} { +func (r *APIContext) Filter(opts *QueryOptions, schema *Schema, obj interface{}) interface{} { switch v := obj.(type) { case []map[string]interface{}: - return r.FilterList(opts, v) + return r.FilterList(opts, schema, v) case map[string]interface{}: - return r.FilterObject(opts, v) + return r.FilterObject(opts, schema, v) } return nil