mirror of
https://github.com/kubernetes/sample-controller.git
synced 2026-04-12 00:00:26 +08:00
Merge pull request #54463 from saad-ali/volumeAttachmentAPI
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Introduce new `VolumeAttachment` API Object **What this PR does / why we need it**: Introduce a new `VolumeAttachment` API Object. This object will be used by the CSI volume plugin to enable external attachers (see design [here](https://github.com/kubernetes/community/pull/1258). In the future, existing volume plugins can be refactored to use this object as well. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: Part of issue https://github.com/kubernetes/features/issues/178 **Special notes for your reviewer**: None **Release note**: ```release-note NONE ``` Kubernetes-commit: ebe8ea73fd1a961779242dfbb629befa153e96fc
This commit is contained in:
-1
@@ -42,7 +42,6 @@ go_library(
|
||||
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
"//vendor/gopkg.in/inf.v0:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
||||
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
-17
@@ -20,23 +20,6 @@ limitations under the License.
|
||||
|
||||
package resource
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Quantity).DeepCopyInto(out.(*Quantity))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Quantity{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Quantity) DeepCopyInto(out *Quantity) {
|
||||
*out = in.DeepCopy()
|
||||
|
||||
Generated
Vendored
-18
@@ -21,27 +21,9 @@ limitations under the License.
|
||||
package internalversion
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*List).DeepCopyInto(out.(*List))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&List{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*ListOptions).DeepCopyInto(out.(*ListOptions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&ListOptions{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *List) DeepCopyInto(out *List) {
|
||||
*out = *in
|
||||
|
||||
-2
@@ -70,7 +70,6 @@ func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion)
|
||||
)
|
||||
|
||||
// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
|
||||
scheme.AddGeneratedDeepCopyFuncs(GetGeneratedDeepCopyFuncs()...)
|
||||
AddConversionFuncs(scheme)
|
||||
RegisterDefaults(scheme)
|
||||
}
|
||||
@@ -90,6 +89,5 @@ func init() {
|
||||
)
|
||||
|
||||
// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
|
||||
scheme.AddGeneratedDeepCopyFuncs(GetGeneratedDeepCopyFuncs()...)
|
||||
RegisterDefaults(scheme)
|
||||
}
|
||||
|
||||
-1
@@ -32,7 +32,6 @@ go_library(
|
||||
importpath = "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
|
||||
deps = [
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/conversion/unstructured:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
|
||||
Generated
Vendored
-18
@@ -21,27 +21,9 @@ limitations under the License.
|
||||
package unstructured
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Unstructured).DeepCopyInto(out.(*Unstructured))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Unstructured{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*UnstructuredList).DeepCopyInto(out.(*UnstructuredList))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&UnstructuredList{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Unstructured) DeepCopyInto(out *Unstructured) {
|
||||
clone := in.DeepCopy()
|
||||
|
||||
-154
@@ -21,164 +21,10 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*APIGroup).DeepCopyInto(out.(*APIGroup))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&APIGroup{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*APIGroupList).DeepCopyInto(out.(*APIGroupList))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&APIGroupList{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*APIResource).DeepCopyInto(out.(*APIResource))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&APIResource{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*APIResourceList).DeepCopyInto(out.(*APIResourceList))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&APIResourceList{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*APIVersions).DeepCopyInto(out.(*APIVersions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&APIVersions{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*DeleteOptions).DeepCopyInto(out.(*DeleteOptions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&DeleteOptions{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Duration).DeepCopyInto(out.(*Duration))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Duration{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*ExportOptions).DeepCopyInto(out.(*ExportOptions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&ExportOptions{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*GetOptions).DeepCopyInto(out.(*GetOptions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&GetOptions{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*GroupKind).DeepCopyInto(out.(*GroupKind))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&GroupKind{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*GroupResource).DeepCopyInto(out.(*GroupResource))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&GroupResource{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*GroupVersion).DeepCopyInto(out.(*GroupVersion))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&GroupVersion{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*GroupVersionForDiscovery).DeepCopyInto(out.(*GroupVersionForDiscovery))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&GroupVersionForDiscovery{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*GroupVersionKind).DeepCopyInto(out.(*GroupVersionKind))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&GroupVersionKind{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*GroupVersionResource).DeepCopyInto(out.(*GroupVersionResource))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&GroupVersionResource{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Initializer).DeepCopyInto(out.(*Initializer))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Initializer{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Initializers).DeepCopyInto(out.(*Initializers))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Initializers{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*InternalEvent).DeepCopyInto(out.(*InternalEvent))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&InternalEvent{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*LabelSelector).DeepCopyInto(out.(*LabelSelector))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&LabelSelector{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*LabelSelectorRequirement).DeepCopyInto(out.(*LabelSelectorRequirement))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&LabelSelectorRequirement{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*List).DeepCopyInto(out.(*List))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&List{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*ListMeta).DeepCopyInto(out.(*ListMeta))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&ListMeta{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*ListOptions).DeepCopyInto(out.(*ListOptions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&ListOptions{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*MicroTime).DeepCopyInto(out.(*MicroTime))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&MicroTime{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*ObjectMeta).DeepCopyInto(out.(*ObjectMeta))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&ObjectMeta{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*OwnerReference).DeepCopyInto(out.(*OwnerReference))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&OwnerReference{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Patch).DeepCopyInto(out.(*Patch))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Patch{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Preconditions).DeepCopyInto(out.(*Preconditions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Preconditions{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*RootPaths).DeepCopyInto(out.(*RootPaths))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&RootPaths{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*ServerAddressByClientCIDR).DeepCopyInto(out.(*ServerAddressByClientCIDR))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&ServerAddressByClientCIDR{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Status).DeepCopyInto(out.(*Status))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Status{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*StatusCause).DeepCopyInto(out.(*StatusCause))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&StatusCause{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*StatusDetails).DeepCopyInto(out.(*StatusDetails))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&StatusDetails{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Time).DeepCopyInto(out.(*Time))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Time{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Timestamp).DeepCopyInto(out.(*Timestamp))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Timestamp{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*WatchEvent).DeepCopyInto(out.(*WatchEvent))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&WatchEvent{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *APIGroup) DeepCopyInto(out *APIGroup) {
|
||||
*out = *in
|
||||
|
||||
-38
@@ -21,47 +21,9 @@ limitations under the License.
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*PartialObjectMetadata).DeepCopyInto(out.(*PartialObjectMetadata))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&PartialObjectMetadata{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*PartialObjectMetadataList).DeepCopyInto(out.(*PartialObjectMetadataList))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&PartialObjectMetadataList{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Table).DeepCopyInto(out.(*Table))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Table{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*TableColumnDefinition).DeepCopyInto(out.(*TableColumnDefinition))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&TableColumnDefinition{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*TableOptions).DeepCopyInto(out.(*TableOptions))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&TableOptions{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*TableRow).DeepCopyInto(out.(*TableRow))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&TableRow{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*TableRowCondition).DeepCopyInto(out.(*TableRowCondition))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&TableRowCondition{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PartialObjectMetadata) DeepCopyInto(out *PartialObjectMetadata) {
|
||||
*out = *in
|
||||
|
||||
-2
@@ -10,7 +10,6 @@ go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"converter_test.go",
|
||||
"deep_copy_test.go",
|
||||
"helper_test.go",
|
||||
],
|
||||
importpath = "k8s.io/apimachinery/pkg/conversion",
|
||||
@@ -25,7 +24,6 @@ go_test(
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"cloner.go",
|
||||
"converter.go",
|
||||
"deep_equal.go",
|
||||
"doc.go",
|
||||
|
||||
-249
@@ -1,249 +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 conversion
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Cloner knows how to copy one type to another.
|
||||
type Cloner struct {
|
||||
// Map from the type to a function which can do the deep copy.
|
||||
deepCopyFuncs map[reflect.Type]reflect.Value
|
||||
generatedDeepCopyFuncs map[reflect.Type]func(in interface{}, out interface{}, c *Cloner) error
|
||||
}
|
||||
|
||||
// NewCloner creates a new Cloner object.
|
||||
func NewCloner() *Cloner {
|
||||
c := &Cloner{
|
||||
deepCopyFuncs: map[reflect.Type]reflect.Value{},
|
||||
generatedDeepCopyFuncs: map[reflect.Type]func(in interface{}, out interface{}, c *Cloner) error{},
|
||||
}
|
||||
if err := c.RegisterDeepCopyFunc(byteSliceDeepCopy); err != nil {
|
||||
// If one of the deep-copy functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// Prevent recursing into every byte...
|
||||
func byteSliceDeepCopy(in *[]byte, out *[]byte, c *Cloner) error {
|
||||
if *in != nil {
|
||||
*out = make([]byte, len(*in))
|
||||
copy(*out, *in)
|
||||
} else {
|
||||
*out = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Verifies whether a deep-copy function has a correct signature.
|
||||
func verifyDeepCopyFunctionSignature(ft reflect.Type) error {
|
||||
if ft.Kind() != reflect.Func {
|
||||
return fmt.Errorf("expected func, got: %v", ft)
|
||||
}
|
||||
if ft.NumIn() != 3 {
|
||||
return fmt.Errorf("expected three 'in' params, got %v", ft)
|
||||
}
|
||||
if ft.NumOut() != 1 {
|
||||
return fmt.Errorf("expected one 'out' param, got %v", ft)
|
||||
}
|
||||
if ft.In(0).Kind() != reflect.Ptr {
|
||||
return fmt.Errorf("expected pointer arg for 'in' param 0, got: %v", ft)
|
||||
}
|
||||
if ft.In(1) != ft.In(0) {
|
||||
return fmt.Errorf("expected 'in' param 0 the same as param 1, got: %v", ft)
|
||||
}
|
||||
var forClonerType Cloner
|
||||
if expected := reflect.TypeOf(&forClonerType); ft.In(2) != expected {
|
||||
return fmt.Errorf("expected '%v' arg for 'in' param 2, got: '%v'", expected, ft.In(2))
|
||||
}
|
||||
var forErrorType error
|
||||
// This convolution is necessary, otherwise TypeOf picks up on the fact
|
||||
// that forErrorType is nil
|
||||
errorType := reflect.TypeOf(&forErrorType).Elem()
|
||||
if ft.Out(0) != errorType {
|
||||
return fmt.Errorf("expected error return, got: %v", ft)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterGeneratedDeepCopyFunc registers a copying func with the Cloner.
|
||||
// deepCopyFunc must take three parameters: a type input, a pointer to a
|
||||
// type output, and a pointer to Cloner. It should return an error.
|
||||
//
|
||||
// Example:
|
||||
// c.RegisterGeneratedDeepCopyFunc(
|
||||
// func(in Pod, out *Pod, c *Cloner) error {
|
||||
// // deep copy logic...
|
||||
// return nil
|
||||
// })
|
||||
func (c *Cloner) RegisterDeepCopyFunc(deepCopyFunc interface{}) error {
|
||||
fv := reflect.ValueOf(deepCopyFunc)
|
||||
ft := fv.Type()
|
||||
if err := verifyDeepCopyFunctionSignature(ft); err != nil {
|
||||
return err
|
||||
}
|
||||
c.deepCopyFuncs[ft.In(0)] = fv
|
||||
return nil
|
||||
}
|
||||
|
||||
// GeneratedDeepCopyFunc bundles an untyped generated deep-copy function of a type
|
||||
// with a reflection type object used as a key to lookup the deep-copy function.
|
||||
type GeneratedDeepCopyFunc struct {
|
||||
Fn func(in interface{}, out interface{}, c *Cloner) error
|
||||
InType reflect.Type
|
||||
}
|
||||
|
||||
// Similar to RegisterDeepCopyFunc, but registers deep copy function that were
|
||||
// automatically generated.
|
||||
func (c *Cloner) RegisterGeneratedDeepCopyFunc(fn GeneratedDeepCopyFunc) error {
|
||||
c.generatedDeepCopyFuncs[fn.InType] = fn.Fn
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeepCopy will perform a deep copy of a given object.
|
||||
func (c *Cloner) DeepCopy(in interface{}) (interface{}, error) {
|
||||
// Can be invalid if we run DeepCopy(X) where X is a nil interface type.
|
||||
// For example, we get an invalid value when someone tries to deep-copy
|
||||
// a nil labels.Selector.
|
||||
// This does not occur if X is nil and is a pointer to a concrete type.
|
||||
if in == nil {
|
||||
return nil, nil
|
||||
}
|
||||
inValue := reflect.ValueOf(in)
|
||||
outValue, err := c.deepCopy(inValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return outValue.Interface(), nil
|
||||
}
|
||||
|
||||
func (c *Cloner) deepCopy(src reflect.Value) (reflect.Value, error) {
|
||||
inType := src.Type()
|
||||
|
||||
switch src.Kind() {
|
||||
case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice:
|
||||
if src.IsNil() {
|
||||
return src, nil
|
||||
}
|
||||
}
|
||||
|
||||
if fv, ok := c.deepCopyFuncs[inType]; ok {
|
||||
return c.customDeepCopy(src, fv)
|
||||
}
|
||||
if fv, ok := c.generatedDeepCopyFuncs[inType]; ok {
|
||||
var outValue reflect.Value
|
||||
outValue = reflect.New(inType.Elem())
|
||||
err := fv(src.Interface(), outValue.Interface(), c)
|
||||
return outValue, err
|
||||
}
|
||||
return c.defaultDeepCopy(src)
|
||||
}
|
||||
|
||||
func (c *Cloner) customDeepCopy(src, fv reflect.Value) (reflect.Value, error) {
|
||||
outValue := reflect.New(src.Type().Elem())
|
||||
args := []reflect.Value{src, outValue, reflect.ValueOf(c)}
|
||||
result := fv.Call(args)[0].Interface()
|
||||
// This convolution is necessary because nil interfaces won't convert
|
||||
// to error.
|
||||
if result == nil {
|
||||
return outValue, nil
|
||||
}
|
||||
return outValue, result.(error)
|
||||
}
|
||||
|
||||
func (c *Cloner) defaultDeepCopy(src reflect.Value) (reflect.Value, error) {
|
||||
switch src.Kind() {
|
||||
case reflect.Chan, reflect.Func, reflect.UnsafePointer, reflect.Uintptr:
|
||||
return src, fmt.Errorf("cannot deep copy kind: %s", src.Kind())
|
||||
case reflect.Array:
|
||||
dst := reflect.New(src.Type())
|
||||
for i := 0; i < src.Len(); i++ {
|
||||
copyVal, err := c.deepCopy(src.Index(i))
|
||||
if err != nil {
|
||||
return src, err
|
||||
}
|
||||
dst.Elem().Index(i).Set(copyVal)
|
||||
}
|
||||
return dst.Elem(), nil
|
||||
case reflect.Interface:
|
||||
if src.IsNil() {
|
||||
return src, nil
|
||||
}
|
||||
return c.deepCopy(src.Elem())
|
||||
case reflect.Map:
|
||||
if src.IsNil() {
|
||||
return src, nil
|
||||
}
|
||||
dst := reflect.MakeMap(src.Type())
|
||||
for _, k := range src.MapKeys() {
|
||||
copyVal, err := c.deepCopy(src.MapIndex(k))
|
||||
if err != nil {
|
||||
return src, err
|
||||
}
|
||||
dst.SetMapIndex(k, copyVal)
|
||||
}
|
||||
return dst, nil
|
||||
case reflect.Ptr:
|
||||
if src.IsNil() {
|
||||
return src, nil
|
||||
}
|
||||
dst := reflect.New(src.Type().Elem())
|
||||
copyVal, err := c.deepCopy(src.Elem())
|
||||
if err != nil {
|
||||
return src, err
|
||||
}
|
||||
dst.Elem().Set(copyVal)
|
||||
return dst, nil
|
||||
case reflect.Slice:
|
||||
if src.IsNil() {
|
||||
return src, nil
|
||||
}
|
||||
dst := reflect.MakeSlice(src.Type(), 0, src.Len())
|
||||
for i := 0; i < src.Len(); i++ {
|
||||
copyVal, err := c.deepCopy(src.Index(i))
|
||||
if err != nil {
|
||||
return src, err
|
||||
}
|
||||
dst = reflect.Append(dst, copyVal)
|
||||
}
|
||||
return dst, nil
|
||||
case reflect.Struct:
|
||||
dst := reflect.New(src.Type())
|
||||
for i := 0; i < src.NumField(); i++ {
|
||||
if !dst.Elem().Field(i).CanSet() {
|
||||
// Can't set private fields. At this point, the
|
||||
// best we can do is a shallow copy. For
|
||||
// example, time.Time is a value type with
|
||||
// private members that can be shallow copied.
|
||||
return src, nil
|
||||
}
|
||||
copyVal, err := c.deepCopy(src.Field(i))
|
||||
if err != nil {
|
||||
return src, err
|
||||
}
|
||||
dst.Elem().Field(i).Set(copyVal)
|
||||
}
|
||||
return dst.Elem(), nil
|
||||
|
||||
default:
|
||||
// Value types like numbers, booleans, and strings.
|
||||
return src, nil
|
||||
}
|
||||
}
|
||||
-1
@@ -31,7 +31,6 @@ go_library(
|
||||
importpath = "k8s.io/apimachinery/pkg/labels",
|
||||
deps = [
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/selection:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/validation:go_default_library",
|
||||
|
||||
-17
@@ -20,23 +20,6 @@ limitations under the License.
|
||||
|
||||
package labels
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Requirement).DeepCopyInto(out.(*Requirement))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Requirement{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Requirement) DeepCopyInto(out *Requirement) {
|
||||
*out = *in
|
||||
|
||||
+2
-2
@@ -94,8 +94,6 @@ type missingVersionErr struct {
|
||||
data string
|
||||
}
|
||||
|
||||
// IsMissingVersion returns true if the error indicates that the provided object
|
||||
// is missing a 'Version' field.
|
||||
func NewMissingVersionErr(data string) error {
|
||||
return &missingVersionErr{data}
|
||||
}
|
||||
@@ -104,6 +102,8 @@ func (k *missingVersionErr) Error() string {
|
||||
return fmt.Sprintf("Object 'apiVersion' is missing in '%s'", k.data)
|
||||
}
|
||||
|
||||
// IsMissingVersion returns true if the error indicates that the provided object
|
||||
// is missing a 'Version' field.
|
||||
func IsMissingVersion(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
|
||||
+4
-32
@@ -68,10 +68,6 @@ type Scheme struct {
|
||||
// converter stores all registered conversion functions. It also has
|
||||
// default coverting behavior.
|
||||
converter *conversion.Converter
|
||||
|
||||
// cloner stores all registered copy functions. It also has default
|
||||
// deep copy behavior.
|
||||
cloner *conversion.Cloner
|
||||
}
|
||||
|
||||
// Function to convert a field selector to internal representation.
|
||||
@@ -80,11 +76,10 @@ type FieldLabelConversionFunc func(label, value string) (internalLabel, internal
|
||||
// NewScheme creates a new Scheme. This scheme is pluggable by default.
|
||||
func NewScheme() *Scheme {
|
||||
s := &Scheme{
|
||||
gvkToType: map[schema.GroupVersionKind]reflect.Type{},
|
||||
typeToGVK: map[reflect.Type][]schema.GroupVersionKind{},
|
||||
unversionedTypes: map[reflect.Type]schema.GroupVersionKind{},
|
||||
unversionedKinds: map[string]reflect.Type{},
|
||||
cloner: conversion.NewCloner(),
|
||||
gvkToType: map[schema.GroupVersionKind]reflect.Type{},
|
||||
typeToGVK: map[reflect.Type][]schema.GroupVersionKind{},
|
||||
unversionedTypes: map[reflect.Type]schema.GroupVersionKind{},
|
||||
unversionedKinds: map[string]reflect.Type{},
|
||||
fieldLabelConversionFuncs: map[string]map[string]FieldLabelConversionFunc{},
|
||||
defaulterFuncs: map[reflect.Type]func(interface{}){},
|
||||
}
|
||||
@@ -354,29 +349,6 @@ func (s *Scheme) AddGeneratedConversionFuncs(conversionFuncs ...interface{}) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddDeepCopyFuncs adds a function to the list of deep-copy functions.
|
||||
// For the expected format of deep-copy function, see the comment for
|
||||
// Copier.RegisterDeepCopyFunction.
|
||||
func (s *Scheme) AddDeepCopyFuncs(deepCopyFuncs ...interface{}) error {
|
||||
for _, f := range deepCopyFuncs {
|
||||
if err := s.cloner.RegisterDeepCopyFunc(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Similar to AddDeepCopyFuncs, but registers deep-copy functions that were
|
||||
// automatically generated.
|
||||
func (s *Scheme) AddGeneratedDeepCopyFuncs(deepCopyFuncs ...conversion.GeneratedDeepCopyFunc) error {
|
||||
for _, fn := range deepCopyFuncs {
|
||||
if err := s.cloner.RegisterGeneratedDeepCopyFunc(fn); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddFieldLabelConversionFunc adds a conversion function to convert field selectors
|
||||
// of the given kind from the given version to internal version representation.
|
||||
func (s *Scheme) AddFieldLabelConversionFunc(version, kind string, conversionFunc FieldLabelConversionFunc) error {
|
||||
|
||||
-25
@@ -20,31 +20,6 @@ limitations under the License.
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*RawExtension).DeepCopyInto(out.(*RawExtension))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&RawExtension{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Unknown).DeepCopyInto(out.(*Unknown))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Unknown{})},
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*VersionedObjects).DeepCopyInto(out.(*VersionedObjects))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&VersionedObjects{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *RawExtension) DeepCopyInto(out *RawExtension) {
|
||||
*out = *in
|
||||
|
||||
-1
@@ -20,7 +20,6 @@ go_library(
|
||||
importpath = "k8s.io/apimachinery/pkg/watch",
|
||||
deps = [
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
||||
|
||||
-17
@@ -20,23 +20,6 @@ limitations under the License.
|
||||
|
||||
package watch
|
||||
|
||||
import (
|
||||
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||
//
|
||||
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
|
||||
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||
return []conversion.GeneratedDeepCopyFunc{
|
||||
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||
in.(*Event).DeepCopyInto(out.(*Event))
|
||||
return nil
|
||||
}, InType: reflect.TypeOf(&Event{})},
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Event) DeepCopyInto(out *Event) {
|
||||
*out = *in
|
||||
|
||||
Reference in New Issue
Block a user