From 838df4eec4496868e772d5708e00f38bad478718 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Fri, 30 Mar 2018 05:49:37 -0400 Subject: Vendor in latest containers/image Some more features. docker-archive generates docker legacy compatible images Do not create $DiffID subdirectories for layers with no configs Ensure the layer IDs in legacy docker/tarfile metadata are unique docker-archive: repeated layers are symlinked in the tar file sysregistries: remove all trailing slashes Improve docker/* error messages Fix failure to make auth directory Create a new slice in Schema1.UpdateLayerInfos Drop unused storageImageDestination.{image,systemContext} Load a *storage.Image only once in storageImageSource Support gzip for docker-archive files Remove .tar extension from blob and config file names ostree, src: support copy of compressed layers ostree: re-pull layer if it misses uncompressed_digest|uncompressed_size image: fix docker schema v1 -> OCI conversion Add /etc/containers/certs.d as default certs directory Signed-off-by: Daniel J Walsh Closes: #569 Approved by: mheon --- .../apimachinery/pkg/api/equality/semantic.go | 49 -- vendor/k8s.io/apimachinery/pkg/api/meta/doc.go | 19 - vendor/k8s.io/apimachinery/pkg/api/meta/errors.go | 121 ---- .../pkg/api/meta/firsthit_restmapper.go | 97 --- vendor/k8s.io/apimachinery/pkg/api/meta/help.go | 205 ------- .../k8s.io/apimachinery/pkg/api/meta/interfaces.go | 149 ----- vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go | 121 ---- vendor/k8s.io/apimachinery/pkg/api/meta/meta.go | 653 --------------------- .../apimachinery/pkg/api/meta/multirestmapper.go | 210 ------- .../k8s.io/apimachinery/pkg/api/meta/priority.go | 222 ------- .../k8s.io/apimachinery/pkg/api/meta/restmapper.go | 548 ----------------- .../apimachinery/pkg/api/meta/unstructured.go | 47 -- .../k8s.io/apimachinery/pkg/api/validation/doc.go | 18 - .../apimachinery/pkg/api/validation/generic.go | 85 --- .../apimachinery/pkg/api/validation/objectmeta.go | 343 ----------- 15 files changed, 2887 deletions(-) delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/equality/semantic.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/doc.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/errors.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/help.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/meta.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/priority.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/validation/doc.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/validation/generic.go delete mode 100644 vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go (limited to 'vendor/k8s.io/apimachinery/pkg/api') diff --git a/vendor/k8s.io/apimachinery/pkg/api/equality/semantic.go b/vendor/k8s.io/apimachinery/pkg/api/equality/semantic.go deleted file mode 100644 index f02fa8e43..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/equality/semantic.go +++ /dev/null @@ -1,49 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 equality - -import ( - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/conversion" - "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/labels" -) - -// Semantic can do semantic deep equality checks for api objects. -// Example: apiequality.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true -var Semantic = conversion.EqualitiesOrDie( - func(a, b resource.Quantity) bool { - // Ignore formatting, only care that numeric value stayed the same. - // TODO: if we decide it's important, it should be safe to start comparing the format. - // - // Uninitialized quantities are equivalent to 0 quantities. - return a.Cmp(b) == 0 - }, - func(a, b metav1.MicroTime) bool { - return a.UTC() == b.UTC() - }, - func(a, b metav1.Time) bool { - return a.UTC() == b.UTC() - }, - func(a, b labels.Selector) bool { - return a.String() == b.String() - }, - func(a, b fields.Selector) bool { - return a.String() == b.String() - }, -) diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/doc.go b/vendor/k8s.io/apimachinery/pkg/api/meta/doc.go deleted file mode 100644 index b6d42acf8..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 meta provides functions for retrieving API metadata from objects -// belonging to the Kubernetes API -package meta // import "k8s.io/apimachinery/pkg/api/meta" diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/errors.go b/vendor/k8s.io/apimachinery/pkg/api/meta/errors.go deleted file mode 100644 index cbf5d0263..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/errors.go +++ /dev/null @@ -1,121 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 meta - -import ( - "fmt" - - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/sets" -) - -// AmbiguousResourceError is returned if the RESTMapper finds multiple matches for a resource -type AmbiguousResourceError struct { - PartialResource schema.GroupVersionResource - - MatchingResources []schema.GroupVersionResource - MatchingKinds []schema.GroupVersionKind -} - -func (e *AmbiguousResourceError) Error() string { - switch { - case len(e.MatchingKinds) > 0 && len(e.MatchingResources) > 0: - return fmt.Sprintf("%v matches multiple resources %v and kinds %v", e.PartialResource, e.MatchingResources, e.MatchingKinds) - case len(e.MatchingKinds) > 0: - return fmt.Sprintf("%v matches multiple kinds %v", e.PartialResource, e.MatchingKinds) - case len(e.MatchingResources) > 0: - return fmt.Sprintf("%v matches multiple resources %v", e.PartialResource, e.MatchingResources) - } - return fmt.Sprintf("%v matches multiple resources or kinds", e.PartialResource) -} - -// AmbiguousKindError is returned if the RESTMapper finds multiple matches for a kind -type AmbiguousKindError struct { - PartialKind schema.GroupVersionKind - - MatchingResources []schema.GroupVersionResource - MatchingKinds []schema.GroupVersionKind -} - -func (e *AmbiguousKindError) Error() string { - switch { - case len(e.MatchingKinds) > 0 && len(e.MatchingResources) > 0: - return fmt.Sprintf("%v matches multiple resources %v and kinds %v", e.PartialKind, e.MatchingResources, e.MatchingKinds) - case len(e.MatchingKinds) > 0: - return fmt.Sprintf("%v matches multiple kinds %v", e.PartialKind, e.MatchingKinds) - case len(e.MatchingResources) > 0: - return fmt.Sprintf("%v matches multiple resources %v", e.PartialKind, e.MatchingResources) - } - return fmt.Sprintf("%v matches multiple resources or kinds", e.PartialKind) -} - -func IsAmbiguousError(err error) bool { - if err == nil { - return false - } - switch err.(type) { - case *AmbiguousResourceError, *AmbiguousKindError: - return true - default: - return false - } -} - -// NoResourceMatchError is returned if the RESTMapper can't find any match for a resource -type NoResourceMatchError struct { - PartialResource schema.GroupVersionResource -} - -func (e *NoResourceMatchError) Error() string { - return fmt.Sprintf("no matches for %v", e.PartialResource) -} - -// NoKindMatchError is returned if the RESTMapper can't find any match for a kind -type NoKindMatchError struct { - // GroupKind is the API group and kind that was searched - GroupKind schema.GroupKind - // SearchedVersions is the optional list of versions the search was restricted to - SearchedVersions []string -} - -func (e *NoKindMatchError) Error() string { - searchedVersions := sets.NewString() - for _, v := range e.SearchedVersions { - searchedVersions.Insert(schema.GroupVersion{Group: e.GroupKind.Group, Version: v}.String()) - } - - switch len(searchedVersions) { - case 0: - return fmt.Sprintf("no matches for kind %q in group %q", e.GroupKind.Kind, e.GroupKind.Group) - case 1: - return fmt.Sprintf("no matches for kind %q in version %q", e.GroupKind.Kind, searchedVersions.List()[0]) - default: - return fmt.Sprintf("no matches for kind %q in versions %q", e.GroupKind.Kind, searchedVersions.List()) - } -} - -func IsNoMatchError(err error) bool { - if err == nil { - return false - } - switch err.(type) { - case *NoResourceMatchError, *NoKindMatchError: - return true - default: - return false - } -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go b/vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go deleted file mode 100644 index fd2210022..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/firsthit_restmapper.go +++ /dev/null @@ -1,97 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 meta - -import ( - "fmt" - - "k8s.io/apimachinery/pkg/runtime/schema" - utilerrors "k8s.io/apimachinery/pkg/util/errors" -) - -// FirstHitRESTMapper is a wrapper for multiple RESTMappers which returns the -// first successful result for the singular requests -type FirstHitRESTMapper struct { - MultiRESTMapper -} - -func (m FirstHitRESTMapper) String() string { - return fmt.Sprintf("FirstHitRESTMapper{\n\t%v\n}", m.MultiRESTMapper) -} - -func (m FirstHitRESTMapper) ResourceFor(resource schema.GroupVersionResource) (schema.GroupVersionResource, error) { - errors := []error{} - for _, t := range m.MultiRESTMapper { - ret, err := t.ResourceFor(resource) - if err == nil { - return ret, nil - } - errors = append(errors, err) - } - - return schema.GroupVersionResource{}, collapseAggregateErrors(errors) -} - -func (m FirstHitRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) { - errors := []error{} - for _, t := range m.MultiRESTMapper { - ret, err := t.KindFor(resource) - if err == nil { - return ret, nil - } - errors = append(errors, err) - } - - return schema.GroupVersionKind{}, collapseAggregateErrors(errors) -} - -// RESTMapping provides the REST mapping for the resource based on the -// kind and version. This implementation supports multiple REST schemas and -// return the first match. -func (m FirstHitRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) { - errors := []error{} - for _, t := range m.MultiRESTMapper { - ret, err := t.RESTMapping(gk, versions...) - if err == nil { - return ret, nil - } - errors = append(errors, err) - } - - return nil, collapseAggregateErrors(errors) -} - -// collapseAggregateErrors returns the minimal errors. it handles empty as nil, handles one item in a list -// by returning the item, and collapses all NoMatchErrors to a single one (since they should all be the same) -func collapseAggregateErrors(errors []error) error { - if len(errors) == 0 { - return nil - } - if len(errors) == 1 { - return errors[0] - } - - allNoMatchErrors := true - for _, err := range errors { - allNoMatchErrors = allNoMatchErrors && IsNoMatchError(err) - } - if allNoMatchErrors { - return errors[0] - } - - return utilerrors.NewAggregate(errors) -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/help.go b/vendor/k8s.io/apimachinery/pkg/api/meta/help.go deleted file mode 100644 index c70b3d2b6..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/help.go +++ /dev/null @@ -1,205 +0,0 @@ -/* -Copyright 2015 The Kubernetes Authors. - -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 meta - -import ( - "fmt" - "reflect" - - "k8s.io/apimachinery/pkg/conversion" - "k8s.io/apimachinery/pkg/runtime" -) - -// IsListType returns true if the provided Object has a slice called Items -func IsListType(obj runtime.Object) bool { - // if we're a runtime.Unstructured, check whether this is a list. - // TODO: refactor GetItemsPtr to use an interface that returns []runtime.Object - if unstructured, ok := obj.(runtime.Unstructured); ok { - return unstructured.IsList() - } - - _, err := GetItemsPtr(obj) - return err == nil -} - -// GetItemsPtr returns a pointer to the list object's Items member. -// If 'list' doesn't have an Items member, it's not really a list type -// and an error will be returned. -// This function will either return a pointer to a slice, or an error, but not both. -func GetItemsPtr(list runtime.Object) (interface{}, error) { - v, err := conversion.EnforcePtr(list) - if err != nil { - return nil, err - } - - items := v.FieldByName("Items") - if !items.IsValid() { - return nil, fmt.Errorf("no Items field in %#v", list) - } - switch items.Kind() { - case reflect.Interface, reflect.Ptr: - target := reflect.TypeOf(items.Interface()).Elem() - if target.Kind() != reflect.Slice { - return nil, fmt.Errorf("items: Expected slice, got %s", target.Kind()) - } - return items.Interface(), nil - case reflect.Slice: - return items.Addr().Interface(), nil - default: - return nil, fmt.Errorf("items: Expected slice, got %s", items.Kind()) - } -} - -// EachListItem invokes fn on each runtime.Object in the list. Any error immediately terminates -// the loop. -func EachListItem(obj runtime.Object, fn func(runtime.Object) error) error { - if unstructured, ok := obj.(runtime.Unstructured); ok { - return unstructured.EachListItem(fn) - } - // TODO: Change to an interface call? - itemsPtr, err := GetItemsPtr(obj) - if err != nil { - return err - } - items, err := conversion.EnforcePtr(itemsPtr) - if err != nil { - return err - } - len := items.Len() - if len == 0 { - return nil - } - takeAddr := false - if elemType := items.Type().Elem(); elemType.Kind() != reflect.Ptr && elemType.Kind() != reflect.Interface { - if !items.Index(0).CanAddr() { - return fmt.Errorf("unable to take address of items in %T for EachListItem", obj) - } - takeAddr = true - } - - for i := 0; i < len; i++ { - raw := items.Index(i) - if takeAddr { - raw = raw.Addr() - } - switch item := raw.Interface().(type) { - case *runtime.RawExtension: - if err := fn(item.Object); err != nil { - return err - } - case runtime.Object: - if err := fn(item); err != nil { - return err - } - default: - obj, ok := item.(runtime.Object) - if !ok { - return fmt.Errorf("%v: item[%v]: Expected object, got %#v(%s)", obj, i, raw.Interface(), raw.Kind()) - } - if err := fn(obj); err != nil { - return err - } - } - } - return nil -} - -// ExtractList returns obj's Items element as an array of runtime.Objects. -// Returns an error if obj is not a List type (does not have an Items member). -func ExtractList(obj runtime.Object) ([]runtime.Object, error) { - itemsPtr, err := GetItemsPtr(obj) - if err != nil { - return nil, err - } - items, err := conversion.EnforcePtr(itemsPtr) - if err != nil { - return nil, err - } - list := make([]runtime.Object, items.Len()) - for i := range list { - raw := items.Index(i) - switch item := raw.Interface().(type) { - case runtime.RawExtension: - switch { - case item.Object != nil: - list[i] = item.Object - case item.Raw != nil: - // TODO: Set ContentEncoding and ContentType correctly. - list[i] = &runtime.Unknown{Raw: item.Raw} - default: - list[i] = nil - } - case runtime.Object: - list[i] = item - default: - var found bool - if list[i], found = raw.Addr().Interface().(runtime.Object); !found { - return nil, fmt.Errorf("%v: item[%v]: Expected object, got %#v(%s)", obj, i, raw.Interface(), raw.Kind()) - } - } - } - return list, nil -} - -// objectSliceType is the type of a slice of Objects -var objectSliceType = reflect.TypeOf([]runtime.Object{}) - -// SetList sets the given list object's Items member have the elements given in -// objects. -// Returns an error if list is not a List type (does not have an Items member), -// or if any of the objects are not of the right type. -func SetList(list runtime.Object, objects []runtime.Object) error { - itemsPtr, err := GetItemsPtr(list) - if err != nil { - return err - } - items, err := conversion.EnforcePtr(itemsPtr) - if err != nil { - return err - } - if items.Type() == objectSliceType { - items.Set(reflect.ValueOf(objects)) - return nil - } - slice := reflect.MakeSlice(items.Type(), len(objects), len(objects)) - for i := range objects { - dest := slice.Index(i) - if dest.Type() == reflect.TypeOf(runtime.RawExtension{}) { - dest = dest.FieldByName("Object") - } - - // check to see if you're directly assignable - if reflect.TypeOf(objects[i]).AssignableTo(dest.Type()) { - dest.Set(reflect.ValueOf(objects[i])) - continue - } - - src, err := conversion.EnforcePtr(objects[i]) - if err != nil { - return err - } - if src.Type().AssignableTo(dest.Type()) { - dest.Set(src) - } else if src.Type().ConvertibleTo(dest.Type()) { - dest.Set(src.Convert(dest.Type())) - } else { - return fmt.Errorf("item[%d]: can't assign or convert %v into %v", i, src.Type(), dest.Type()) - } - } - items.Set(slice) - return nil -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go b/vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go deleted file mode 100644 index 5dc9d89e6..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/interfaces.go +++ /dev/null @@ -1,149 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 meta - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" -) - -// VersionInterfaces contains the interfaces one should use for dealing with types of a particular version. -type VersionInterfaces struct { - runtime.ObjectConvertor - MetadataAccessor -} - -type ListMetaAccessor interface { - GetListMeta() List -} - -// List lets you work with list metadata from any of the versioned or -// internal API objects. Attempting to set or retrieve a field on an object that does -// not support that field will be a no-op and return a default value. -type List metav1.ListInterface - -// Type exposes the type and APIVersion of versioned or internal API objects. -type Type metav1.Type - -// MetadataAccessor lets you work with object and list metadata from any of the versioned or -// internal API objects. Attempting to set or retrieve a field on an object that does -// not support that field (Name, UID, Namespace on lists) will be a no-op and return -// a default value. -// -// MetadataAccessor exposes Interface in a way that can be used with multiple objects. -type MetadataAccessor interface { - APIVersion(obj runtime.Object) (string, error) - SetAPIVersion(obj runtime.Object, version string) error - - Kind(obj runtime.Object) (string, error) - SetKind(obj runtime.Object, kind string) error - - Namespace(obj runtime.Object) (string, error) - SetNamespace(obj runtime.Object, namespace string) error - - Name(obj runtime.Object) (string, error) - SetName(obj runtime.Object, name string) error - - GenerateName(obj runtime.Object) (string, error) - SetGenerateName(obj runtime.Object, name string) error - - UID(obj runtime.Object) (types.UID, error) - SetUID(obj runtime.Object, uid types.UID) error - - SelfLink(obj runtime.Object) (string, error) - SetSelfLink(obj runtime.Object, selfLink string) error - - Labels(obj runtime.Object) (map[string]string, error) - SetLabels(obj runtime.Object, labels map[string]string) error - - Annotations(obj runtime.Object) (map[string]string, error) - SetAnnotations(obj runtime.Object, annotations map[string]string) error - - Continue(obj runtime.Object) (string, error) - SetContinue(obj runtime.Object, c string) error - - runtime.ResourceVersioner -} - -type RESTScopeName string - -const ( - RESTScopeNameNamespace RESTScopeName = "namespace" - RESTScopeNameRoot RESTScopeName = "root" -) - -// RESTScope contains the information needed to deal with REST resources that are in a resource hierarchy -type RESTScope interface { - // Name of the scope - Name() RESTScopeName - // ParamName is the optional name of the parameter that should be inserted in the resource url - // If empty, no param will be inserted - ParamName() string - // ArgumentName is the optional name that should be used for the variable holding the value. - ArgumentName() string - // ParamDescription is the optional description to use to document the parameter in api documentation - ParamDescription() string -} - -// RESTMapping contains the information needed to deal with objects of a specific -// resource and kind in a RESTful manner. -type RESTMapping struct { - // Resource is a string representing the name of this resource as a REST client would see it - Resource string - - GroupVersionKind schema.GroupVersionKind - - // Scope contains the information needed to deal with REST Resources that are in a resource hierarchy - Scope RESTScope - - runtime.ObjectConvertor - MetadataAccessor -} - -// RESTMapper allows clients to map resources to kind, and map kind and version -// to interfaces for manipulating those objects. It is primarily intended for -// consumers of Kubernetes compatible REST APIs as defined in docs/devel/api-conventions.md. -// -// The Kubernetes API provides versioned resources and object kinds which are scoped -// to API groups. In other words, kinds and resources should not be assumed to be -// unique across groups. -// -// TODO: split into sub-interfaces -type RESTMapper interface { - // KindFor takes a partial resource and returns the single match. Returns an error if there are multiple matches - KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) - - // KindsFor takes a partial resource and returns the list of potential kinds in priority order - KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error) - - // ResourceFor takes a partial resource and returns the single match. Returns an error if there are multiple matches - ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error) - - // ResourcesFor takes a partial resource and returns the list of potential resource in priority order - ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error) - - // RESTMapping identifies a preferred resource mapping for the provided group kind. - RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) - // RESTMappings returns all resource mappings for the provided group kind if no - // version search is provided. Otherwise identifies a preferred resource mapping for - // the provided version(s). - RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) - - ResourceSingularizer(resource string) (singular string, err error) -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go b/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go deleted file mode 100644 index 7f92f39a4..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/lazy.go +++ /dev/null @@ -1,121 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -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 meta - -import ( - "sync" - - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// lazyObject defers loading the mapper and typer until necessary. -type lazyObject struct { - loader func() (RESTMapper, runtime.ObjectTyper, error) - - lock sync.Mutex - loaded bool - err error - mapper RESTMapper - typer runtime.ObjectTyper -} - -// NewLazyObjectLoader handles unrecoverable errors when creating a RESTMapper / ObjectTyper by -// returning those initialization errors when the interface methods are invoked. This defers the -// initialization and any server calls until a client actually needs to perform the action. -func NewLazyObjectLoader(fn func() (RESTMapper, runtime.ObjectTyper, error)) (RESTMapper, runtime.ObjectTyper) { - obj := &lazyObject{loader: fn} - return obj, obj -} - -// init lazily loads the mapper and typer, returning an error if initialization has failed. -func (o *lazyObject) init() error { - o.lock.Lock() - defer o.lock.Unlock() - if o.loaded { - return o.err - } - o.mapper, o.typer, o.err = o.loader() - o.loaded = true - return o.err -} - -var _ RESTMapper = &lazyObject{} -var _ runtime.ObjectTyper = &lazyObject{} - -func (o *lazyObject) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) { - if err := o.init(); err != nil { - return schema.GroupVersionKind{}, err - } - return o.mapper.KindFor(resource) -} - -func (o *lazyObject) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error) { - if err := o.init(); err != nil { - return []schema.GroupVersionKind{}, err - } - return o.mapper.KindsFor(resource) -} - -func (o *lazyObject) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error) { - if err := o.init(); err != nil { - return schema.GroupVersionResource{}, err - } - return o.mapper.ResourceFor(input) -} - -func (o *lazyObject) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error) { - if err := o.init(); err != nil { - return []schema.GroupVersionResource{}, err - } - return o.mapper.ResourcesFor(input) -} - -func (o *lazyObject) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) { - if err := o.init(); err != nil { - return nil, err - } - return o.mapper.RESTMapping(gk, versions...) -} - -func (o *lazyObject) RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) { - if err := o.init(); err != nil { - return nil, err - } - return o.mapper.RESTMappings(gk, versions...) -} - -func (o *lazyObject) ResourceSingularizer(resource string) (singular string, err error) { - if err := o.init(); err != nil { - return "", err - } - return o.mapper.ResourceSingularizer(resource) -} - -func (o *lazyObject) ObjectKinds(obj runtime.Object) ([]schema.GroupVersionKind, bool, error) { - if err := o.init(); err != nil { - return nil, false, err - } - return o.typer.ObjectKinds(obj) -} - -func (o *lazyObject) Recognizes(gvk schema.GroupVersionKind) bool { - if err := o.init(); err != nil { - return false - } - return o.typer.Recognizes(gvk) -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go b/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go deleted file mode 100644 index b9670071c..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/meta.go +++ /dev/null @@ -1,653 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 meta - -import ( - "fmt" - "reflect" - - "github.com/golang/glog" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" - "k8s.io/apimachinery/pkg/conversion" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" -) - -// errNotList is returned when an object implements the Object style interfaces but not the List style -// interfaces. -var errNotList = fmt.Errorf("object does not implement the List interfaces") - -var errNotCommon = fmt.Errorf("object does not implement the common interface for accessing the SelfLink") - -// CommonAccessor returns a Common interface for the provided object or an error if the object does -// not provide List. -// TODO: return bool instead of error -func CommonAccessor(obj interface{}) (metav1.Common, error) { - switch t := obj.(type) { - case List: - return t, nil - case metav1.ListInterface: - return t, nil - case ListMetaAccessor: - if m := t.GetListMeta(); m != nil { - return m, nil - } - return nil, errNotCommon - case metav1.ListMetaAccessor: - if m := t.GetListMeta(); m != nil { - return m, nil - } - return nil, errNotCommon - case metav1.Object: - return t, nil - case metav1.ObjectMetaAccessor: - if m := t.GetObjectMeta(); m != nil { - return m, nil - } - return nil, errNotCommon - default: - return nil, errNotCommon - } -} - -// ListAccessor returns a List interface for the provided object or an error if the object does -// not provide List. -// IMPORTANT: Objects are NOT a superset of lists. Do not use this check to determine whether an -// object *is* a List. -// TODO: return bool instead of error -func ListAccessor(obj interface{}) (List, error) { - switch t := obj.(type) { - case List: - return t, nil - case metav1.ListInterface: - return t, nil - case ListMetaAccessor: - if m := t.GetListMeta(); m != nil { - return m, nil - } - return nil, errNotList - case metav1.ListMetaAccessor: - if m := t.GetListMeta(); m != nil { - return m, nil - } - return nil, errNotList - default: - return nil, errNotList - } -} - -// errNotObject is returned when an object implements the List style interfaces but not the Object style -// interfaces. -var errNotObject = fmt.Errorf("object does not implement the Object interfaces") - -// Accessor takes an arbitrary object pointer and returns meta.Interface. -// obj must be a pointer to an API type. An error is returned if the minimum -// required fields are missing. Fields that are not required return the default -// value and are a no-op if set. -// TODO: return bool instead of error -func Accessor(obj interface{}) (metav1.Object, error) { - switch t := obj.(type) { - case metav1.Object: - return t, nil - case metav1.ObjectMetaAccessor: - if m := t.GetObjectMeta(); m != nil { - return m, nil - } - return nil, errNotObject - default: - return nil, errNotObject - } -} - -// AsPartialObjectMetadata takes the metav1 interface and returns a partial object. -// TODO: consider making this solely a conversion action. -func AsPartialObjectMetadata(m metav1.Object) *metav1beta1.PartialObjectMetadata { - switch t := m.(type) { - case *metav1.ObjectMeta: - return &metav1beta1.PartialObjectMetadata{ObjectMeta: *t} - default: - return &metav1beta1.PartialObjectMetadata{ - ObjectMeta: metav1.ObjectMeta{ - Name: m.GetName(), - GenerateName: m.GetGenerateName(), - Namespace: m.GetNamespace(), - SelfLink: m.GetSelfLink(), - UID: m.GetUID(), - ResourceVersion: m.GetResourceVersion(), - Generation: m.GetGeneration(), - CreationTimestamp: m.GetCreationTimestamp(), - DeletionTimestamp: m.GetDeletionTimestamp(), - DeletionGracePeriodSeconds: m.GetDeletionGracePeriodSeconds(), - Labels: m.GetLabels(), - Annotations: m.GetAnnotations(), - OwnerReferences: m.GetOwnerReferences(), - Finalizers: m.GetFinalizers(), - ClusterName: m.GetClusterName(), - Initializers: m.GetInitializers(), - }, - } - } -} - -// TypeAccessor returns an interface that allows retrieving and modifying the APIVersion -// and Kind of an in-memory internal object. -// TODO: this interface is used to test code that does not have ObjectMeta or ListMeta -// in round tripping (objects which can use apiVersion/kind, but do not fit the Kube -// api conventions). -func TypeAccessor(obj interface{}) (Type, error) { - if typed, ok := obj.(runtime.Object); ok { - return objectAccessor{typed}, nil - } - v, err := conversion.EnforcePtr(obj) - if err != nil { - return nil, err - } - t := v.Type() - if v.Kind() != reflect.Struct { - return nil, fmt.Errorf("expected struct, but got %v: %v (%#v)", v.Kind(), t, v.Interface()) - } - - typeMeta := v.FieldByName("TypeMeta") - if !typeMeta.IsValid() { - return nil, fmt.Errorf("struct %v lacks embedded TypeMeta type", t) - } - a := &genericAccessor{} - if err := extractFromTypeMeta(typeMeta, a); err != nil { - return nil, fmt.Errorf("unable to find type fields on %#v: %v", typeMeta, err) - } - return a, nil -} - -type objectAccessor struct { - runtime.Object -} - -func (obj objectAccessor) GetKind() string { - return obj.GetObjectKind().GroupVersionKind().Kind -} - -func (obj objectAccessor) SetKind(kind string) { - gvk := obj.GetObjectKind().GroupVersionKind() - gvk.Kind = kind - obj.GetObjectKind().SetGroupVersionKind(gvk) -} - -func (obj objectAccessor) GetAPIVersion() string { - return obj.GetObjectKind().GroupVersionKind().GroupVersion().String() -} - -func (obj objectAccessor) SetAPIVersion(version string) { - gvk := obj.GetObjectKind().GroupVersionKind() - gv, err := schema.ParseGroupVersion(version) - if err != nil { - gv = schema.GroupVersion{Version: version} - } - gvk.Group, gvk.Version = gv.Group, gv.Version - obj.GetObjectKind().SetGroupVersionKind(gvk) -} - -// NewAccessor returns a MetadataAccessor that can retrieve -// or manipulate resource version on objects derived from core API -// metadata concepts. -func NewAccessor() MetadataAccessor { - return resourceAccessor{} -} - -// resourceAccessor implements ResourceVersioner and SelfLinker. -type resourceAccessor struct{} - -func (resourceAccessor) Kind(obj runtime.Object) (string, error) { - return objectAccessor{obj}.GetKind(), nil -} - -func (resourceAccessor) SetKind(obj runtime.Object, kind string) error { - objectAccessor{obj}.SetKind(kind) - return nil -} - -func (resourceAccessor) APIVersion(obj runtime.Object) (string, error) { - return objectAccessor{obj}.GetAPIVersion(), nil -} - -func (resourceAccessor) SetAPIVersion(obj runtime.Object, version string) error { - objectAccessor{obj}.SetAPIVersion(version) - return nil -} - -func (resourceAccessor) Namespace(obj runtime.Object) (string, error) { - accessor, err := Accessor(obj) - if err != nil { - return "", err - } - return accessor.GetNamespace(), nil -} - -func (resourceAccessor) SetNamespace(obj runtime.Object, namespace string) error { - accessor, err := Accessor(obj) - if err != nil { - return err - } - accessor.SetNamespace(namespace) - return nil -} - -func (resourceAccessor) Name(obj runtime.Object) (string, error) { - accessor, err := Accessor(obj) - if err != nil { - return "", err - } - return accessor.GetName(), nil -} - -func (resourceAccessor) SetName(obj runtime.Object, name string) error { - accessor, err := Accessor(obj) - if err != nil { - return err - } - accessor.SetName(name) - return nil -} - -func (resourceAccessor) GenerateName(obj runtime.Object) (string, error) { - accessor, err := Accessor(obj) - if err != nil { - return "", err - } - return accessor.GetGenerateName(), nil -} - -func (resourceAccessor) SetGenerateName(obj runtime.Object, name string) error { - accessor, err := Accessor(obj) - if err != nil { - return err - } - accessor.SetGenerateName(name) - return nil -} - -func (resourceAccessor) UID(obj runtime.Object) (types.UID, error) { - accessor, err := Accessor(obj) - if err != nil { - return "", err - } - return accessor.GetUID(), nil -} - -func (resourceAccessor) SetUID(obj runtime.Object, uid types.UID) error { - accessor, err := Accessor(obj) - if err != nil { - return err - } - accessor.SetUID(uid) - return nil -} - -func (resourceAccessor) SelfLink(obj runtime.Object) (string, error) { - accessor, err := CommonAccessor(obj) - if err != nil { - return "", err - } - return accessor.GetSelfLink(), nil -} - -func (resourceAccessor) SetSelfLink(obj runtime.Object, selfLink string) error { - accessor, err := CommonAccessor(obj) - if err != nil { - return err - } - accessor.SetSelfLink(selfLink) - return nil -} - -func (resourceAccessor) Labels(obj runtime.Object) (map[string]string, error) { - accessor, err := Accessor(obj) - if err != nil { - return nil, err - } - return accessor.GetLabels(), nil -} - -func (resourceAccessor) SetLabels(obj runtime.Object, labels map[string]string) error { - accessor, err := Accessor(obj) - if err != nil { - return err - } - accessor.SetLabels(labels) - return nil -} - -func (resourceAccessor) Annotations(obj runtime.Object) (map[string]string, error) { - accessor, err := Accessor(obj) - if err != nil { - return nil, err - } - return accessor.GetAnnotations(), nil -} - -func (resourceAccessor) SetAnnotations(obj runtime.Object, annotations map[string]string) error { - accessor, err := Accessor(obj) - if err != nil { - return err - } - accessor.SetAnnotations(annotations) - return nil -} - -func (resourceAccessor) ResourceVersion(obj runtime.Object) (string, error) { - accessor, err := CommonAccessor(obj) - if err != nil { - return "", err - } - return accessor.GetResourceVersion(), nil -} - -func (resourceAccessor) SetResourceVersion(obj runtime.Object, version string) error { - accessor, err := CommonAccessor(obj) - if err != nil { - return err - } - accessor.SetResourceVersion(version) - return nil -} - -func (resourceAccessor) Continue(obj runtime.Object) (string, error) { - accessor, err := ListAccessor(obj) - if err != nil { - return "", err - } - return accessor.GetContinue(), nil -} - -func (resourceAccessor) SetContinue(obj runtime.Object, version string) error { - accessor, err := ListAccessor(obj) - if err != nil { - return err - } - accessor.SetContinue(version) - return nil -} - -// extractFromOwnerReference extracts v to o. v is the OwnerReferences field of an object. -func extractFromOwnerReference(v reflect.Value, o *metav1.OwnerReference) error { - if err := runtime.Field(v, "APIVersion", &o.APIVersion); err != nil { - return err - } - if err := runtime.Field(v, "Kind", &o.Kind); err != nil { - return err - } - if err := runtime.Field(v, "Name", &o.Name); err != nil { - return err - } - if err := runtime.Field(v, "UID", &o.UID); err != nil { - return err - } - var controllerPtr *bool - if err := runtime.Field(v, "Controller", &controllerPtr); err != nil { - return err - } - if controllerPtr != nil { - controller := *controllerPtr - o.Controller = &controller - } - var blockOwnerDeletionPtr *bool - if err := runtime.Field(v, "BlockOwnerDeletion", &blockOwnerDeletionPtr); err != nil { - return err - } - if blockOwnerDeletionPtr != nil { - block := *blockOwnerDeletionPtr - o.BlockOwnerDeletion = &block - } - return nil -} - -// setOwnerReference sets v to o. v is the OwnerReferences field of an object. -func setOwnerReference(v reflect.Value, o *metav1.OwnerReference) error { - if err := runtime.SetField(o.APIVersion, v, "APIVersion"); err != nil { - return err - } - if err := runtime.SetField(o.Kind, v, "Kind"); err != nil { - return err - } - if err := runtime.SetField(o.Name, v, "Name"); err != nil { - return err - } - if err := runtime.SetField(o.UID, v, "UID"); err != nil { - return err - } - if o.Controller != nil { - controller := *(o.Controller) - if err := runtime.SetField(&controller, v, "Controller"); err != nil { - return err - } - } - if o.BlockOwnerDeletion != nil { - block := *(o.BlockOwnerDeletion) - if err := runtime.SetField(&block, v, "BlockOwnerDeletion"); err != nil { - return err - } - } - return nil -} - -// genericAccessor contains pointers to strings that can modify an arbitrary -// struct and implements the Accessor interface. -type genericAccessor struct { - namespace *string - name *string - generateName *string - uid *types.UID - apiVersion *string - kind *string - resourceVersion *string - selfLink *string - creationTimestamp *metav1.Time - deletionTimestamp **metav1.Time - labels *map[string]string - annotations *map[string]string - ownerReferences reflect.Value - finalizers *[]string -} - -func (a genericAccessor) GetNamespace() string { - if a.namespace == nil { - return "" - } - return *a.namespace -} - -func (a genericAccessor) SetNamespace(namespace string) { - if a.namespace == nil { - return - } - *a.namespace = namespace -} - -func (a genericAccessor) GetName() string { - if a.name == nil { - return "" - } - return *a.name -} - -func (a genericAccessor) SetName(name string) { - if a.name == nil { - return - } - *a.name = name -} - -func (a genericAccessor) GetGenerateName() string { - if a.generateName == nil { - return "" - } - return *a.generateName -} - -func (a genericAccessor) SetGenerateName(generateName string) { - if a.generateName == nil { - return - } - *a.generateName = generateName -} - -func (a genericAccessor) GetUID() types.UID { - if a.uid == nil { - return "" - } - return *a.uid -} - -func (a genericAccessor) SetUID(uid types.UID) { - if a.uid == nil { - return - } - *a.uid = uid -} - -func (a genericAccessor) GetAPIVersion() string { - return *a.apiVersion -} - -func (a genericAccessor) SetAPIVersion(version string) { - *a.apiVersion = version -} - -func (a genericAccessor) GetKind() string { - return *a.kind -} - -func (a genericAccessor) SetKind(kind string) { - *a.kind = kind -} - -func (a genericAccessor) GetResourceVersion() string { - return *a.resourceVersion -} - -func (a genericAccessor) SetResourceVersion(version string) { - *a.resourceVersion = version -} - -func (a genericAccessor) GetSelfLink() string { - return *a.selfLink -} - -func (a genericAccessor) SetSelfLink(selfLink string) { - *a.selfLink = selfLink -} - -func (a genericAccessor) GetCreationTimestamp() metav1.Time { - return *a.creationTimestamp -} - -func (a genericAccessor) SetCreationTimestamp(timestamp metav1.Time) { - *a.creationTimestamp = timestamp -} - -func (a genericAccessor) GetDeletionTimestamp() *metav1.Time { - return *a.deletionTimestamp -} - -func (a genericAccessor) SetDeletionTimestamp(timestamp *metav1.Time) { - *a.deletionTimestamp = timestamp -} - -func (a genericAccessor) GetLabels() map[string]string { - if a.labels == nil { - return nil - } - return *a.labels -} - -func (a genericAccessor) SetLabels(labels map[string]string) { - *a.labels = labels -} - -func (a genericAccessor) GetAnnotations() map[string]string { - if a.annotations == nil { - return nil - } - return *a.annotations -} - -func (a genericAccessor) SetAnnotations(annotations map[string]string) { - if a.annotations == nil { - emptyAnnotations := make(map[string]string) - a.annotations = &emptyAnnotations - } - *a.annotations = annotations -} - -func (a genericAccessor) GetFinalizers() []string { - if a.finalizers == nil { - return nil - } - return *a.finalizers -} - -func (a genericAccessor) SetFinalizers(finalizers []string) { - *a.finalizers = finalizers -} - -func (a genericAccessor) GetOwnerReferences() []metav1.OwnerReference { - var ret []metav1.OwnerReference - s := a.ownerReferences - if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice { - glog.Errorf("expect %v to be a pointer to slice", s) - return ret - } - s = s.Elem() - // Set the capacity to one element greater to avoid copy if the caller later append an element. - ret = make([]metav1.OwnerReference, s.Len(), s.Len()+1) - for i := 0; i < s.Len(); i++ { - if err := extractFromOwnerReference(s.Index(i), &ret[i]); err != nil { - glog.Errorf("extractFromOwnerReference failed: %v", err) - return ret - } - } - return ret -} - -func (a genericAccessor) SetOwnerReferences(references []metav1.OwnerReference) { - s := a.ownerReferences - if s.Kind() != reflect.Ptr || s.Elem().Kind() != reflect.Slice { - glog.Errorf("expect %v to be a pointer to slice", s) - } - s = s.Elem() - newReferences := reflect.MakeSlice(s.Type(), len(references), len(references)) - for i := 0; i < len(references); i++ { - if err := setOwnerReference(newReferences.Index(i), &references[i]); err != nil { - glog.Errorf("setOwnerReference failed: %v", err) - return - } - } - s.Set(newReferences) -} - -// extractFromTypeMeta extracts pointers to version and kind fields from an object -func extractFromTypeMeta(v reflect.Value, a *genericAccessor) error { - if err := runtime.FieldPtr(v, "APIVersion", &a.apiVersion); err != nil { - return err - } - if err := runtime.FieldPtr(v, "Kind", &a.kind); err != nil { - return err - } - return nil -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go b/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go deleted file mode 100644 index 6b01bf197..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/multirestmapper.go +++ /dev/null @@ -1,210 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 meta - -import ( - "fmt" - "strings" - - "k8s.io/apimachinery/pkg/runtime/schema" - utilerrors "k8s.io/apimachinery/pkg/util/errors" -) - -// MultiRESTMapper is a wrapper for multiple RESTMappers. -type MultiRESTMapper []RESTMapper - -func (m MultiRESTMapper) String() string { - nested := []string{} - for _, t := range m { - currString := fmt.Sprintf("%v", t) - splitStrings := strings.Split(currString, "\n") - nested = append(nested, strings.Join(splitStrings, "\n\t")) - } - - return fmt.Sprintf("MultiRESTMapper{\n\t%s\n}", strings.Join(nested, "\n\t")) -} - -// ResourceSingularizer converts a REST resource name from plural to singular (e.g., from pods to pod) -// This implementation supports multiple REST schemas and return the first match. -func (m MultiRESTMapper) ResourceSingularizer(resource string) (singular string, err error) { - for _, t := range m { - singular, err = t.ResourceSingularizer(resource) - if err == nil { - return - } - } - return -} - -func (m MultiRESTMapper) ResourcesFor(resource schema.GroupVersionResource) ([]schema.GroupVersionResource, error) { - allGVRs := []schema.GroupVersionResource{} - for _, t := range m { - gvrs, err := t.ResourcesFor(resource) - // ignore "no match" errors, but any other error percolates back up - if IsNoMatchError(err) { - continue - } - if err != nil { - return nil, err - } - - // walk the existing values to de-dup - for _, curr := range gvrs { - found := false - for _, existing := range allGVRs { - if curr == existing { - found = true - break - } - } - - if !found { - allGVRs = append(allGVRs, curr) - } - } - } - - if len(allGVRs) == 0 { - return nil, &NoResourceMatchError{PartialResource: resource} - } - - return allGVRs, nil -} - -func (m MultiRESTMapper) KindsFor(resource schema.GroupVersionResource) (gvk []schema.GroupVersionKind, err error) { - allGVKs := []schema.GroupVersionKind{} - for _, t := range m { - gvks, err := t.KindsFor(resource) - // ignore "no match" errors, but any other error percolates back up - if IsNoMatchError(err) { - continue - } - if err != nil { - return nil, err - } - - // walk the existing values to de-dup - for _, curr := range gvks { - found := false - for _, existing := range allGVKs { - if curr == existing { - found = true - break - } - } - - if !found { - allGVKs = append(allGVKs, curr) - } - } - } - - if len(allGVKs) == 0 { - return nil, &NoResourceMatchError{PartialResource: resource} - } - - return allGVKs, nil -} - -func (m MultiRESTMapper) ResourceFor(resource schema.GroupVersionResource) (schema.GroupVersionResource, error) { - resources, err := m.ResourcesFor(resource) - if err != nil { - return schema.GroupVersionResource{}, err - } - if len(resources) == 1 { - return resources[0], nil - } - - return schema.GroupVersionResource{}, &AmbiguousResourceError{PartialResource: resource, MatchingResources: resources} -} - -func (m MultiRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) { - kinds, err := m.KindsFor(resource) - if err != nil { - return schema.GroupVersionKind{}, err - } - if len(kinds) == 1 { - return kinds[0], nil - } - - return schema.GroupVersionKind{}, &AmbiguousResourceError{PartialResource: resource, MatchingKinds: kinds} -} - -// RESTMapping provides the REST mapping for the resource based on the -// kind and version. This implementation supports multiple REST schemas and -// return the first match. -func (m MultiRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) { - allMappings := []*RESTMapping{} - errors := []error{} - - for _, t := range m { - currMapping, err := t.RESTMapping(gk, versions...) - // ignore "no match" errors, but any other error percolates back up - if IsNoMatchError(err) { - continue - } - if err != nil { - errors = append(errors, err) - continue - } - - allMappings = append(allMappings, currMapping) - } - - // if we got exactly one mapping, then use it even if other requested failed - if len(allMappings) == 1 { - return allMappings[0], nil - } - if len(allMappings) > 1 { - var kinds []schema.GroupVersionKind - for _, m := range allMappings { - kinds = append(kinds, m.GroupVersionKind) - } - return nil, &AmbiguousKindError{PartialKind: gk.WithVersion(""), MatchingKinds: kinds} - } - if len(errors) > 0 { - return nil, utilerrors.NewAggregate(errors) - } - return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions} -} - -// RESTMappings returns all possible RESTMappings for the provided group kind, or an error -// if the type is not recognized. -func (m MultiRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) { - var allMappings []*RESTMapping - var errors []error - - for _, t := range m { - currMappings, err := t.RESTMappings(gk, versions...) - // ignore "no match" errors, but any other error percolates back up - if IsNoMatchError(err) { - continue - } - if err != nil { - errors = append(errors, err) - continue - } - allMappings = append(allMappings, currMappings...) - } - if len(errors) > 0 { - return nil, utilerrors.NewAggregate(errors) - } - if len(allMappings) == 0 { - return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions} - } - return allMappings, nil -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go b/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go deleted file mode 100644 index df28e64ff..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/priority.go +++ /dev/null @@ -1,222 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -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 meta - -import ( - "fmt" - - "k8s.io/apimachinery/pkg/runtime/schema" -) - -const ( - AnyGroup = "*" - AnyVersion = "*" - AnyResource = "*" - AnyKind = "*" -) - -// PriorityRESTMapper is a wrapper for automatically choosing a particular Resource or Kind -// when multiple matches are possible -type PriorityRESTMapper struct { - // Delegate is the RESTMapper to use to locate all the Kind and Resource matches - Delegate RESTMapper - - // ResourcePriority is a list of priority patterns to apply to matching resources. - // The list of all matching resources is narrowed based on the patterns until only one remains. - // A pattern with no matches is skipped. A pattern with more than one match uses its - // matches as the list to continue matching against. - ResourcePriority []schema.GroupVersionResource - - // KindPriority is a list of priority patterns to apply to matching kinds. - // The list of all matching kinds is narrowed based on the patterns until only one remains. - // A pattern with no matches is skipped. A pattern with more than one match uses its - // matches as the list to continue matching against. - KindPriority []schema.GroupVersionKind -} - -func (m PriorityRESTMapper) String() string { - return fmt.Sprintf("PriorityRESTMapper{\n\t%v\n\t%v\n\t%v\n}", m.ResourcePriority, m.KindPriority, m.Delegate) -} - -// ResourceFor finds all resources, then passes them through the ResourcePriority patterns to find a single matching hit. -func (m PriorityRESTMapper) ResourceFor(partiallySpecifiedResource schema.GroupVersionResource) (schema.GroupVersionResource, error) { - originalGVRs, err := m.Delegate.ResourcesFor(partiallySpecifiedResource) - if err != nil { - return schema.GroupVersionResource{}, err - } - if len(originalGVRs) == 1 { - return originalGVRs[0], nil - } - - remainingGVRs := append([]schema.GroupVersionResource{}, originalGVRs...) - for _, pattern := range m.ResourcePriority { - matchedGVRs := []schema.GroupVersionResource{} - for _, gvr := range remainingGVRs { - if resourceMatches(pattern, gvr) { - matchedGVRs = append(matchedGVRs, gvr) - } - } - - switch len(matchedGVRs) { - case 0: - // if you have no matches, then nothing matched this pattern just move to the next - continue - case 1: - // one match, return - return matchedGVRs[0], nil - default: - // more than one match, use the matched hits as the list moving to the next pattern. - // this way you can have a series of selection criteria - remainingGVRs = matchedGVRs - } - } - - return schema.GroupVersionResource{}, &AmbiguousResourceError{PartialResource: partiallySpecifiedResource, MatchingResources: originalGVRs} -} - -// KindFor finds all kinds, then passes them through the KindPriority patterns to find a single matching hit. -func (m PriorityRESTMapper) KindFor(partiallySpecifiedResource schema.GroupVersionResource) (schema.GroupVersionKind, error) { - originalGVKs, err := m.Delegate.KindsFor(partiallySpecifiedResource) - if err != nil { - return schema.GroupVersionKind{}, err - } - if len(originalGVKs) == 1 { - return originalGVKs[0], nil - } - - remainingGVKs := append([]schema.GroupVersionKind{}, originalGVKs...) - for _, pattern := range m.KindPriority { - matchedGVKs := []schema.GroupVersionKind{} - for _, gvr := range remainingGVKs { - if kindMatches(pattern, gvr) { - matchedGVKs = append(matchedGVKs, gvr) - } - } - - switch len(matchedGVKs) { - case 0: - // if you have no matches, then nothing matched this pattern just move to the next - continue - case 1: - // one match, return - return matchedGVKs[0], nil - default: - // more than one match, use the matched hits as the list moving to the next pattern. - // this way you can have a series of selection criteria - remainingGVKs = matchedGVKs - } - } - - return schema.GroupVersionKind{}, &AmbiguousResourceError{PartialResource: partiallySpecifiedResource, MatchingKinds: originalGVKs} -} - -func resourceMatches(pattern schema.GroupVersionResource, resource schema.GroupVersionResource) bool { - if pattern.Group != AnyGroup && pattern.Group != resource.Group { - return false - } - if pattern.Version != AnyVersion && pattern.Version != resource.Version { - return false - } - if pattern.Resource != AnyResource && pattern.Resource != resource.Resource { - return false - } - - return true -} - -func kindMatches(pattern schema.GroupVersionKind, kind schema.GroupVersionKind) bool { - if pattern.Group != AnyGroup && pattern.Group != kind.Group { - return false - } - if pattern.Version != AnyVersion && pattern.Version != kind.Version { - return false - } - if pattern.Kind != AnyKind && pattern.Kind != kind.Kind { - return false - } - - return true -} - -func (m PriorityRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (mapping *RESTMapping, err error) { - mappings, err := m.Delegate.RESTMappings(gk, versions...) - if err != nil { - return nil, err - } - - // any versions the user provides take priority - priorities := m.KindPriority - if len(versions) > 0 { - priorities = make([]schema.GroupVersionKind, 0, len(m.KindPriority)+len(versions)) - for _, version := range versions { - gv := schema.GroupVersion{ - Version: version, - Group: gk.Group, - } - priorities = append(priorities, gv.WithKind(AnyKind)) - } - priorities = append(priorities, m.KindPriority...) - } - - remaining := append([]*RESTMapping{}, mappings...) - for _, pattern := range priorities { - var matching []*RESTMapping - for _, m := range remaining { - if kindMatches(pattern, m.GroupVersionKind) { - matching = append(matching, m) - } - } - - switch len(matching) { - case 0: - // if you have no matches, then nothing matched this pattern just move to the next - continue - case 1: - // one match, return - return matching[0], nil - default: - // more than one match, use the matched hits as the list moving to the next pattern. - // this way you can have a series of selection criteria - remaining = matching - } - } - if len(remaining) == 1 { - return remaining[0], nil - } - - var kinds []schema.GroupVersionKind - for _, m := range mappings { - kinds = append(kinds, m.GroupVersionKind) - } - return nil, &AmbiguousKindError{PartialKind: gk.WithVersion(""), MatchingKinds: kinds} -} - -func (m PriorityRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) { - return m.Delegate.RESTMappings(gk, versions...) -} - -func (m PriorityRESTMapper) ResourceSingularizer(resource string) (singular string, err error) { - return m.Delegate.ResourceSingularizer(resource) -} - -func (m PriorityRESTMapper) ResourcesFor(partiallySpecifiedResource schema.GroupVersionResource) ([]schema.GroupVersionResource, error) { - return m.Delegate.ResourcesFor(partiallySpecifiedResource) -} - -func (m PriorityRESTMapper) KindsFor(partiallySpecifiedResource schema.GroupVersionResource) (gvk []schema.GroupVersionKind, err error) { - return m.Delegate.KindsFor(partiallySpecifiedResource) -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go b/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go deleted file mode 100644 index ff945acd1..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/restmapper.go +++ /dev/null @@ -1,548 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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. -*/ - -// TODO: move everything in this file to pkg/api/rest -package meta - -import ( - "fmt" - "sort" - "strings" - - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// Implements RESTScope interface -type restScope struct { - name RESTScopeName - paramName string - argumentName string - paramDescription string -} - -func (r *restScope) Name() RESTScopeName { - return r.name -} -func (r *restScope) ParamName() string { - return r.paramName -} -func (r *restScope) ArgumentName() string { - return r.argumentName -} -func (r *restScope) ParamDescription() string { - return r.paramDescription -} - -var RESTScopeNamespace = &restScope{ - name: RESTScopeNameNamespace, - paramName: "namespaces", - argumentName: "namespace", - paramDescription: "object name and auth scope, such as for teams and projects", -} - -var RESTScopeRoot = &restScope{ - name: RESTScopeNameRoot, -} - -// DefaultRESTMapper exposes mappings between the types defined in a -// runtime.Scheme. It assumes that all types defined the provided scheme -// can be mapped with the provided MetadataAccessor and Codec interfaces. -// -// The resource name of a Kind is defined as the lowercase, -// English-plural version of the Kind string. -// When converting from resource to Kind, the singular version of the -// resource name is also accepted for convenience. -// -// TODO: Only accept plural for some operations for increased control? -// (`get pod bar` vs `get pods bar`) -type DefaultRESTMapper struct { - defaultGroupVersions []schema.GroupVersion - - resourceToKind map[schema.GroupVersionResource]schema.GroupVersionKind - kindToPluralResource map[schema.GroupVersionKind]schema.GroupVersionResource - kindToScope map[schema.GroupVersionKind]RESTScope - singularToPlural map[schema.GroupVersionResource]schema.GroupVersionResource - pluralToSingular map[schema.GroupVersionResource]schema.GroupVersionResource - - interfacesFunc VersionInterfacesFunc -} - -func (m *DefaultRESTMapper) String() string { - return fmt.Sprintf("DefaultRESTMapper{kindToPluralResource=%v}", m.kindToPluralResource) -} - -var _ RESTMapper = &DefaultRESTMapper{} - -// VersionInterfacesFunc returns the appropriate typer, and metadata accessor for a -// given api version, or an error if no such api version exists. -type VersionInterfacesFunc func(version schema.GroupVersion) (*VersionInterfaces, error) - -// NewDefaultRESTMapper initializes a mapping between Kind and APIVersion -// to a resource name and back based on the objects in a runtime.Scheme -// and the Kubernetes API conventions. Takes a group name, a priority list of the versions -// to search when an object has no default version (set empty to return an error), -// and a function that retrieves the correct metadata for a given version. -func NewDefaultRESTMapper(defaultGroupVersions []schema.GroupVersion, f VersionInterfacesFunc) *DefaultRESTMapper { - resourceToKind := make(map[schema.GroupVersionResource]schema.GroupVersionKind) - kindToPluralResource := make(map[schema.GroupVersionKind]schema.GroupVersionResource) - kindToScope := make(map[schema.GroupVersionKind]RESTScope) - singularToPlural := make(map[schema.GroupVersionResource]schema.GroupVersionResource) - pluralToSingular := make(map[schema.GroupVersionResource]schema.GroupVersionResource) - // TODO: verify name mappings work correctly when versions differ - - return &DefaultRESTMapper{ - resourceToKind: resourceToKind, - kindToPluralResource: kindToPluralResource, - kindToScope: kindToScope, - defaultGroupVersions: defaultGroupVersions, - singularToPlural: singularToPlural, - pluralToSingular: pluralToSingular, - interfacesFunc: f, - } -} - -func (m *DefaultRESTMapper) Add(kind schema.GroupVersionKind, scope RESTScope) { - plural, singular := UnsafeGuessKindToResource(kind) - m.AddSpecific(kind, plural, singular, scope) -} - -func (m *DefaultRESTMapper) AddSpecific(kind schema.GroupVersionKind, plural, singular schema.GroupVersionResource, scope RESTScope) { - m.singularToPlural[singular] = plural - m.pluralToSingular[plural] = singular - - m.resourceToKind[singular] = kind - m.resourceToKind[plural] = kind - - m.kindToPluralResource[kind] = plural - m.kindToScope[kind] = scope -} - -// unpluralizedSuffixes is a list of resource suffixes that are the same plural and singular -// This is only is only necessary because some bits of code are lazy and don't actually use the RESTMapper like they should. -// TODO eliminate this so that different callers can correctly map to resources. This probably means updating all -// callers to use the RESTMapper they mean. -var unpluralizedSuffixes = []string{ - "endpoints", -} - -// UnsafeGuessKindToResource converts Kind to a resource name. -// Broken. This method only "sort of" works when used outside of this package. It assumes that Kinds and Resources match -// and they aren't guaranteed to do so. -func UnsafeGuessKindToResource(kind schema.GroupVersionKind) ( /*plural*/ schema.GroupVersionResource /*singular*/, schema.GroupVersionResource) { - kindName := kind.Kind - if len(kindName) == 0 { - return schema.GroupVersionResource{}, schema.GroupVersionResource{} - } - singularName := strings.ToLower(kindName) - singular := kind.GroupVersion().WithResource(singularName) - - for _, skip := range unpluralizedSuffixes { - if strings.HasSuffix(singularName, skip) { - return singular, singular - } - } - - switch string(singularName[len(singularName)-1]) { - case "s": - return kind.GroupVersion().WithResource(singularName + "es"), singular - case "y": - return kind.GroupVersion().WithResource(strings.TrimSuffix(singularName, "y") + "ies"), singular - } - - return kind.GroupVersion().WithResource(singularName + "s"), singular -} - -// ResourceSingularizer implements RESTMapper -// It converts a resource name from plural to singular (e.g., from pods to pod) -func (m *DefaultRESTMapper) ResourceSingularizer(resourceType string) (string, error) { - partialResource := schema.GroupVersionResource{Resource: resourceType} - resources, err := m.ResourcesFor(partialResource) - if err != nil { - return resourceType, err - } - - singular := schema.GroupVersionResource{} - for _, curr := range resources { - currSingular, ok := m.pluralToSingular[curr] - if !ok { - continue - } - if singular.Empty() { - singular = currSingular - continue - } - - if currSingular.Resource != singular.Resource { - return resourceType, fmt.Errorf("multiple possible singular resources (%v) found for %v", resources, resourceType) - } - } - - if singular.Empty() { - return resourceType, fmt.Errorf("no singular of resource %v has been defined", resourceType) - } - - return singular.Resource, nil -} - -// coerceResourceForMatching makes the resource lower case and converts internal versions to unspecified (legacy behavior) -func coerceResourceForMatching(resource schema.GroupVersionResource) schema.GroupVersionResource { - resource.Resource = strings.ToLower(resource.Resource) - if resource.Version == runtime.APIVersionInternal { - resource.Version = "" - } - - return resource -} - -func (m *DefaultRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error) { - resource := coerceResourceForMatching(input) - - hasResource := len(resource.Resource) > 0 - hasGroup := len(resource.Group) > 0 - hasVersion := len(resource.Version) > 0 - - if !hasResource { - return nil, fmt.Errorf("a resource must be present, got: %v", resource) - } - - ret := []schema.GroupVersionResource{} - switch { - case hasGroup && hasVersion: - // fully qualified. Find the exact match - for plural, singular := range m.pluralToSingular { - if singular == resource { - ret = append(ret, plural) - break - } - if plural == resource { - ret = append(ret, plural) - break - } - } - - case hasGroup: - // given a group, prefer an exact match. If you don't find one, resort to a prefix match on group - foundExactMatch := false - requestedGroupResource := resource.GroupResource() - for plural, singular := range m.pluralToSingular { - if singular.GroupResource() == requestedGroupResource { - foundExactMatch = true - ret = append(ret, plural) - } - if plural.GroupResource() == requestedGroupResource { - foundExactMatch = true - ret = append(ret, plural) - } - } - - // if you didn't find an exact match, match on group prefixing. This allows storageclass.storage to match - // storageclass.storage.k8s.io - if !foundExactMatch { - for plural, singular := range m.pluralToSingular { - if !strings.HasPrefix(plural.Group, requestedGroupResource.Group) { - continue - } - if singular.Resource == requestedGroupResource.Resource { - ret = append(ret, plural) - } - if plural.Resource == requestedGroupResource.Resource { - ret = append(ret, plural) - } - } - - } - - case hasVersion: - for plural, singular := range m.pluralToSingular { - if singular.Version == resource.Version && singular.Resource == resource.Resource { - ret = append(ret, plural) - } - if plural.Version == resource.Version && plural.Resource == resource.Resource { - ret = append(ret, plural) - } - } - - default: - for plural, singular := range m.pluralToSingular { - if singular.Resource == resource.Resource { - ret = append(ret, plural) - } - if plural.Resource == resource.Resource { - ret = append(ret, plural) - } - } - } - - if len(ret) == 0 { - return nil, &NoResourceMatchError{PartialResource: resource} - } - - sort.Sort(resourceByPreferredGroupVersion{ret, m.defaultGroupVersions}) - return ret, nil -} - -func (m *DefaultRESTMapper) ResourceFor(resource schema.GroupVersionResource) (schema.GroupVersionResource, error) { - resources, err := m.ResourcesFor(resource) - if err != nil { - return schema.GroupVersionResource{}, err - } - if len(resources) == 1 { - return resources[0], nil - } - - return schema.GroupVersionResource{}, &AmbiguousResourceError{PartialResource: resource, MatchingResources: resources} -} - -func (m *DefaultRESTMapper) KindsFor(input schema.GroupVersionResource) ([]schema.GroupVersionKind, error) { - resource := coerceResourceForMatching(input) - - hasResource := len(resource.Resource) > 0 - hasGroup := len(resource.Group) > 0 - hasVersion := len(resource.Version) > 0 - - if !hasResource { - return nil, fmt.Errorf("a resource must be present, got: %v", resource) - } - - ret := []schema.GroupVersionKind{} - switch { - // fully qualified. Find the exact match - case hasGroup && hasVersion: - kind, exists := m.resourceToKind[resource] - if exists { - ret = append(ret, kind) - } - - case hasGroup: - foundExactMatch := false - requestedGroupResource := resource.GroupResource() - for currResource, currKind := range m.resourceToKind { - if currResource.GroupResource() == requestedGroupResource { - foundExactMatch = true - ret = append(ret, currKind) - } - } - - // if you didn't find an exact match, match on group prefixing. This allows storageclass.storage to match - // storageclass.storage.k8s.io - if !foundExactMatch { - for currResource, currKind := range m.resourceToKind { - if !strings.HasPrefix(currResource.Group, requestedGroupResource.Group) { - continue - } - if currResource.Resource == requestedGroupResource.Resource { - ret = append(ret, currKind) - } - } - - } - - case hasVersion: - for currResource, currKind := range m.resourceToKind { - if currResource.Version == resource.Version && currResource.Resource == resource.Resource { - ret = append(ret, currKind) - } - } - - default: - for currResource, currKind := range m.resourceToKind { - if currResource.Resource == resource.Resource { - ret = append(ret, currKind) - } - } - } - - if len(ret) == 0 { - return nil, &NoResourceMatchError{PartialResource: input} - } - - sort.Sort(kindByPreferredGroupVersion{ret, m.defaultGroupVersions}) - return ret, nil -} - -func (m *DefaultRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error) { - kinds, err := m.KindsFor(resource) - if err != nil { - return schema.GroupVersionKind{}, err - } - if len(kinds) == 1 { - return kinds[0], nil - } - - return schema.GroupVersionKind{}, &AmbiguousResourceError{PartialResource: resource, MatchingKinds: kinds} -} - -type kindByPreferredGroupVersion struct { - list []schema.GroupVersionKind - sortOrder []schema.GroupVersion -} - -func (o kindByPreferredGroupVersion) Len() int { return len(o.list) } -func (o kindByPreferredGroupVersion) Swap(i, j int) { o.list[i], o.list[j] = o.list[j], o.list[i] } -func (o kindByPreferredGroupVersion) Less(i, j int) bool { - lhs := o.list[i] - rhs := o.list[j] - if lhs == rhs { - return false - } - - if lhs.GroupVersion() == rhs.GroupVersion() { - return lhs.Kind < rhs.Kind - } - - // otherwise, the difference is in the GroupVersion, so we need to sort with respect to the preferred order - lhsIndex := -1 - rhsIndex := -1 - - for i := range o.sortOrder { - if o.sortOrder[i] == lhs.GroupVersion() { - lhsIndex = i - } - if o.sortOrder[i] == rhs.GroupVersion() { - rhsIndex = i - } - } - - if rhsIndex == -1 { - return true - } - - return lhsIndex < rhsIndex -} - -type resourceByPreferredGroupVersion struct { - list []schema.GroupVersionResource - sortOrder []schema.GroupVersion -} - -func (o resourceByPreferredGroupVersion) Len() int { return len(o.list) } -func (o resourceByPreferredGroupVersion) Swap(i, j int) { o.list[i], o.list[j] = o.list[j], o.list[i] } -func (o resourceByPreferredGroupVersion) Less(i, j int) bool { - lhs := o.list[i] - rhs := o.list[j] - if lhs == rhs { - return false - } - - if lhs.GroupVersion() == rhs.GroupVersion() { - return lhs.Resource < rhs.Resource - } - - // otherwise, the difference is in the GroupVersion, so we need to sort with respect to the preferred order - lhsIndex := -1 - rhsIndex := -1 - - for i := range o.sortOrder { - if o.sortOrder[i] == lhs.GroupVersion() { - lhsIndex = i - } - if o.sortOrder[i] == rhs.GroupVersion() { - rhsIndex = i - } - } - - if rhsIndex == -1 { - return true - } - - return lhsIndex < rhsIndex -} - -// RESTMapping returns a struct representing the resource path and conversion interfaces a -// RESTClient should use to operate on the provided group/kind in order of versions. If a version search -// order is not provided, the search order provided to DefaultRESTMapper will be used to resolve which -// version should be used to access the named group/kind. -func (m *DefaultRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*RESTMapping, error) { - mappings, err := m.RESTMappings(gk, versions...) - if err != nil { - return nil, err - } - if len(mappings) == 0 { - return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions} - } - // since we rely on RESTMappings method - // take the first match and return to the caller - // as this was the existing behavior. - return mappings[0], nil -} - -// RESTMappings returns the RESTMappings for the provided group kind. If a version search order -// is not provided, the search order provided to DefaultRESTMapper will be used. -func (m *DefaultRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*RESTMapping, error) { - mappings := make([]*RESTMapping, 0) - potentialGVK := make([]schema.GroupVersionKind, 0) - hadVersion := false - - // Pick an appropriate version - for _, version := range versions { - if len(version) == 0 || version == runtime.APIVersionInternal { - continue - } - currGVK := gk.WithVersion(version) - hadVersion = true - if _, ok := m.kindToPluralResource[currGVK]; ok { - potentialGVK = append(potentialGVK, currGVK) - break - } - } - // Use the default preferred versions - if !hadVersion && len(potentialGVK) == 0 { - for _, gv := range m.defaultGroupVersions { - if gv.Group != gk.Group { - continue - } - potentialGVK = append(potentialGVK, gk.WithVersion(gv.Version)) - } - } - - if len(potentialGVK) == 0 { - return nil, &NoKindMatchError{GroupKind: gk, SearchedVersions: versions} - } - - for _, gvk := range potentialGVK { - //Ensure we have a REST mapping - res, ok := m.kindToPluralResource[gvk] - if !ok { - continue - } - - // Ensure we have a REST scope - scope, ok := m.kindToScope[gvk] - if !ok { - return nil, fmt.Errorf("the provided version %q and kind %q cannot be mapped to a supported scope", gvk.GroupVersion(), gvk.Kind) - } - - interfaces, err := m.interfacesFunc(gvk.GroupVersion()) - if err != nil { - return nil, fmt.Errorf("the provided version %q has no relevant versions: %v", gvk.GroupVersion().String(), err) - } - - mappings = append(mappings, &RESTMapping{ - Resource: res.Resource, - GroupVersionKind: gvk, - Scope: scope, - - ObjectConvertor: interfaces.ObjectConvertor, - MetadataAccessor: interfaces.MetadataAccessor, - }) - } - - if len(mappings) == 0 { - return nil, &NoResourceMatchError{PartialResource: schema.GroupVersionResource{Group: gk.Group, Resource: gk.Kind}} - } - return mappings, nil -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go b/vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go deleted file mode 100644 index 4e13efea3..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/meta/unstructured.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -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 meta - -import ( - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// InterfacesForUnstructuredConversion returns VersionInterfaces suitable for -// dealing with unstructured.Unstructured objects and supports conversion -// from typed objects (provided by parent) to untyped objects. -func InterfacesForUnstructuredConversion(parent VersionInterfacesFunc) VersionInterfacesFunc { - return func(version schema.GroupVersion) (*VersionInterfaces, error) { - if i, err := parent(version); err == nil { - return &VersionInterfaces{ - ObjectConvertor: i.ObjectConvertor, - MetadataAccessor: NewAccessor(), - }, nil - } - return InterfacesForUnstructured(version) - } -} - -// InterfacesForUnstructured returns VersionInterfaces suitable for -// dealing with unstructured.Unstructured objects. It will return errors for -// other conversions. -func InterfacesForUnstructured(schema.GroupVersion) (*VersionInterfaces, error) { - return &VersionInterfaces{ - ObjectConvertor: &unstructured.UnstructuredObjectConverter{}, - MetadataAccessor: NewAccessor(), - }, nil -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/validation/doc.go b/vendor/k8s.io/apimachinery/pkg/api/validation/doc.go deleted file mode 100644 index 9f20152e4..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/validation/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -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 validation contains generic api type validation functions. -package validation // import "k8s.io/apimachinery/pkg/api/validation" diff --git a/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go b/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go deleted file mode 100644 index 348cdc087..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 validation - -import ( - "strings" - - "k8s.io/apimachinery/pkg/util/validation" - "k8s.io/apimachinery/pkg/util/validation/field" -) - -const IsNegativeErrorMsg string = `must be greater than or equal to 0` - -// ValidateNameFunc validates that the provided name is valid for a given resource type. -// Not all resources have the same validation rules for names. Prefix is true -// if the name will have a value appended to it. If the name is not valid, -// this returns a list of descriptions of individual characteristics of the -// value that were not valid. Otherwise this returns an empty list or nil. -type ValidateNameFunc func(name string, prefix bool) []string - -// NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain. -func NameIsDNSSubdomain(name string, prefix bool) []string { - if prefix { - name = maskTrailingDash(name) - } - return validation.IsDNS1123Subdomain(name) -} - -// NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label. -func NameIsDNSLabel(name string, prefix bool) []string { - if prefix { - name = maskTrailingDash(name) - } - return validation.IsDNS1123Label(name) -} - -// NameIsDNS1035Label is a ValidateNameFunc for names that must be a DNS 952 label. -func NameIsDNS1035Label(name string, prefix bool) []string { - if prefix { - name = maskTrailingDash(name) - } - return validation.IsDNS1035Label(name) -} - -// ValidateNamespaceName can be used to check whether the given namespace name is valid. -// Prefix indicates this name will be used as part of generation, in which case -// trailing dashes are allowed. -var ValidateNamespaceName = NameIsDNSLabel - -// ValidateServiceAccountName can be used to check whether the given service account name is valid. -// Prefix indicates this name will be used as part of generation, in which case -// trailing dashes are allowed. -var ValidateServiceAccountName = NameIsDNSSubdomain - -// maskTrailingDash replaces the final character of a string with a subdomain safe -// value if is a dash. -func maskTrailingDash(name string) string { - if strings.HasSuffix(name, "-") { - return name[:len(name)-2] + "a" - } - return name -} - -// Validates that given value is not negative. -func ValidateNonnegativeField(value int64, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - if value < 0 { - allErrs = append(allErrs, field.Invalid(fldPath, value, IsNegativeErrorMsg)) - } - return allErrs -} diff --git a/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go b/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go deleted file mode 100644 index 3c32a937a..000000000 --- a/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go +++ /dev/null @@ -1,343 +0,0 @@ -/* -Copyright 2014 The Kubernetes Authors. - -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 validation - -import ( - "fmt" - "strings" - - apiequality "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/apimachinery/pkg/util/validation" - "k8s.io/apimachinery/pkg/util/validation/field" -) - -// TODO: delete this global variable when we enable the validation of common -// fields by default. -var RepairMalformedUpdates bool = true - -const FieldImmutableErrorMsg string = `field is immutable` - -const totalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB - -// BannedOwners is a black list of object that are not allowed to be owners. -var BannedOwners = map[schema.GroupVersionKind]struct{}{ - {Group: "", Version: "v1", Kind: "Event"}: {}, -} - -// ValidateClusterName can be used to check whether the given cluster name is valid. -var ValidateClusterName = NameIsDNS1035Label - -// ValidateAnnotations validates that a set of annotations are correctly defined. -func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - var totalSize int64 - for k, v := range annotations { - for _, msg := range validation.IsQualifiedName(strings.ToLower(k)) { - allErrs = append(allErrs, field.Invalid(fldPath, k, msg)) - } - totalSize += (int64)(len(k)) + (int64)(len(v)) - } - if totalSize > (int64)(totalAnnotationSizeLimitB) { - allErrs = append(allErrs, field.TooLong(fldPath, "", totalAnnotationSizeLimitB)) - } - return allErrs -} - -func validateOwnerReference(ownerReference metav1.OwnerReference, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - gvk := schema.FromAPIVersionAndKind(ownerReference.APIVersion, ownerReference.Kind) - // gvk.Group is empty for the legacy group. - if len(gvk.Version) == 0 { - allErrs = append(allErrs, field.Invalid(fldPath.Child("apiVersion"), ownerReference.APIVersion, "version must not be empty")) - } - if len(gvk.Kind) == 0 { - allErrs = append(allErrs, field.Invalid(fldPath.Child("kind"), ownerReference.Kind, "kind must not be empty")) - } - if len(ownerReference.Name) == 0 { - allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), ownerReference.Name, "name must not be empty")) - } - if len(ownerReference.UID) == 0 { - allErrs = append(allErrs, field.Invalid(fldPath.Child("uid"), ownerReference.UID, "uid must not be empty")) - } - if _, ok := BannedOwners[gvk]; ok { - allErrs = append(allErrs, field.Invalid(fldPath, ownerReference, fmt.Sprintf("%s is disallowed from being an owner", gvk))) - } - return allErrs -} - -func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - controllerName := "" - for _, ref := range ownerReferences { - allErrs = append(allErrs, validateOwnerReference(ref, fldPath)...) - if ref.Controller != nil && *ref.Controller { - if controllerName != "" { - allErrs = append(allErrs, field.Invalid(fldPath, ownerReferences, - fmt.Sprintf("Only one reference can have Controller set to true. Found \"true\" in references for %v and %v", controllerName, ref.Name))) - } else { - controllerName = ref.Name - } - } - } - return allErrs -} - -// Validate finalizer names -func ValidateFinalizerName(stringValue string, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - for _, msg := range validation.IsQualifiedName(stringValue) { - allErrs = append(allErrs, field.Invalid(fldPath, stringValue, msg)) - } - - return allErrs -} - -func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - extra := sets.NewString(newFinalizers...).Difference(sets.NewString(oldFinalizers...)) - if len(extra) != 0 { - allErrs = append(allErrs, field.Forbidden(fldPath, fmt.Sprintf("no new finalizers can be added if the object is being deleted, found new finalizers %#v", extra.List()))) - } - return allErrs -} - -func ValidateImmutableField(newVal, oldVal interface{}, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - if !apiequality.Semantic.DeepEqual(oldVal, newVal) { - allErrs = append(allErrs, field.Invalid(fldPath, newVal, FieldImmutableErrorMsg)) - } - return allErrs -} - -// ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already -// been performed. -// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before. -func ValidateObjectMeta(objMeta *metav1.ObjectMeta, requiresNamespace bool, nameFn ValidateNameFunc, fldPath *field.Path) field.ErrorList { - metadata, err := meta.Accessor(objMeta) - if err != nil { - allErrs := field.ErrorList{} - allErrs = append(allErrs, field.Invalid(fldPath, objMeta, err.Error())) - return allErrs - } - return ValidateObjectMetaAccessor(metadata, requiresNamespace, nameFn, fldPath) -} - -// ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already -// been performed. -// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before. -func ValidateObjectMetaAccessor(meta metav1.Object, requiresNamespace bool, nameFn ValidateNameFunc, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - - if len(meta.GetGenerateName()) != 0 { - for _, msg := range nameFn(meta.GetGenerateName(), true) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("generateName"), meta.GetGenerateName(), msg)) - } - } - // If the generated name validates, but the calculated value does not, it's a problem with generation, and we - // report it here. This may confuse users, but indicates a programming bug and still must be validated. - // If there are multiple fields out of which one is required then add an or as a separator - if len(meta.GetName()) == 0 { - allErrs = append(allErrs, field.Required(fldPath.Child("name"), "name or generateName is required")) - } else { - for _, msg := range nameFn(meta.GetName(), false) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), meta.GetName(), msg)) - } - } - if requiresNamespace { - if len(meta.GetNamespace()) == 0 { - allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), "")) - } else { - for _, msg := range ValidateNamespaceName(meta.GetNamespace(), false) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("namespace"), meta.GetNamespace(), msg)) - } - } - } else { - if len(meta.GetNamespace()) != 0 { - allErrs = append(allErrs, field.Forbidden(fldPath.Child("namespace"), "not allowed on this type")) - } - } - if len(meta.GetClusterName()) != 0 { - for _, msg := range ValidateClusterName(meta.GetClusterName(), false) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("clusterName"), meta.GetClusterName(), msg)) - } - } - allErrs = append(allErrs, ValidateNonnegativeField(meta.GetGeneration(), fldPath.Child("generation"))...) - allErrs = append(allErrs, v1validation.ValidateLabels(meta.GetLabels(), fldPath.Child("labels"))...) - allErrs = append(allErrs, ValidateAnnotations(meta.GetAnnotations(), fldPath.Child("annotations"))...) - allErrs = append(allErrs, ValidateOwnerReferences(meta.GetOwnerReferences(), fldPath.Child("ownerReferences"))...) - allErrs = append(allErrs, ValidateInitializers(meta.GetInitializers(), fldPath.Child("initializers"))...) - allErrs = append(allErrs, ValidateFinalizers(meta.GetFinalizers(), fldPath.Child("finalizers"))...) - return allErrs -} - -func ValidateInitializers(initializers *metav1.Initializers, fldPath *field.Path) field.ErrorList { - var allErrs field.ErrorList - if initializers == nil { - return allErrs - } - for i, initializer := range initializers.Pending { - allErrs = append(allErrs, validation.IsFullyQualifiedName(fldPath.Child("pending").Index(i).Child("name"), initializer.Name)...) - } - allErrs = append(allErrs, validateInitializersResult(initializers.Result, fldPath.Child("result"))...) - return allErrs -} - -func validateInitializersResult(result *metav1.Status, fldPath *field.Path) field.ErrorList { - var allErrs field.ErrorList - if result == nil { - return allErrs - } - switch result.Status { - case metav1.StatusFailure: - default: - allErrs = append(allErrs, field.Invalid(fldPath.Child("status"), result.Status, "must be 'Failure'")) - } - return allErrs -} - -// ValidateFinalizers tests if the finalizers name are valid, and if there are conflicting finalizers. -func ValidateFinalizers(finalizers []string, fldPath *field.Path) field.ErrorList { - allErrs := field.ErrorList{} - hasFinalizerOrphanDependents := false - hasFinalizerDeleteDependents := false - for _, finalizer := range finalizers { - allErrs = append(allErrs, ValidateFinalizerName(finalizer, fldPath)...) - if finalizer == metav1.FinalizerOrphanDependents { - hasFinalizerOrphanDependents = true - } - if finalizer == metav1.FinalizerDeleteDependents { - hasFinalizerDeleteDependents = true - } - } - if hasFinalizerDeleteDependents && hasFinalizerOrphanDependents { - allErrs = append(allErrs, field.Invalid(fldPath, finalizers, fmt.Sprintf("finalizer %s and %s cannot be both set", metav1.FinalizerOrphanDependents, metav1.FinalizerDeleteDependents))) - } - return allErrs -} - -// ValidateObjectMetaUpdate validates an object's metadata when updated -func ValidateObjectMetaUpdate(newMeta, oldMeta *metav1.ObjectMeta, fldPath *field.Path) field.ErrorList { - newMetadata, err := meta.Accessor(newMeta) - if err != nil { - allErrs := field.ErrorList{} - allErrs = append(allErrs, field.Invalid(fldPath, newMeta, err.Error())) - return allErrs - } - oldMetadata, err := meta.Accessor(oldMeta) - if err != nil { - allErrs := field.ErrorList{} - allErrs = append(allErrs, field.Invalid(fldPath, oldMeta, err.Error())) - return allErrs - } - return ValidateObjectMetaAccessorUpdate(newMetadata, oldMetadata, fldPath) -} - -func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *field.Path) field.ErrorList { - var allErrs field.ErrorList - - if !RepairMalformedUpdates && newMeta.GetUID() != oldMeta.GetUID() { - allErrs = append(allErrs, field.Invalid(fldPath.Child("uid"), newMeta.GetUID(), "field is immutable")) - } - // in the event it is left empty, set it, to allow clients more flexibility - // TODO: remove the following code that repairs the update request when we retire the clients that modify the immutable fields. - // Please do not copy this pattern elsewhere; validation functions should not be modifying the objects they are passed! - if RepairMalformedUpdates { - if len(newMeta.GetUID()) == 0 { - newMeta.SetUID(oldMeta.GetUID()) - } - // ignore changes to timestamp - if oldCreationTime := oldMeta.GetCreationTimestamp(); oldCreationTime.IsZero() { - oldMeta.SetCreationTimestamp(newMeta.GetCreationTimestamp()) - } else { - newMeta.SetCreationTimestamp(oldMeta.GetCreationTimestamp()) - } - // an object can never remove a deletion timestamp or clear/change grace period seconds - if !oldMeta.GetDeletionTimestamp().IsZero() { - newMeta.SetDeletionTimestamp(oldMeta.GetDeletionTimestamp()) - } - if oldMeta.GetDeletionGracePeriodSeconds() != nil && newMeta.GetDeletionGracePeriodSeconds() == nil { - newMeta.SetDeletionGracePeriodSeconds(oldMeta.GetDeletionGracePeriodSeconds()) - } - } - - // TODO: needs to check if newMeta==nil && oldMeta !=nil after the repair logic is removed. - if newMeta.GetDeletionGracePeriodSeconds() != nil && (oldMeta.GetDeletionGracePeriodSeconds() == nil || *newMeta.GetDeletionGracePeriodSeconds() != *oldMeta.GetDeletionGracePeriodSeconds()) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("deletionGracePeriodSeconds"), newMeta.GetDeletionGracePeriodSeconds(), "field is immutable; may only be changed via deletion")) - } - if newMeta.GetDeletionTimestamp() != nil && (oldMeta.GetDeletionTimestamp() == nil || !newMeta.GetDeletionTimestamp().Equal(oldMeta.GetDeletionTimestamp())) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("deletionTimestamp"), newMeta.GetDeletionTimestamp(), "field is immutable; may only be changed via deletion")) - } - - // Finalizers cannot be added if the object is already being deleted. - if oldMeta.GetDeletionTimestamp() != nil { - allErrs = append(allErrs, ValidateNoNewFinalizers(newMeta.GetFinalizers(), oldMeta.GetFinalizers(), fldPath.Child("finalizers"))...) - } - - // Reject updates that don't specify a resource version - if len(newMeta.GetResourceVersion()) == 0 { - allErrs = append(allErrs, field.Invalid(fldPath.Child("resourceVersion"), newMeta.GetResourceVersion(), "must be specified for an update")) - } - - // Generation shouldn't be decremented - if newMeta.GetGeneration() < oldMeta.GetGeneration() { - allErrs = append(allErrs, field.Invalid(fldPath.Child("generation"), newMeta.GetGeneration(), "must not be decremented")) - } - - allErrs = append(allErrs, ValidateInitializersUpdate(newMeta.GetInitializers(), oldMeta.GetInitializers(), fldPath.Child("initializers"))...) - - allErrs = append(allErrs, ValidateImmutableField(newMeta.GetName(), oldMeta.GetName(), fldPath.Child("name"))...) - allErrs = append(allErrs, ValidateImmutableField(newMeta.GetNamespace(), oldMeta.GetNamespace(), fldPath.Child("namespace"))...) - allErrs = append(allErrs, ValidateImmutableField(newMeta.GetUID(), oldMeta.GetUID(), fldPath.Child("uid"))...) - allErrs = append(allErrs, ValidateImmutableField(newMeta.GetCreationTimestamp(), oldMeta.GetCreationTimestamp(), fldPath.Child("creationTimestamp"))...) - allErrs = append(allErrs, ValidateImmutableField(newMeta.GetClusterName(), oldMeta.GetClusterName(), fldPath.Child("clusterName"))...) - - allErrs = append(allErrs, v1validation.ValidateLabels(newMeta.GetLabels(), fldPath.Child("labels"))...) - allErrs = append(allErrs, ValidateAnnotations(newMeta.GetAnnotations(), fldPath.Child("annotations"))...) - allErrs = append(allErrs, ValidateOwnerReferences(newMeta.GetOwnerReferences(), fldPath.Child("ownerReferences"))...) - - return allErrs -} - -// ValidateInitializersUpdate checks the update of the metadata initializers field -func ValidateInitializersUpdate(newInit, oldInit *metav1.Initializers, fldPath *field.Path) field.ErrorList { - var allErrs field.ErrorList - switch { - case oldInit == nil && newInit != nil: - // Initializers may not be set on new objects - allErrs = append(allErrs, field.Invalid(fldPath, nil, "field is immutable once initialization has completed")) - case oldInit != nil && newInit == nil: - // this is a valid transition and means initialization was successful - case oldInit != nil && newInit != nil: - // validate changes to initializers - switch { - case oldInit.Result == nil && newInit.Result != nil: - // setting a result is allowed - allErrs = append(allErrs, validateInitializersResult(newInit.Result, fldPath.Child("result"))...) - case oldInit.Result != nil: - // setting Result implies permanent failure, and all future updates will be prevented - allErrs = append(allErrs, ValidateImmutableField(newInit.Result, oldInit.Result, fldPath.Child("result"))...) - default: - // leaving the result nil is allowed - } - } - return allErrs -} -- cgit v1.2.3-54-g00ecf