Move Ingress godeps to vendor/
This commit is contained in:
parent
0d4f49e50e
commit
ca620e4074
2059 changed files with 3706 additions and 213845 deletions
19
vendor/k8s.io/kubernetes/pkg/registry/generic/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/registry/generic/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package generic provides a generic object store interface and a
|
||||
// generic label/field matching type.
|
||||
package generic
|
||||
142
vendor/k8s.io/kubernetes/pkg/registry/generic/matcher.go
generated
vendored
Normal file
142
vendor/k8s.io/kubernetes/pkg/registry/generic/matcher.go
generated
vendored
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package generic
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// AttrFunc returns label and field sets for List or Watch to compare against, or an error.
|
||||
type AttrFunc func(obj runtime.Object) (label labels.Set, field fields.Set, err error)
|
||||
|
||||
// ObjectMetaFieldsSet returns a fields set that represents the ObjectMeta.
|
||||
func ObjectMetaFieldsSet(objectMeta api.ObjectMeta, hasNamespaceField bool) fields.Set {
|
||||
if !hasNamespaceField {
|
||||
return fields.Set{
|
||||
"metadata.name": objectMeta.Name,
|
||||
}
|
||||
}
|
||||
return fields.Set{
|
||||
"metadata.name": objectMeta.Name,
|
||||
"metadata.namespace": objectMeta.Namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// MergeFieldsSets merges a fields'set from fragment into the source.
|
||||
func MergeFieldsSets(source fields.Set, fragment fields.Set) fields.Set {
|
||||
for k, value := range fragment {
|
||||
source[k] = value
|
||||
}
|
||||
return source
|
||||
}
|
||||
|
||||
// SelectionPredicate implements a generic predicate that can be passed to
|
||||
// GenericRegistry's List or Watch methods. Implements the Matcher interface.
|
||||
type SelectionPredicate struct {
|
||||
Label labels.Selector
|
||||
Field fields.Selector
|
||||
GetAttrs AttrFunc
|
||||
}
|
||||
|
||||
// Matches returns true if the given object's labels and fields (as
|
||||
// returned by s.GetAttrs) match s.Label and s.Field. An error is
|
||||
// returned if s.GetAttrs fails.
|
||||
func (s *SelectionPredicate) Matches(obj runtime.Object) (bool, error) {
|
||||
if s.Label.Empty() && s.Field.Empty() {
|
||||
return true, nil
|
||||
}
|
||||
labels, fields, err := s.GetAttrs(obj)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return s.Label.Matches(labels) && s.Field.Matches(fields), nil
|
||||
}
|
||||
|
||||
// MatchesSingle will return (name, true) if and only if s.Field matches on the object's
|
||||
// name.
|
||||
func (s *SelectionPredicate) MatchesSingle() (string, bool) {
|
||||
// TODO: should be namespace.name
|
||||
if name, ok := s.Field.RequiresExactMatch("metadata.name"); ok {
|
||||
return name, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Matcher can return true if an object matches the Matcher's selection
|
||||
// criteria. If it is known that the matcher will match only a single object
|
||||
// then MatchesSingle should return the key of that object and true. This is an
|
||||
// optimization only--Matches() should continue to work.
|
||||
type Matcher interface {
|
||||
// Matches should return true if obj matches this matcher's requirements.
|
||||
Matches(obj runtime.Object) (matchesThisObject bool, err error)
|
||||
|
||||
// If this matcher matches a single object, return the key for that
|
||||
// object and true here. This will greatly increase efficiency. You
|
||||
// must still implement Matches(). Note that key does NOT need to
|
||||
// include the object's namespace.
|
||||
MatchesSingle() (key string, matchesSingleObject bool)
|
||||
|
||||
// TODO: when we start indexing objects, add something like the below:
|
||||
// MatchesIndices() (indexName []string, indexValue []string)
|
||||
// where indexName/indexValue are the same length.
|
||||
}
|
||||
|
||||
// MatcherFunc makes a matcher from the provided function. For easy definition
|
||||
// of matchers for testing. Note: use SelectionPredicate above for real code!
|
||||
func MatcherFunc(f func(obj runtime.Object) (bool, error)) Matcher {
|
||||
return matcherFunc(f)
|
||||
}
|
||||
|
||||
type matcherFunc func(obj runtime.Object) (bool, error)
|
||||
|
||||
// Matches calls the embedded function.
|
||||
func (m matcherFunc) Matches(obj runtime.Object) (bool, error) {
|
||||
return m(obj)
|
||||
}
|
||||
|
||||
// MatchesSingle always returns "", false-- because this is a predicate
|
||||
// implementation of Matcher.
|
||||
func (m matcherFunc) MatchesSingle() (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// MatchOnKey returns a matcher that will send only the object matching key
|
||||
// through the matching function f. For testing!
|
||||
// Note: use SelectionPredicate above for real code!
|
||||
func MatchOnKey(key string, f func(obj runtime.Object) (bool, error)) Matcher {
|
||||
return matchKey{key, f}
|
||||
}
|
||||
|
||||
type matchKey struct {
|
||||
key string
|
||||
matcherFunc
|
||||
}
|
||||
|
||||
// MatchesSingle always returns its key, true.
|
||||
func (m matchKey) MatchesSingle() (string, bool) {
|
||||
return m.key, true
|
||||
}
|
||||
|
||||
var (
|
||||
// Assert implementations match the interface.
|
||||
_ = Matcher(matchKey{})
|
||||
_ = Matcher(&SelectionPredicate{})
|
||||
_ = Matcher(matcherFunc(nil))
|
||||
)
|
||||
28
vendor/k8s.io/kubernetes/pkg/registry/generic/options.go
generated
vendored
Normal file
28
vendor/k8s.io/kubernetes/pkg/registry/generic/options.go
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package generic
|
||||
|
||||
import (
|
||||
pkgstorage "k8s.io/kubernetes/pkg/storage"
|
||||
)
|
||||
|
||||
// RESTOptions is set of configuration options to generic registries.
|
||||
type RESTOptions struct {
|
||||
Storage pkgstorage.Interface
|
||||
Decorator StorageDecorator
|
||||
DeleteCollectionWorkers int
|
||||
}
|
||||
44
vendor/k8s.io/kubernetes/pkg/registry/generic/storage_decorator.go
generated
vendored
Normal file
44
vendor/k8s.io/kubernetes/pkg/registry/generic/storage_decorator.go
generated
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package generic
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/storage"
|
||||
)
|
||||
|
||||
// StorageDecorator is a function signature for producing
|
||||
// a storage.Interface from given parameters.
|
||||
type StorageDecorator func(
|
||||
storageInterface storage.Interface,
|
||||
capacity int,
|
||||
objectType runtime.Object,
|
||||
resourcePrefix string,
|
||||
scopeStrategy rest.NamespaceScopedStrategy,
|
||||
newListFunc func() runtime.Object) storage.Interface
|
||||
|
||||
// Returns given 'storageInterface' without any decoration.
|
||||
func UndecoratedStorage(
|
||||
storageInterface storage.Interface,
|
||||
capacity int,
|
||||
objectType runtime.Object,
|
||||
resourcePrefix string,
|
||||
scopeStrategy rest.NamespaceScopedStrategy,
|
||||
newListFunc func() runtime.Object) storage.Interface {
|
||||
return storageInterface
|
||||
}
|
||||
484
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/codec.go
generated
vendored
Normal file
484
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/codec.go
generated
vendored
Normal file
|
|
@ -0,0 +1,484 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
apiutil "k8s.io/kubernetes/pkg/api/util"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
)
|
||||
|
||||
type thirdPartyObjectConverter struct {
|
||||
converter runtime.ObjectConvertor
|
||||
}
|
||||
|
||||
func (t *thirdPartyObjectConverter) ConvertToVersion(in runtime.Object, outVersion string) (out runtime.Object, err error) {
|
||||
switch in.(type) {
|
||||
// This seems weird, but in this case the ThirdPartyResourceData is really just a wrapper on the raw 3rd party data.
|
||||
// The actual thing printed/sent to server is the actual raw third party resource data, which only has one version.
|
||||
case *extensions.ThirdPartyResourceData:
|
||||
return in, nil
|
||||
default:
|
||||
return t.converter.ConvertToVersion(in, outVersion)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *thirdPartyObjectConverter) Convert(in, out interface{}) error {
|
||||
return t.converter.Convert(in, out)
|
||||
}
|
||||
|
||||
func (t *thirdPartyObjectConverter) ConvertFieldLabel(version, kind, label, value string) (string, string, error) {
|
||||
return t.converter.ConvertFieldLabel(version, kind, label, value)
|
||||
}
|
||||
|
||||
func NewThirdPartyObjectConverter(converter runtime.ObjectConvertor) runtime.ObjectConvertor {
|
||||
return &thirdPartyObjectConverter{converter}
|
||||
}
|
||||
|
||||
type thirdPartyResourceDataMapper struct {
|
||||
mapper meta.RESTMapper
|
||||
kind string
|
||||
version string
|
||||
group string
|
||||
}
|
||||
|
||||
var _ meta.RESTMapper = &thirdPartyResourceDataMapper{}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) getResource() unversioned.GroupVersionResource {
|
||||
plural, _ := meta.KindToResource(t.getKind())
|
||||
|
||||
return plural
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) getKind() unversioned.GroupVersionKind {
|
||||
return unversioned.GroupVersionKind{Group: t.group, Version: t.version, Kind: t.kind}
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) isThirdPartyResource(partialResource unversioned.GroupVersionResource) bool {
|
||||
actualResource := t.getResource()
|
||||
if strings.ToLower(partialResource.Resource) != strings.ToLower(actualResource.Resource) {
|
||||
return false
|
||||
}
|
||||
if len(partialResource.Group) != 0 && partialResource.Group != actualResource.Group {
|
||||
return false
|
||||
}
|
||||
if len(partialResource.Version) != 0 && partialResource.Version != actualResource.Version {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) ResourcesFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionResource, error) {
|
||||
if t.isThirdPartyResource(resource) {
|
||||
return []unversioned.GroupVersionResource{t.getResource()}, nil
|
||||
}
|
||||
return t.mapper.ResourcesFor(resource)
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) KindsFor(resource unversioned.GroupVersionResource) ([]unversioned.GroupVersionKind, error) {
|
||||
if t.isThirdPartyResource(resource) {
|
||||
return []unversioned.GroupVersionKind{t.getKind()}, nil
|
||||
}
|
||||
return t.mapper.KindsFor(resource)
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) ResourceFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionResource, error) {
|
||||
if t.isThirdPartyResource(resource) {
|
||||
return t.getResource(), nil
|
||||
}
|
||||
return t.mapper.ResourceFor(resource)
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) KindFor(resource unversioned.GroupVersionResource) (unversioned.GroupVersionKind, error) {
|
||||
if t.isThirdPartyResource(resource) {
|
||||
return t.getKind(), nil
|
||||
}
|
||||
return t.mapper.KindFor(resource)
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) RESTMapping(gk unversioned.GroupKind, versions ...string) (*meta.RESTMapping, error) {
|
||||
if len(versions) != 1 {
|
||||
return nil, fmt.Errorf("unexpected set of versions: %v", versions)
|
||||
}
|
||||
if gk.Group != t.group {
|
||||
return nil, fmt.Errorf("unknown group %q expected %s", gk.Group, t.group)
|
||||
}
|
||||
if gk.Kind != "ThirdPartyResourceData" {
|
||||
return nil, fmt.Errorf("unknown kind %s expected %s", gk.Kind, t.kind)
|
||||
}
|
||||
if versions[0] != t.version {
|
||||
return nil, fmt.Errorf("unknown version %q expected %q", versions[0], t.version)
|
||||
}
|
||||
|
||||
// TODO figure out why we're doing this rewriting
|
||||
extensionGK := unversioned.GroupKind{Group: extensions.GroupName, Kind: "ThirdPartyResourceData"}
|
||||
|
||||
mapping, err := t.mapper.RESTMapping(extensionGK, registered.GroupOrDie(extensions.GroupName).GroupVersion.Version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mapping.ObjectConvertor = &thirdPartyObjectConverter{mapping.ObjectConvertor}
|
||||
return mapping, nil
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) AliasesForResource(resource string) ([]string, bool) {
|
||||
return t.mapper.AliasesForResource(resource)
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataMapper) ResourceSingularizer(resource string) (singular string, err error) {
|
||||
return t.mapper.ResourceSingularizer(resource)
|
||||
}
|
||||
|
||||
func NewMapper(mapper meta.RESTMapper, kind, version, group string) meta.RESTMapper {
|
||||
return &thirdPartyResourceDataMapper{
|
||||
mapper: mapper,
|
||||
kind: kind,
|
||||
version: version,
|
||||
group: group,
|
||||
}
|
||||
}
|
||||
|
||||
type thirdPartyResourceDataCodecFactory struct {
|
||||
runtime.NegotiatedSerializer
|
||||
kind string
|
||||
encodeGV unversioned.GroupVersion
|
||||
decodeGV unversioned.GroupVersion
|
||||
}
|
||||
|
||||
func NewNegotiatedSerializer(s runtime.NegotiatedSerializer, kind string, encodeGV, decodeGV unversioned.GroupVersion) runtime.NegotiatedSerializer {
|
||||
return &thirdPartyResourceDataCodecFactory{
|
||||
NegotiatedSerializer: s,
|
||||
|
||||
kind: kind,
|
||||
encodeGV: encodeGV,
|
||||
decodeGV: decodeGV,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataCodecFactory) SupportedMediaTypes() []string {
|
||||
supported := sets.NewString(t.NegotiatedSerializer.SupportedMediaTypes()...)
|
||||
return supported.Intersection(sets.NewString("application/json", "application/yaml")).List()
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataCodecFactory) SupportedStreamingMediaTypes() []string {
|
||||
supported := sets.NewString(t.NegotiatedSerializer.SupportedStreamingMediaTypes()...)
|
||||
return supported.Intersection(sets.NewString("application/json", "application/json;stream=watch")).List()
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataCodecFactory) EncoderForVersion(s runtime.Encoder, gv unversioned.GroupVersion) runtime.Encoder {
|
||||
return &thirdPartyResourceDataEncoder{delegate: t.NegotiatedSerializer.EncoderForVersion(s, gv), kind: t.kind}
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataCodecFactory) DecoderToVersion(s runtime.Decoder, gv unversioned.GroupVersion) runtime.Decoder {
|
||||
return NewDecoder(t.NegotiatedSerializer.DecoderToVersion(s, gv), t.kind)
|
||||
}
|
||||
|
||||
func NewCodec(delegate runtime.Codec, kind string) runtime.Codec {
|
||||
return runtime.NewCodec(NewEncoder(delegate, kind), NewDecoder(delegate, kind))
|
||||
}
|
||||
|
||||
type thirdPartyResourceDataDecoder struct {
|
||||
delegate runtime.Decoder
|
||||
kind string
|
||||
}
|
||||
|
||||
func NewDecoder(delegate runtime.Decoder, kind string) runtime.Decoder {
|
||||
return &thirdPartyResourceDataDecoder{delegate: delegate, kind: kind}
|
||||
}
|
||||
|
||||
var _ runtime.Decoder = &thirdPartyResourceDataDecoder{}
|
||||
|
||||
func parseObject(data []byte) (map[string]interface{}, error) {
|
||||
var obj interface{}
|
||||
if err := json.Unmarshal(data, &obj); err != nil {
|
||||
fmt.Printf("Invalid JSON:\n%s\n", string(data))
|
||||
return nil, err
|
||||
}
|
||||
mapObj, ok := obj.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected object: %#v", obj)
|
||||
}
|
||||
return mapObj, nil
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataDecoder) populate(data []byte) (runtime.Object, error) {
|
||||
mapObj, err := parseObject(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return t.populateFromObject(mapObj, data)
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataDecoder) populateFromObject(mapObj map[string]interface{}, data []byte) (runtime.Object, error) {
|
||||
typeMeta := unversioned.TypeMeta{}
|
||||
if err := json.Unmarshal(data, &typeMeta); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch typeMeta.Kind {
|
||||
case t.kind:
|
||||
result := &extensions.ThirdPartyResourceData{}
|
||||
if err := t.populateResource(result, mapObj, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case t.kind + "List":
|
||||
list := &extensions.ThirdPartyResourceDataList{}
|
||||
if err := t.populateListResource(list, mapObj); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected kind: %s, expected %s", typeMeta.Kind, t.kind)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataDecoder) populateResource(objIn *extensions.ThirdPartyResourceData, mapObj map[string]interface{}, data []byte) error {
|
||||
metadata, ok := mapObj["metadata"].(map[string]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected object for metadata: %#v", mapObj["metadata"])
|
||||
}
|
||||
|
||||
metadataData, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(metadataData, &objIn.ObjectMeta); err != nil {
|
||||
return err
|
||||
}
|
||||
// Override API Version with the ThirdPartyResourceData value
|
||||
// TODO: fix this hard code
|
||||
objIn.APIVersion = v1beta1.SchemeGroupVersion.String()
|
||||
|
||||
objIn.Data = data
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataDecoder) Decode(data []byte, gvk *unversioned.GroupVersionKind, into runtime.Object) (runtime.Object, *unversioned.GroupVersionKind, error) {
|
||||
if into == nil {
|
||||
obj, err := t.populate(data)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return obj, gvk, nil
|
||||
}
|
||||
thirdParty, ok := into.(*extensions.ThirdPartyResourceData)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unexpected object: %#v", into)
|
||||
}
|
||||
|
||||
var dataObj interface{}
|
||||
if err := json.Unmarshal(data, &dataObj); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
mapObj, ok := dataObj.(map[string]interface{})
|
||||
if !ok {
|
||||
|
||||
return nil, nil, fmt.Errorf("unexpected object: %#v", dataObj)
|
||||
}
|
||||
/*if gvk.Kind != "ThirdPartyResourceData" {
|
||||
return nil, nil, fmt.Errorf("unexpected kind: %s", gvk.Kind)
|
||||
}*/
|
||||
actual := &unversioned.GroupVersionKind{}
|
||||
if kindObj, found := mapObj["kind"]; !found {
|
||||
if gvk == nil {
|
||||
return nil, nil, runtime.NewMissingKindErr(string(data))
|
||||
}
|
||||
mapObj["kind"] = gvk.Kind
|
||||
actual.Kind = gvk.Kind
|
||||
} else {
|
||||
kindStr, ok := kindObj.(string)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unexpected object for 'kind': %v", kindObj)
|
||||
}
|
||||
if kindStr != t.kind {
|
||||
return nil, nil, fmt.Errorf("kind doesn't match, expecting: %s, got %s", gvk.Kind, kindStr)
|
||||
}
|
||||
actual.Kind = t.kind
|
||||
}
|
||||
if versionObj, found := mapObj["apiVersion"]; !found {
|
||||
if gvk == nil {
|
||||
return nil, nil, runtime.NewMissingVersionErr(string(data))
|
||||
}
|
||||
mapObj["apiVersion"] = gvk.GroupVersion().String()
|
||||
actual.Group, actual.Version = gvk.Group, gvk.Version
|
||||
} else {
|
||||
versionStr, ok := versionObj.(string)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unexpected object for 'apiVersion': %v", versionObj)
|
||||
}
|
||||
if gvk != nil && versionStr != gvk.GroupVersion().String() {
|
||||
return nil, nil, fmt.Errorf("version doesn't match, expecting: %v, got %s", gvk.GroupVersion(), versionStr)
|
||||
}
|
||||
gv, err := unversioned.ParseGroupVersion(versionStr)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
actual.Group, actual.Version = gv.Group, gv.Version
|
||||
}
|
||||
|
||||
mapObj, err := parseObject(data)
|
||||
if err != nil {
|
||||
return nil, actual, err
|
||||
}
|
||||
if err := t.populateResource(thirdParty, mapObj, data); err != nil {
|
||||
return nil, actual, err
|
||||
}
|
||||
return thirdParty, actual, nil
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataDecoder) populateListResource(objIn *extensions.ThirdPartyResourceDataList, mapObj map[string]interface{}) error {
|
||||
items, ok := mapObj["items"].([]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected object for items: %#v", mapObj["items"])
|
||||
}
|
||||
objIn.Items = make([]extensions.ThirdPartyResourceData, len(items))
|
||||
for ix := range items {
|
||||
objData, err := json.Marshal(items[ix])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
objMap, err := parseObject(objData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := t.populateResource(&objIn.Items[ix], objMap, objData); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
const template = `{
|
||||
"kind": "%s",
|
||||
"items": [ %s ]
|
||||
}`
|
||||
|
||||
type thirdPartyResourceDataEncoder struct {
|
||||
delegate runtime.Encoder
|
||||
kind string
|
||||
}
|
||||
|
||||
func NewEncoder(delegate runtime.Encoder, kind string) runtime.Encoder {
|
||||
return &thirdPartyResourceDataEncoder{delegate: delegate, kind: kind}
|
||||
}
|
||||
|
||||
var _ runtime.Encoder = &thirdPartyResourceDataEncoder{}
|
||||
|
||||
func encodeToJSON(obj *extensions.ThirdPartyResourceData, stream io.Writer) error {
|
||||
var objOut interface{}
|
||||
if err := json.Unmarshal(obj.Data, &objOut); err != nil {
|
||||
return err
|
||||
}
|
||||
objMap, ok := objOut.(map[string]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type: %v", objOut)
|
||||
}
|
||||
objMap["metadata"] = obj.ObjectMeta
|
||||
encoder := json.NewEncoder(stream)
|
||||
return encoder.Encode(objMap)
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataEncoder) EncodeToStream(obj runtime.Object, stream io.Writer, overrides ...unversioned.GroupVersion) (err error) {
|
||||
switch obj := obj.(type) {
|
||||
case *extensions.ThirdPartyResourceData:
|
||||
return encodeToJSON(obj, stream)
|
||||
case *extensions.ThirdPartyResourceDataList:
|
||||
// TODO: There must be a better way to do this...
|
||||
dataStrings := make([]string, len(obj.Items))
|
||||
for ix := range obj.Items {
|
||||
buff := &bytes.Buffer{}
|
||||
err := encodeToJSON(&obj.Items[ix], buff)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dataStrings[ix] = buff.String()
|
||||
}
|
||||
fmt.Fprintf(stream, template, t.kind+"List", strings.Join(dataStrings, ","))
|
||||
return nil
|
||||
case *unversioned.Status, *unversioned.APIResourceList:
|
||||
return t.delegate.EncodeToStream(obj, stream, overrides...)
|
||||
default:
|
||||
return fmt.Errorf("unexpected object to encode: %#v", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func NewObjectCreator(group, version string, delegate runtime.ObjectCreater) runtime.ObjectCreater {
|
||||
return &thirdPartyResourceDataCreator{group, version, delegate}
|
||||
}
|
||||
|
||||
type thirdPartyResourceDataCreator struct {
|
||||
group string
|
||||
version string
|
||||
delegate runtime.ObjectCreater
|
||||
}
|
||||
|
||||
func (t *thirdPartyResourceDataCreator) New(kind unversioned.GroupVersionKind) (out runtime.Object, err error) {
|
||||
switch kind.Kind {
|
||||
case "ThirdPartyResourceData":
|
||||
if apiutil.GetGroupVersion(t.group, t.version) != kind.GroupVersion().String() {
|
||||
return nil, fmt.Errorf("unknown kind %v", kind)
|
||||
}
|
||||
return &extensions.ThirdPartyResourceData{}, nil
|
||||
case "ThirdPartyResourceDataList":
|
||||
if apiutil.GetGroupVersion(t.group, t.version) != kind.GroupVersion().String() {
|
||||
return nil, fmt.Errorf("unknown kind %v", kind)
|
||||
}
|
||||
return &extensions.ThirdPartyResourceDataList{}, nil
|
||||
// TODO: this list needs to be formalized higher in the chain
|
||||
case "ListOptions", "WatchEvent":
|
||||
if apiutil.GetGroupVersion(t.group, t.version) == kind.GroupVersion().String() {
|
||||
// Translate third party group to external group.
|
||||
gvk := registered.EnabledVersionsForGroup(api.GroupName)[0].WithKind(kind.Kind)
|
||||
return t.delegate.New(gvk)
|
||||
}
|
||||
return t.delegate.New(kind)
|
||||
default:
|
||||
return t.delegate.New(kind)
|
||||
}
|
||||
}
|
||||
|
||||
func NewThirdPartyParameterCodec(p runtime.ParameterCodec) runtime.ParameterCodec {
|
||||
return &thirdPartyParameterCodec{p}
|
||||
}
|
||||
|
||||
type thirdPartyParameterCodec struct {
|
||||
delegate runtime.ParameterCodec
|
||||
}
|
||||
|
||||
func (t *thirdPartyParameterCodec) DecodeParameters(parameters url.Values, from unversioned.GroupVersion, into runtime.Object) error {
|
||||
return t.delegate.DecodeParameters(parameters, v1.SchemeGroupVersion, into)
|
||||
}
|
||||
|
||||
func (t *thirdPartyParameterCodec) EncodeParameters(obj runtime.Object, to unversioned.GroupVersion) (url.Values, error) {
|
||||
return t.delegate.EncodeParameters(obj, v1.SchemeGroupVersion)
|
||||
}
|
||||
19
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package thirdpartyresourcedata provides Registry interface and its REST
|
||||
// implementation for storing ThirdPartyResourceData api objects.
|
||||
package thirdpartyresourcedata
|
||||
80
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/registry.go
generated
vendored
Normal file
80
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/registry.go
generated
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
// Registry is an interface implemented by things that know how to store ThirdPartyResourceData objects.
|
||||
type Registry interface {
|
||||
ListThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (*extensions.ThirdPartyResourceDataList, error)
|
||||
WatchThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
|
||||
GetThirdPartyResourceData(ctx api.Context, name string) (*extensions.ThirdPartyResourceData, error)
|
||||
CreateThirdPartyResourceData(ctx api.Context, resource *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error)
|
||||
UpdateThirdPartyResourceData(ctx api.Context, resource *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error)
|
||||
DeleteThirdPartyResourceData(ctx api.Context, name string) error
|
||||
}
|
||||
|
||||
// storage puts strong typing around storage calls
|
||||
type storage struct {
|
||||
rest.StandardStorage
|
||||
}
|
||||
|
||||
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched
|
||||
// types will panic.
|
||||
func NewRegistry(s rest.StandardStorage) Registry {
|
||||
return &storage{s}
|
||||
}
|
||||
|
||||
func (s *storage) ListThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (*extensions.ThirdPartyResourceDataList, error) {
|
||||
obj, err := s.List(ctx, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ThirdPartyResourceDataList), nil
|
||||
}
|
||||
|
||||
func (s *storage) WatchThirdPartyResourceData(ctx api.Context, options *api.ListOptions) (watch.Interface, error) {
|
||||
return s.Watch(ctx, options)
|
||||
}
|
||||
|
||||
func (s *storage) GetThirdPartyResourceData(ctx api.Context, name string) (*extensions.ThirdPartyResourceData, error) {
|
||||
obj, err := s.Get(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*extensions.ThirdPartyResourceData), nil
|
||||
}
|
||||
|
||||
func (s *storage) CreateThirdPartyResourceData(ctx api.Context, ThirdPartyResourceData *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error) {
|
||||
obj, err := s.Create(ctx, ThirdPartyResourceData)
|
||||
return obj.(*extensions.ThirdPartyResourceData), err
|
||||
}
|
||||
|
||||
func (s *storage) UpdateThirdPartyResourceData(ctx api.Context, ThirdPartyResourceData *extensions.ThirdPartyResourceData) (*extensions.ThirdPartyResourceData, error) {
|
||||
obj, _, err := s.Update(ctx, ThirdPartyResourceData)
|
||||
return obj.(*extensions.ThirdPartyResourceData), err
|
||||
}
|
||||
|
||||
func (s *storage) DeleteThirdPartyResourceData(ctx api.Context, name string) error {
|
||||
_, err := s.Delete(ctx, name, nil)
|
||||
return err
|
||||
}
|
||||
92
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/strategy.go
generated
vendored
Normal file
92
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/strategy.go
generated
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions/validation"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/util/validation/field"
|
||||
)
|
||||
|
||||
// strategy implements behavior for ThirdPartyResource objects
|
||||
type strategy struct {
|
||||
runtime.ObjectTyper
|
||||
api.NameGenerator
|
||||
}
|
||||
|
||||
// Strategy is the default logic that applies when creating and updating ThirdPartyResource
|
||||
// objects via the REST API.
|
||||
var Strategy = strategy{api.Scheme, api.SimpleNameGenerator}
|
||||
|
||||
var _ = rest.RESTCreateStrategy(Strategy)
|
||||
|
||||
var _ = rest.RESTUpdateStrategy(Strategy)
|
||||
|
||||
func (strategy) NamespaceScoped() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (strategy) PrepareForCreate(obj runtime.Object) {
|
||||
}
|
||||
|
||||
func (strategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
return validation.ValidateThirdPartyResourceData(obj.(*extensions.ThirdPartyResourceData))
|
||||
}
|
||||
|
||||
// Canonicalize normalizes the object after validation.
|
||||
func (strategy) Canonicalize(obj runtime.Object) {
|
||||
}
|
||||
|
||||
func (strategy) AllowCreateOnUpdate() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (strategy) PrepareForUpdate(obj, old runtime.Object) {
|
||||
}
|
||||
|
||||
func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateThirdPartyResourceDataUpdate(obj.(*extensions.ThirdPartyResourceData), old.(*extensions.ThirdPartyResourceData))
|
||||
}
|
||||
|
||||
func (strategy) AllowUnconditionalUpdate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Matcher returns a generic matcher for a given label and field selector.
|
||||
func Matcher(label labels.Selector, field fields.Selector) generic.Matcher {
|
||||
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
|
||||
sa, ok := obj.(*extensions.ThirdPartyResourceData)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("not a ThirdPartyResourceData")
|
||||
}
|
||||
fields := SelectableFields(sa)
|
||||
return label.Matches(labels.Set(sa.Labels)) && field.Matches(fields), nil
|
||||
})
|
||||
}
|
||||
|
||||
// SelectableFields returns a label set that can be used for filter selection
|
||||
func SelectableFields(obj *extensions.ThirdPartyResourceData) labels.Set {
|
||||
return labels.Set{}
|
||||
}
|
||||
68
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/util.go
generated
vendored
Normal file
68
vendor/k8s.io/kubernetes/pkg/registry/thirdpartyresourcedata/util.go
generated
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package thirdpartyresourcedata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
)
|
||||
|
||||
func ExtractGroupVersionKind(list *extensions.ThirdPartyResourceList) ([]unversioned.GroupVersion, []unversioned.GroupVersionKind, error) {
|
||||
gvs := []unversioned.GroupVersion{}
|
||||
gvks := []unversioned.GroupVersionKind{}
|
||||
for ix := range list.Items {
|
||||
rsrc := &list.Items[ix]
|
||||
kind, group, err := ExtractApiGroupAndKind(rsrc)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, version := range rsrc.Versions {
|
||||
gv := unversioned.GroupVersion{Group: group, Version: version.Name}
|
||||
gvs = append(gvs, gv)
|
||||
gvks = append(gvks, unversioned.GroupVersionKind{Group: group, Version: version.Name, Kind: kind})
|
||||
}
|
||||
}
|
||||
return gvs, gvks, nil
|
||||
}
|
||||
|
||||
func convertToCamelCase(input string) string {
|
||||
result := ""
|
||||
toUpper := true
|
||||
for ix := range input {
|
||||
char := input[ix]
|
||||
if toUpper {
|
||||
result = result + string([]byte{(char - 32)})
|
||||
toUpper = false
|
||||
} else if char == '-' {
|
||||
toUpper = true
|
||||
} else {
|
||||
result = result + string([]byte{char})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ExtractApiGroupAndKind(rsrc *extensions.ThirdPartyResource) (kind string, group string, err error) {
|
||||
parts := strings.Split(rsrc.Name, ".")
|
||||
if len(parts) < 3 {
|
||||
return "", "", fmt.Errorf("unexpectedly short resource name: %s, expected at least <kind>.<domain>.<tld>", rsrc.Name)
|
||||
}
|
||||
return convertToCamelCase(parts[0]), strings.Join(parts[1:], "."), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue