1
0
mirror of https://github.com/rancher/types.git synced 2025-08-31 12:48:45 +00:00

Update vendor

This commit is contained in:
Darren Shepherd
2018-12-17 16:08:12 -07:00
parent c0e0d4dd2b
commit e6cf6cb0f7
8 changed files with 60 additions and 23 deletions

View File

@@ -2,5 +2,5 @@
github.com/rancher/types
github.com/pkg/errors v0.8.0
github.com/rancher/norman 1d24e0fc0b0a92dfc48012e82219e0d584cb8b0b transitive=true
github.com/rancher/norman 457c15b94acae52afb5290aa315452c7621d452a transitive=true
github.com/coreos/prometheus-operator v0.25.0

View File

@@ -200,7 +200,7 @@ func (g *genericController) Start(ctx context.Context, threadiness int) error {
if g.running {
for _, h := range g.handlers {
if h.generation < g.generation {
if h.generation != g.generation {
continue
}
for _, key := range g.informer.GetStore().ListKeys() {

View File

@@ -13,6 +13,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"
)
@@ -35,6 +36,13 @@ var (
}
)
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
obj.Namespace = namespace
return &obj
}
type {{.schema.CodeName}}List struct {
metav1.TypeMeta %BACK%json:",inline"%BACK%
metav1.ListMeta %BACK%json:"metadata,omitempty"%BACK%
@@ -231,8 +239,8 @@ func (s *{{.schema.ID}}Client) Watch(opts metav1.ListOptions) (watch.Interface,
}
// Patch applies the patch and returns the patched deployment.
func (s *{{.schema.ID}}Client) Patch(o *{{.prefix}}{{.schema.CodeName}}, data []byte, subresources ...string) (*{{.prefix}}{{.schema.CodeName}}, error) {
obj, err := s.objectClient.Patch(o.Name, o, data, subresources...)
func (s *{{.schema.ID}}Client) Patch(o *{{.prefix}}{{.schema.CodeName}}, patchType types.PatchType, data []byte, subresources ...string) (*{{.prefix}}{{.schema.CodeName}}, error) {
obj, err := s.objectClient.Patch(o.Name, o, patchType, data, subresources...)
return obj.(*{{.prefix}}{{.schema.CodeName}}), err
}
@@ -284,6 +292,7 @@ type {{.schema.CodeName}}Client interface {
Enqueue(namespace, name string)
Generic() controller.GenericController
ObjectClient() *objectclient.ObjectClient
Interface() {{.schema.CodeName}}Interface
}
@@ -304,6 +313,10 @@ func (n *{{.schema.ID}}Client2) Generic() controller.GenericController {
return n.iface.Controller().Generic()
}
func (n *{{.schema.ID}}Client2) ObjectClient() *objectclient.ObjectClient {
return n.Interface().ObjectClient()
}
func (n *{{.schema.ID}}Client2) Enqueue(namespace, name string) {
n.iface.Controller().Enqueue(namespace, name)
}

View File

@@ -26,6 +26,7 @@ type Interface interface {
}
type Clients struct {
Interface Interface
{{range .schemas}}
{{.CodeName}} {{.CodeName}}Client{{end}}
}
@@ -69,6 +70,7 @@ func NewClients(config rest.Config) (*Clients, error) {
func NewClientsFromInterface(iface Interface) *Clients {
return &Clients{
Interface: iface,
{{range .schemas}}
{{.CodeName}}: &{{.ID}}Client2{
iface: iface.{{.CodeNamePlural}}(""),

View File

@@ -178,23 +178,23 @@ func (o *objectLifecycleAdapter) record(obj runtime.Object, f func(runtime.Objec
origObj := obj
obj = origObj.DeepCopyObject()
if newObj, err := f(obj); err != nil {
if newObj, err := checkNil(obj, f); err != nil {
newObj, _ = o.update(metadata.GetName(), origObj, newObj)
return newObj, err
} else if newObj != nil {
newMetadata, err := meta.Accessor(newObj)
if err != nil {
// don't return error, no original error
return newObj, nil
}
if newMetadata.GetResourceVersion() == metadata.GetResourceVersion() {
return o.update(metadata.GetName(), origObj, newObj)
}
return newObj, nil
return o.update(metadata.GetName(), origObj, newObj)
}
return obj, nil
}
func checkNil(obj runtime.Object, f func(runtime.Object) (runtime.Object, error)) (runtime.Object, error) {
obj, err := f(obj)
if obj == nil || reflect.ValueOf(obj).IsNil() {
return nil, err
}
return obj, err
}
func (o *objectLifecycleAdapter) create(obj runtime.Object) (runtime.Object, bool, error) {
metadata, err := meta.Accessor(obj)
if err != nil {

View File

@@ -48,7 +48,7 @@ type GenericClient interface {
List(opts metav1.ListOptions) (runtime.Object, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOptions *metav1.DeleteOptions, listOptions metav1.ListOptions) error
Patch(name string, o runtime.Object, data []byte, subresources ...string) (runtime.Object, error)
Patch(name string, o runtime.Object, patchType types.PatchType, data []byte, subresources ...string) (runtime.Object, error)
ObjectFactory() ObjectFactory
}
@@ -284,7 +284,7 @@ func (p *ObjectClient) DeleteCollection(deleteOptions *metav1.DeleteOptions, lis
Error()
}
func (p *ObjectClient) Patch(name string, o runtime.Object, data []byte, subresources ...string) (runtime.Object, error) {
func (p *ObjectClient) Patch(name string, o runtime.Object, patchType types.PatchType, data []byte, subresources ...string) (runtime.Object, error) {
ns := p.ns
if obj, ok := o.(metav1.Object); ok && obj.GetNamespace() != "" {
ns = obj.GetNamespace()
@@ -293,7 +293,7 @@ func (p *ObjectClient) Patch(name string, o runtime.Object, data []byte, subreso
if len(name) == 0 {
return result, errors.New("object missing name")
}
err := p.restClient.Patch(types.StrategicMergePatchType).
err := p.restClient.Patch(patchType).
Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version).
NamespaceIfScoped(ns, p.resource.Namespaced).
Resource(p.resource.Name).

View File

@@ -83,6 +83,9 @@ func (s *Schemas) newSchemaFromType(version *APIVersion, t reflect.Type, typeNam
CollectionActions: map[string]Action{},
}
s.processingTypes[t] = schema
defer delete(s.processingTypes, t)
if err := s.readFields(schema, t); err != nil {
return nil, err
}
@@ -148,6 +151,11 @@ func (s *Schemas) importType(version *APIVersion, t reflect.Type, overrides ...r
return existing, nil
}
if s, ok := s.processingTypes[t]; ok {
logrus.Debugf("Returning half built schema %s for %v", typeName, t)
return s, nil
}
logrus.Debugf("Inspecting schema %s for %v", typeName, t)
schema, err := s.newSchemaFromType(version, t, typeName)
@@ -289,7 +297,9 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
fieldType.Kind() == reflect.Uint32 ||
fieldType.Kind() == reflect.Int32 ||
fieldType.Kind() == reflect.Uint64 ||
fieldType.Kind() == reflect.Int64 {
fieldType.Kind() == reflect.Int64 ||
fieldType.Kind() == reflect.Float32 ||
fieldType.Kind() == reflect.Float64 {
schemaField.Nullable = false
schemaField.Default = 0
}
@@ -314,6 +324,12 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
return err
}
schemaField.Default = n
case "float":
n, err := convert.ToFloat(schemaField.Default)
if err != nil {
return err
}
schemaField.Default = n
case "boolean":
schemaField.Default = convert.ToBool(schemaField.Default)
}
@@ -446,6 +462,10 @@ func (s *Schemas) determineSchemaType(version *APIVersion, t reflect.Type) (stri
fallthrough
case reflect.Int64:
return "int", nil
case reflect.Float32:
fallthrough
case reflect.Float64:
return "float", nil
case reflect.Interface:
return "json", nil
case reflect.Map:

View File

@@ -29,6 +29,7 @@ type BackReference struct {
type Schemas struct {
sync.Mutex
processingTypes map[reflect.Type]*Schema
typeNames map[reflect.Type]string
schemasByPath map[string]map[string]*Schema
mappers map[string]map[string][]Mapper
@@ -44,11 +45,12 @@ type Schemas struct {
func NewSchemas() *Schemas {
return &Schemas{
typeNames: map[reflect.Type]string{},
schemasByPath: map[string]map[string]*Schema{},
mappers: map[string]map[string][]Mapper{},
references: map[string][]BackReference{},
embedded: map[string]*Schema{},
processingTypes: map[reflect.Type]*Schema{},
typeNames: map[reflect.Type]string{},
schemasByPath: map[string]map[string]*Schema{},
mappers: map[string]map[string][]Mapper{},
references: map[string][]BackReference{},
embedded: map[string]*Schema{},
}
}