1
0
mirror of https://github.com/rancher/types.git synced 2025-09-03 06:04:24 +00:00

Update vendor

This commit is contained in:
Darren Shepherd
2018-01-18 16:42:44 -07:00
parent fae7ebb808
commit 84b8fb5d3a
5 changed files with 100 additions and 9 deletions

View File

@@ -95,7 +95,7 @@ func (p *ObjectClient) Create(o runtime.Object) (runtime.Object, error) {
return result, err
}
func (p *ObjectClient) GetNamespace(name, namespace string, opts metav1.GetOptions) (runtime.Object, error) {
func (p *ObjectClient) GetNamespaced(namespace, name string, opts metav1.GetOptions) (runtime.Object, error) {
result := p.Factory.Object()
req := p.restClient.Get().
Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version)
@@ -145,7 +145,7 @@ func (p *ObjectClient) Update(name string, o runtime.Object) (runtime.Object, er
return result, err
}
func (p *ObjectClient) DeleteNamespace(name, namespace string, opts *metav1.DeleteOptions) error {
func (p *ObjectClient) DeleteNamespaced(namespace, name string, opts *metav1.DeleteOptions) error {
req := p.restClient.Delete().
Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version)
if namespace != "" {

View File

@@ -61,11 +61,11 @@ type {{.schema.CodeName}}Controller interface {
type {{.schema.CodeName}}Interface interface {
ObjectClient() *clientbase.ObjectClient
Create(*{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error)
GetNamespace(name, namespace string, opts metav1.GetOptions) (*{{.prefix}}{{.schema.CodeName}}, error)
GetNamespaced(namespace, name string, opts metav1.GetOptions) (*{{.prefix}}{{.schema.CodeName}}, error)
Get(name string, opts metav1.GetOptions) (*{{.prefix}}{{.schema.CodeName}}, error)
Update(*{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error)
Delete(name string, options *metav1.DeleteOptions) error
DeleteNamespace(name, namespace string, options *metav1.DeleteOptions) error
DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (*{{.schema.CodeName}}List, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
@@ -203,8 +203,8 @@ func (s *{{.schema.ID}}Client) Get(name string, opts metav1.GetOptions) (*{{.pre
return obj.(*{{.prefix}}{{.schema.CodeName}}), err
}
func (s *{{.schema.ID}}Client) GetNamespace(name, namespace string, opts metav1.GetOptions) (*{{.prefix}}{{.schema.CodeName}}, error) {
obj, err := s.objectClient.GetNamespace(name, namespace, opts)
func (s *{{.schema.ID}}Client) GetNamespaced(namespace, name string, opts metav1.GetOptions) (*{{.prefix}}{{.schema.CodeName}}, error) {
obj, err := s.objectClient.GetNamespaced(namespace, name, opts)
return obj.(*{{.prefix}}{{.schema.CodeName}}), err
}
@@ -217,8 +217,8 @@ func (s *{{.schema.ID}}Client) Delete(name string, options *metav1.DeleteOptions
return s.objectClient.Delete(name, options)
}
func (s *{{.schema.ID}}Client) DeleteNamespace(name, namespace string, options *metav1.DeleteOptions) error {
return s.objectClient.DeleteNamespace(name, namespace, options)
func (s *{{.schema.ID}}Client) DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error {
return s.objectClient.DeleteNamespaced(namespace, name, options)
}
func (s *{{.schema.ID}}Client) List(opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) {

View File

@@ -11,6 +11,9 @@ import (
)
func Chan(c <-chan map[string]interface{}, f func(map[string]interface{}) map[string]interface{}) chan map[string]interface{} {
if c == nil {
return nil
}
result := make(chan map[string]interface{})
go func() {
for data := range c {

View File

@@ -0,0 +1,88 @@
package convert
import (
"strings"
)
func APIUpdateMerge(dest, src map[string]interface{}, replace bool) map[string]interface{} {
result := map[string]interface{}{}
if replace {
if status, ok := dest["status"]; ok {
result["status"] = status
}
if metadata, ok := dest["metadata"]; ok {
result["metadata"] = metadata
}
} else {
result = copyMap(dest)
}
for k, v := range src {
if k == "metadata" {
result["metadata"] = mergeMetadata(ToMapInterface(dest["metadata"]), ToMapInterface(v))
} else if k == "status" {
continue
}
existing, ok := dest[k]
if ok && !replace {
result[k] = merge(existing, v)
} else {
result[k] = v
}
}
return result
}
func mergeMetadata(dest map[string]interface{}, src map[string]interface{}) map[string]interface{} {
result := copyMap(dest)
labels := mergeMaps(ToMapInterface(dest["labels"]), ToMapInterface(src["labels"]))
existingAnnotation := ToMapInterface(dest["annotations"])
newAnnotation := ToMapInterface(src["annotations"])
annotations := copyMap(existingAnnotation)
for k, v := range newAnnotation {
if strings.Contains(k, "cattle.io/") {
continue
}
annotations[k] = v
}
for k, v := range existingAnnotation {
if strings.Contains(k, "cattle.io/") {
annotations[k] = v
}
}
result["labels"] = labels
result["annotations"] = annotations
return result
}
func merge(dest, src interface{}) interface{} {
sm, smOk := src.(map[string]interface{})
dm, dmOk := dest.(map[string]interface{})
if smOk && dmOk {
return mergeMaps(dm, sm)
}
return src
}
func mergeMaps(dest map[string]interface{}, src map[string]interface{}) interface{} {
result := copyMap(dest)
for k, v := range src {
result[k] = merge(dest[k], v)
}
return result
}
func copyMap(src map[string]interface{}) map[string]interface{} {
result := map[string]interface{}{}
for k, v := range src {
result[k] = v
}
return result
}