deepcopy: add interface deepcopy funcs

- add DeepCopyObject() to runtime.Object interface
- add DeepCopyObject() via deepcopy-gen
- add DeepCopyObject() manually
- add DeepCopySelector() to selector interfaces
- add custom DeepCopy func for TableRow.Cells

Kubernetes-commit: 39d95b9b065fffebe5b6f233d978fe1723722085
This commit is contained in:
Dr. Stefan Schimanski 2017-07-06 10:59:05 +02:00 committed by Kubernetes Publisher
parent 530dec4a81
commit 36b2f4560f
14 changed files with 71 additions and 0 deletions

View File

@ -21,6 +21,8 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// AdmissionConfiguration provides versioned configuration for admission controllers. // AdmissionConfiguration provides versioned configuration for admission controllers.
type AdmissionConfiguration struct { type AdmissionConfiguration struct {
metav1.TypeMeta metav1.TypeMeta

View File

@ -21,6 +21,8 @@ import (
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// AdmissionConfiguration provides versioned configuration for admission controllers. // AdmissionConfiguration provides versioned configuration for admission controllers.
type AdmissionConfiguration struct { type AdmissionConfiguration struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`

View File

@ -65,6 +65,8 @@ const (
StagePanic = "Panic" StagePanic = "Panic"
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Event captures all the information that can be included in an API audit log. // Event captures all the information that can be included in an API audit log.
type Event struct { type Event struct {
metav1.TypeMeta metav1.TypeMeta
@ -118,6 +120,8 @@ type Event struct {
ResponseObject *runtime.Unknown ResponseObject *runtime.Unknown
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// EventList is a list of audit Events. // EventList is a list of audit Events.
type EventList struct { type EventList struct {
metav1.TypeMeta metav1.TypeMeta
@ -127,6 +131,8 @@ type EventList struct {
Items []Event Items []Event
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Policy defines the configuration of audit logging, and the rules for how different request // Policy defines the configuration of audit logging, and the rules for how different request
// categories are logged. // categories are logged.
type Policy struct { type Policy struct {
@ -142,6 +148,8 @@ type Policy struct {
Rules []PolicyRule Rules []PolicyRule
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PolicyList is a list of audit Policies. // PolicyList is a list of audit Policies.
type PolicyList struct { type PolicyList struct {
metav1.TypeMeta metav1.TypeMeta

View File

@ -66,6 +66,8 @@ const (
StagePanic = "Panic" StagePanic = "Panic"
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Event captures all the information that can be included in an API audit log. // Event captures all the information that can be included in an API audit log.
type Event struct { type Event struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
@ -119,6 +121,8 @@ type Event struct {
ResponseObject *runtime.Unknown `json:"responseObject,omitempty" protobuf:"bytes,14,opt,name=responseObject"` ResponseObject *runtime.Unknown `json:"responseObject,omitempty" protobuf:"bytes,14,opt,name=responseObject"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// EventList is a list of audit Events. // EventList is a list of audit Events.
type EventList struct { type EventList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
@ -128,6 +132,8 @@ type EventList struct {
Items []Event `json:"items" protobuf:"bytes,2,rep,name=items"` Items []Event `json:"items" protobuf:"bytes,2,rep,name=items"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Policy defines the configuration of audit logging, and the rules for how different request // Policy defines the configuration of audit logging, and the rules for how different request
// categories are logged. // categories are logged.
type Policy struct { type Policy struct {
@ -143,6 +149,8 @@ type Policy struct {
Rules []PolicyRule `json:"rules" protobuf:"bytes,2,rep,name=rules"` Rules []PolicyRule `json:"rules" protobuf:"bytes,2,rep,name=rules"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PolicyList is a list of audit Policies. // PolicyList is a list of audit Policies.
type PolicyList struct { type PolicyList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`

View File

@ -27,6 +27,8 @@ type (
RestartPolicy string RestartPolicy string
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Pod is a collection of containers, used as either input (create, update) or as output (list, get). // Pod is a collection of containers, used as either input (create, update) or as output (list, get).
type Pod struct { type Pod struct {
metav1.TypeMeta metav1.TypeMeta
@ -124,6 +126,8 @@ type PodSpec struct {
SchedulerName string SchedulerName string
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PodList is a list of Pods. // PodList is a list of Pods.
type PodList struct { type PodList struct {
metav1.TypeMeta metav1.TypeMeta

View File

@ -27,6 +27,8 @@ type (
RestartPolicy string RestartPolicy string
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Pod is a collection of containers, used as either input (create, update) or as output (list, get). // Pod is a collection of containers, used as either input (create, update) or as output (list, get).
type Pod struct { type Pod struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
@ -178,6 +180,8 @@ type PodSpec struct {
SchedulerName string `json:"schedulername,omitempty" protobuf:"bytes,19,opt,name=schedulername"` SchedulerName string `json:"schedulername,omitempty" protobuf:"bytes,19,opt,name=schedulername"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PodList is a list of Pods. // PodList is a list of Pods.
type PodList struct { type PodList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`

View File

@ -467,6 +467,9 @@ func (s *SimpleStream) Close() error {
} }
func (obj *SimpleStream) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind } func (obj *SimpleStream) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func (obj *SimpleStream) DeepCopyObject() runtime.Object {
panic("SimpleStream does not support DeepCopy")
}
func (s *SimpleStream) InputStream(version, accept string) (io.ReadCloser, bool, string, error) { func (s *SimpleStream) InputStream(version, accept string) (io.ReadCloser, bool, string, error) {
s.version = version s.version = version
@ -3761,6 +3764,13 @@ type UnregisteredAPIObject struct {
func (obj *UnregisteredAPIObject) GetObjectKind() schema.ObjectKind { func (obj *UnregisteredAPIObject) GetObjectKind() schema.ObjectKind {
return schema.EmptyObjectKind return schema.EmptyObjectKind
} }
func (obj *UnregisteredAPIObject) DeepCopyObject() runtime.Object {
if obj == nil {
return nil
}
clone := *obj
return &clone
}
func TestWriteJSONDecodeError(t *testing.T) { func TestWriteJSONDecodeError(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {

View File

@ -64,6 +64,14 @@ type TestPatchSubType struct {
StringField string `json:"theField"` StringField string `json:"theField"`
} }
func (obj *testPatchType) DeepCopyObject() runtime.Object {
if obj == nil {
return nil
}
clone := *obj
return &clone
}
func TestPatchAnonymousField(t *testing.T) { func TestPatchAnonymousField(t *testing.T) {
testGV := schema.GroupVersion{Group: "", Version: "v"} testGV := schema.GroupVersion{Group: "", Version: "v"}
scheme.AddKnownTypes(testGV, &testPatchType{}) scheme.AddKnownTypes(testGV, &testPatchType{})

View File

@ -21,6 +21,7 @@ import (
) )
// +k8s:deepcopy-gen=true // +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type TestType struct { type TestType struct {
} }

View File

@ -20,6 +20,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type Simple struct { type Simple struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"` metav1.ObjectMeta `json:"metadata"`
@ -29,6 +31,8 @@ type Simple struct {
Labels map[string]string `json:"labels,omitempty"` Labels map[string]string `json:"labels,omitempty"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type SimpleRoot struct { type SimpleRoot struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"` metav1.ObjectMeta `json:"metadata"`
@ -38,6 +42,8 @@ type SimpleRoot struct {
Labels map[string]string `json:"labels,omitempty"` Labels map[string]string `json:"labels,omitempty"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type SimpleGetOptions struct { type SimpleGetOptions struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
Param1 string `json:"param1"` Param1 string `json:"param1"`
@ -52,6 +58,8 @@ func (SimpleGetOptions) SwaggerDoc() map[string]string {
} }
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type SimpleList struct { type SimpleList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,inline"` metav1.ListMeta `json:"metadata,inline"`
@ -59,6 +67,8 @@ type SimpleList struct {
Items []Simple `json:"items,omitempty"` Items []Simple `json:"items,omitempty"`
} }
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the // SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the
// same group as its parent resource. // same group as its parent resource.
type SimpleXGSubresource struct { type SimpleXGSubresource struct {

View File

@ -22,6 +22,7 @@ import (
"net/url" "net/url"
"strings" "strings"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest" "k8s.io/apiserver/pkg/registry/rest"
) )
@ -42,6 +43,9 @@ var _ rest.ResourceStreamer = &LocationStreamer{}
func (obj *LocationStreamer) GetObjectKind() schema.ObjectKind { func (obj *LocationStreamer) GetObjectKind() schema.ObjectKind {
return schema.EmptyObjectKind return schema.EmptyObjectKind
} }
func (obj *LocationStreamer) DeepCopyObject() runtime.Object {
panic("rest.LocationStreamer does not implement DeepCopyObject")
}
// InputStream returns a stream with the contents of the URL location. If no location is provided, // InputStream returns a stream with the contents of the URL location. If no location is provided,
// a null stream is returned. // a null stream is returned.

View File

@ -319,6 +319,8 @@ type StorageMetadata interface {
ProducesObject(verb string) interface{} ProducesObject(verb string) interface{}
} }
// +k8s:deepcopy-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ConnectRequest is an object passed to admission control for Connect operations // ConnectRequest is an object passed to admission control for Connect operations
type ConnectRequest struct { type ConnectRequest struct {
// Name is the name of the object on which the connect request was made // Name is the name of the object on which the connect request was made

View File

@ -36,6 +36,12 @@ type IgnoredList struct {
func (obj *Ignored) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind } func (obj *Ignored) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func (obj *IgnoredList) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind } func (obj *IgnoredList) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func (obj *Ignored) DeepCopyObject() runtime.Object {
panic("Ignored does not support DeepCopy")
}
func (obj *IgnoredList) DeepCopyObject() runtime.Object {
panic("IgnoredList does not support DeepCopy")
}
func TestSelectionPredicate(t *testing.T) { func TestSelectionPredicate(t *testing.T) {
table := map[string]struct { table := map[string]struct {

View File

@ -20,6 +20,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type TestResource struct { type TestResource struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"` metav1.ObjectMeta `json:"metadata"`