diff --git a/vendor.conf b/vendor.conf index cfa30a50..8e8455d8 100644 --- a/vendor.conf +++ b/vendor.conf @@ -2,5 +2,5 @@ github.com/rancher/types github.com/pkg/errors v0.8.0 -github.com/rancher/norman 457c15b94acae52afb5290aa315452c7621d452a transitive=true +github.com/rancher/norman 6e03f4578a4b5b4c50d4194010d5814335439606 transitive=true github.com/coreos/prometheus-operator v0.25.0 diff --git a/vendor/github.com/rancher/norman/.drone.yml b/vendor/github.com/rancher/norman/.drone.yml index 8f5c37cd..a9b80360 100644 --- a/vendor/github.com/rancher/norman/.drone.yml +++ b/vendor/github.com/rancher/norman/.drone.yml @@ -1,9 +1,23 @@ --- -pipeline: - build: - privileged: true - image: rancher/dapper:1.11.2 - volumes: - - /var/run/docker.sock:/var/run/docker.sock - commands: - - dapper ci +kind: pipeline +name: default + +platform: + os: linux + arch: amd64 + +steps: +- name: build + pull: default + image: rancher/dapper:1.11.2 + commands: + - dapper ci + privileged: true + volumes: + - name: socket + path: /var/run/docker.sock + +volumes: +- name: socket + host: + path: /var/run/docker.sock diff --git a/vendor/github.com/rancher/norman/clientbase/common.go b/vendor/github.com/rancher/norman/clientbase/common.go index 2a1331fc..e1ab8f93 100644 --- a/vendor/github.com/rancher/norman/clientbase/common.go +++ b/vendor/github.com/rancher/norman/clientbase/common.go @@ -7,6 +7,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io" "io/ioutil" "net/http" "net/url" @@ -216,7 +217,9 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) { if err != nil { return result, err } - defer resp.Body.Close() + defer func(closer io.Closer) { + closer.Close() + }(resp.Body) if resp.StatusCode != 200 { return result, NewAPIError(resp, opts.URL) @@ -242,7 +245,9 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) { if err != nil { return result, err } - defer resp.Body.Close() + defer func(closer io.Closer) { + closer.Close() + }(resp.Body) if resp.StatusCode != 200 { return result, NewAPIError(resp, schemasURLs) diff --git a/vendor/github.com/rancher/norman/clientbase/ops.go b/vendor/github.com/rancher/norman/clientbase/ops.go index 92ea6e0a..52c2ba6d 100644 --- a/vendor/github.com/rancher/norman/clientbase/ops.go +++ b/vendor/github.com/rancher/norman/clientbase/ops.go @@ -120,6 +120,12 @@ func (a *APIOperations) DoNext(nextURL string, respObject interface{}) error { } func (a *APIOperations) DoModify(method string, url string, createObj interface{}, respObject interface{}) error { + if createObj == nil { + createObj = map[string]string{} + } + if respObject == nil { + respObject = &map[string]interface{}{} + } bodyContent, err := json.Marshal(createObj) if err != nil { return err diff --git a/vendor/github.com/rancher/norman/controller/generic_controller.go b/vendor/github.com/rancher/norman/controller/generic_controller.go index c5213175..02fed9c9 100644 --- a/vendor/github.com/rancher/norman/controller/generic_controller.go +++ b/vendor/github.com/rancher/norman/controller/generic_controller.go @@ -304,7 +304,7 @@ func filterConflictsError(err error) error { var newErrors []error for _, err := range errs.Errors { if !ignoreError(err, true) { - newErrors = append(newErrors) + newErrors = append(newErrors, err) } } return types.NewErrors(newErrors...) diff --git a/vendor/github.com/rancher/norman/generator/controller_template.go b/vendor/github.com/rancher/norman/generator/controller_template.go index 081d9557..db33d34e 100644 --- a/vendor/github.com/rancher/norman/generator/controller_template.go +++ b/vendor/github.com/rancher/norman/generator/controller_template.go @@ -8,6 +8,7 @@ import ( {{.importPackage}} "github.com/rancher/norman/objectclient" "github.com/rancher/norman/controller" + "github.com/rancher/norman/resource" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -34,8 +35,18 @@ var ( {{- end }} Kind: {{.schema.CodeName}}GroupVersionKind.Kind, } + + {{.schema.CodeName}}GroupVersionResource = schema.GroupVersionResource{ + Group: GroupName, + Version: Version, + Resource: "{{.schema.PluralName | toLower}}", + } ) +func init() { + resource.Put({{.schema.CodeName}}GroupVersionResource) +} + func New{{.schema.CodeName}}(namespace, name string, obj {{.prefix}}{{.schema.CodeName}}) *{{.prefix}}{{.schema.CodeName}} { obj.APIVersion, obj.Kind = {{.schema.CodeName}}GroupVersionKind.ToAPIVersionAndKind() obj.Name = name diff --git a/vendor/github.com/rancher/norman/httperror/error.go b/vendor/github.com/rancher/norman/httperror/error.go index 73b10acd..84938d6d 100644 --- a/vendor/github.com/rancher/norman/httperror/error.go +++ b/vendor/github.com/rancher/norman/httperror/error.go @@ -105,6 +105,14 @@ func IsAPIError(err error) bool { return ok } +func IsNotFound(err error) bool { + if apiError, ok := err.(*APIError); ok { + return apiError.Code.Status == 404 + } + + return false +} + func IsConflict(err error) bool { if apiError, ok := err.(*APIError); ok { return apiError.Code.Status == 409 diff --git a/vendor/github.com/rancher/norman/objectclient/object_client.go b/vendor/github.com/rancher/norman/objectclient/object_client.go index 01d1b930..9a09bf0e 100644 --- a/vendor/github.com/rancher/norman/objectclient/object_client.go +++ b/vendor/github.com/rancher/norman/objectclient/object_client.go @@ -102,6 +102,13 @@ func (p *ObjectClient) Create(o runtime.Object) (runtime.Object, error) { labels := obj.GetLabels() if labels == nil { labels = make(map[string]string) + } else { + ls := make(map[string]string) + for k, v := range labels { + ls[k] = v + } + labels = ls + } labels["cattle.io/creator"] = "norman" obj.SetLabels(labels) diff --git a/vendor/github.com/rancher/norman/resource/resource.go b/vendor/github.com/rancher/norman/resource/resource.go new file mode 100644 index 00000000..8ed4eb47 --- /dev/null +++ b/vendor/github.com/rancher/norman/resource/resource.go @@ -0,0 +1,38 @@ +package resource + +import ( + "sync" + + "k8s.io/apimachinery/pkg/runtime/schema" +) + +//rancherTypes is a set of all types generated by rancher +var ( + rancherTypes = struct { + sync.RWMutex + m map[schema.GroupVersionResource]bool + }{m: make(map[schema.GroupVersionResource]bool)} +) + +//Get returns a copy of the set of rancherTypes +func Get() map[schema.GroupVersionResource]bool { + rancherTypes.RLock() + defer rancherTypes.RUnlock() + targetMap := make(map[schema.GroupVersionResource]bool, len(rancherTypes.m)) + for key, value := range rancherTypes.m { + targetMap[key] = value + } + return targetMap +} + +//Put adds an object to the set and panic on collision +func Put(key schema.GroupVersionResource) { + rancherTypes.Lock() + defer rancherTypes.Unlock() + _, exists := rancherTypes.m[key] + if exists { + //only used in an init function + panic("key exists in rancherTypes") + } + rancherTypes.m[key] = true +} diff --git a/vendor/github.com/rancher/norman/restwatch/rest.go b/vendor/github.com/rancher/norman/restwatch/rest.go index 25092052..52d14591 100644 --- a/vendor/github.com/rancher/norman/restwatch/rest.go +++ b/vendor/github.com/rancher/norman/restwatch/rest.go @@ -21,7 +21,7 @@ func UnversionedRESTClientFor(config *rest.Config) (rest.Interface, error) { } newConfig := *config - newConfig.Timeout = time.Hour + newConfig.Timeout = 30 * time.Minute watchClient, err := rest.UnversionedRESTClientFor(&newConfig) if err != nil { return nil, err diff --git a/vendor/github.com/rancher/norman/store/proxy/proxy_store.go b/vendor/github.com/rancher/norman/store/proxy/proxy_store.go index 245e72a9..13927dca 100644 --- a/vendor/github.com/rancher/norman/store/proxy/proxy_store.go +++ b/vendor/github.com/rancher/norman/store/proxy/proxy_store.go @@ -17,6 +17,7 @@ import ( "github.com/rancher/norman/types/convert/merge" "github.com/rancher/norman/types/values" "github.com/sirupsen/logrus" + "golang.org/x/sync/errgroup" "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -192,11 +193,41 @@ func (s *Store) Context() types.StorageContext { } func (s *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) { - namespace := getNamespace(apiContext, opt) + var resultList unstructured.UnstructuredList - resultList, err := s.retryList(namespace, apiContext) - if err != nil { - return nil, err + // if there are no namespaces field in options, a single request is made + if opt == nil || opt.Namespaces == nil { + ns := getNamespace(apiContext, opt) + list, err := s.retryList(ns, apiContext) + if err != nil { + return nil, err + } + resultList = *list + } else { + var ( + errGroup errgroup.Group + mux sync.Mutex + ) + + allNS := opt.Namespaces + for _, ns := range allNS { + nsCopy := ns + errGroup.Go(func() error { + list, err := s.retryList(nsCopy, apiContext) + if err != nil { + return err + } + + mux.Lock() + resultList.Items = append(resultList.Items, list.Items...) + mux.Unlock() + + return nil + }) + } + if err := errGroup.Wait(); err != nil { + return nil, err + } } var result []map[string]interface{} @@ -256,7 +287,7 @@ func (s *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, op k8sClient = watchClient.WatchClient() } - timeout := int64(60 * 60) + timeout := int64(60 * 30) req := s.common(namespace, k8sClient.Get()) req.VersionedParams(&metav1.ListOptions{ Watch: true, diff --git a/vendor/github.com/rancher/norman/types/mapper/embed.go b/vendor/github.com/rancher/norman/types/mapper/embed.go index 554e2435..b1d35d98 100644 --- a/vendor/github.com/rancher/norman/types/mapper/embed.go +++ b/vendor/github.com/rancher/norman/types/mapper/embed.go @@ -70,10 +70,11 @@ func (e *Embed) ModifySchema(schema *types.Schema, schemas *types.Schemas) error } deleteField := true +outer: for name, field := range embeddedSchema.ResourceFields { for _, ignore := range e.Ignore { if ignore == name { - continue + continue outer } } diff --git a/vendor/github.com/rancher/norman/types/schemas.go b/vendor/github.com/rancher/norman/types/schemas.go index 0e72a178..2afee0aa 100644 --- a/vendor/github.com/rancher/norman/types/schemas.go +++ b/vendor/github.com/rancher/norman/types/schemas.go @@ -108,10 +108,16 @@ func (s *Schemas) removeReferences(schema *Schema) { func (s *Schemas) AddSchema(schema Schema) *Schemas { s.Lock() defer s.Unlock() - return s.doAddSchema(schema) + return s.doAddSchema(schema, false) } -func (s *Schemas) doAddSchema(schema Schema) *Schemas { +func (s *Schemas) ForceAddSchema(schema Schema) *Schemas { + s.Lock() + defer s.Unlock() + return s.doAddSchema(schema, true) +} + +func (s *Schemas) doAddSchema(schema Schema, replace bool) *Schemas { s.setupDefaults(&schema) if s.AddHook != nil { @@ -125,9 +131,20 @@ func (s *Schemas) doAddSchema(schema Schema) *Schemas { s.versions = append(s.versions, schema.Version) } - if _, ok := schemas[schema.ID]; !ok { + if _, ok := schemas[schema.ID]; !ok || + (replace && schema.DynamicSchemaVersion != schemas[schema.ID].DynamicSchemaVersion) { schemas[schema.ID] = &schema - s.schemas = append(s.schemas, &schema) + + if replace { + for i, candidate := range s.schemas { + if candidate.ID == schema.ID { + s.schemas[i] = &schema + break + } + } + } else { + s.schemas = append(s.schemas, &schema) + } if !schema.Embed { s.addReferences(&schema) @@ -159,7 +176,7 @@ func (s *Schemas) removeEmbed(schema *Schema) { } s.doRemoveSchema(*target) - s.doAddSchema(newSchema) + s.doAddSchema(newSchema, false) } func (s *Schemas) embed(schema *Schema) { @@ -184,7 +201,7 @@ func (s *Schemas) embed(schema *Schema) { } s.doRemoveSchema(*target) - s.doAddSchema(newSchema) + s.doAddSchema(newSchema, false) } func (s *Schemas) addReferences(schema *Schema) { diff --git a/vendor/github.com/rancher/norman/types/server_types.go b/vendor/github.com/rancher/norman/types/server_types.go index 7fede86f..7e36aa22 100644 --- a/vendor/github.com/rancher/norman/types/server_types.go +++ b/vendor/github.com/rancher/norman/types/server_types.go @@ -184,6 +184,8 @@ type QueryOptions struct { Pagination *Pagination Conditions []*QueryCondition Options map[string]string + // Set namespaces to an empty array will result in an empty response + Namespaces []string } type ReferenceValidator interface { diff --git a/vendor/github.com/rancher/norman/types/types.go b/vendor/github.com/rancher/norman/types/types.go index 21106f5a..9edfd764 100644 --- a/vendor/github.com/rancher/norman/types/types.go +++ b/vendor/github.com/rancher/norman/types/types.go @@ -94,25 +94,26 @@ var NamespaceScope TypeScope = "namespace" type TypeScope string type Schema struct { - ID string `json:"id,omitempty"` - Embed bool `json:"embed,omitempty"` - EmbedType string `json:"embedType,omitempty"` - CodeName string `json:"-"` - CodeNamePlural string `json:"-"` - PkgName string `json:"-"` - Type string `json:"type,omitempty"` - BaseType string `json:"baseType,omitempty"` - Links map[string]string `json:"links"` - Version APIVersion `json:"version"` - PluralName string `json:"pluralName,omitempty"` - ResourceMethods []string `json:"resourceMethods,omitempty"` - ResourceFields map[string]Field `json:"resourceFields"` - ResourceActions map[string]Action `json:"resourceActions,omitempty"` - CollectionMethods []string `json:"collectionMethods,omitempty"` - CollectionFields map[string]Field `json:"collectionFields,omitempty"` - CollectionActions map[string]Action `json:"collectionActions,omitempty"` - CollectionFilters map[string]Filter `json:"collectionFilters,omitempty"` - Scope TypeScope `json:"-"` + ID string `json:"id,omitempty"` + Embed bool `json:"embed,omitempty"` + EmbedType string `json:"embedType,omitempty"` + CodeName string `json:"-"` + CodeNamePlural string `json:"-"` + PkgName string `json:"-"` + Type string `json:"type,omitempty"` + BaseType string `json:"baseType,omitempty"` + Links map[string]string `json:"links"` + Version APIVersion `json:"version"` + PluralName string `json:"pluralName,omitempty"` + ResourceMethods []string `json:"resourceMethods,omitempty"` + ResourceFields map[string]Field `json:"resourceFields"` + ResourceActions map[string]Action `json:"resourceActions,omitempty"` + CollectionMethods []string `json:"collectionMethods,omitempty"` + CollectionFields map[string]Field `json:"collectionFields,omitempty"` + CollectionActions map[string]Action `json:"collectionActions,omitempty"` + CollectionFilters map[string]Filter `json:"collectionFilters,omitempty"` + DynamicSchemaVersion string `json:"dynamicSchemaVersion,omitempty"` + Scope TypeScope `json:"-"` InternalSchema *Schema `json:"-"` Mapper Mapper `json:"-"`