add Local and Unstructured builder attributes

Moves DisabledClientMapperForMapping wrapper to new Local attribute.
Removes Factory#NewUnstructuredBuilder in favor of new Unstructured
builder attribute.
This commit is contained in:
juanvallejo
2017-08-02 16:23:07 -04:00
parent c10f4f78bc
commit 90d76adb4b
39 changed files with 143 additions and 157 deletions

View File

@@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -67,6 +68,9 @@ type Builder struct {
defaultNamespace bool
requireNamespace bool
isLocal bool
isUnstructured bool
flatten bool
latest bool
@@ -82,6 +86,8 @@ type Builder struct {
schema validation.Schema
}
var LocalUnstructuredBuilderError = fmt.Errorf("Unstructured objects cannot be handled with a local builder - Local and Unstructured attributes cannot be used in conjunction")
var missingResourceError = fmt.Errorf(`You must provide one or more resources by argument or filename.
Example resource specifications include:
'-f rsrc.yaml'
@@ -161,6 +167,35 @@ func (b *Builder) FilenameParam(enforceNamespace bool, filenameOptions *Filename
return b
}
// Local wraps the builder's clientMapper in a DisabledClientMapperForMapping
func (b *Builder) Local(mapperFunc ClientMapperFunc) *Builder {
if b.isUnstructured {
b.errs = append(b.errs, LocalUnstructuredBuilderError)
return b
}
b.isLocal = true
b.mapper.ClientMapper = DisabledClientForMapping{ClientMapper: ClientMapperFunc(mapperFunc)}
return b
}
// Unstructured updates the builder's ClientMapper, RESTMapper,
// ObjectTyper, and codec for working with unstructured api objects
func (b *Builder) Unstructured(mapperFunc ClientMapperFunc, mapper meta.RESTMapper, typer runtime.ObjectTyper) *Builder {
if b.isLocal {
b.errs = append(b.errs, LocalUnstructuredBuilderError)
return b
}
b.isUnstructured = true
b.mapper.RESTMapper = mapper
b.mapper.ObjectTyper = typer
b.mapper.Decoder = unstructured.UnstructuredJSONScheme
b.mapper.ClientMapper = ClientMapperFunc(mapperFunc)
return b
}
// URL accepts a number of URLs directly.
func (b *Builder) URL(httpAttemptCount int, urls ...*url.URL) *Builder {
for _, u := range urls {