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:
parent
530dec4a81
commit
36b2f4560f
|
|
@ -21,6 +21,8 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
// AdmissionConfiguration provides versioned configuration for admission controllers.
|
||||
type AdmissionConfiguration struct {
|
||||
metav1.TypeMeta
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
// AdmissionConfiguration provides versioned configuration for admission controllers.
|
||||
type AdmissionConfiguration struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ const (
|
|||
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.
|
||||
type Event struct {
|
||||
metav1.TypeMeta
|
||||
|
|
@ -118,6 +120,8 @@ type Event struct {
|
|||
ResponseObject *runtime.Unknown
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
// EventList is a list of audit Events.
|
||||
type EventList struct {
|
||||
metav1.TypeMeta
|
||||
|
|
@ -127,6 +131,8 @@ type EventList struct {
|
|||
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
|
||||
// categories are logged.
|
||||
type Policy struct {
|
||||
|
|
@ -142,6 +148,8 @@ type Policy struct {
|
|||
Rules []PolicyRule
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
// PolicyList is a list of audit Policies.
|
||||
type PolicyList struct {
|
||||
metav1.TypeMeta
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ const (
|
|||
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.
|
||||
type Event struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
|
@ -119,6 +121,8 @@ type Event struct {
|
|||
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.
|
||||
type EventList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
|
@ -128,6 +132,8 @@ type EventList struct {
|
|||
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
|
||||
// categories are logged.
|
||||
type Policy struct {
|
||||
|
|
@ -143,6 +149,8 @@ type Policy struct {
|
|||
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.
|
||||
type PolicyList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ type (
|
|||
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).
|
||||
type Pod struct {
|
||||
metav1.TypeMeta
|
||||
|
|
@ -124,6 +126,8 @@ type PodSpec struct {
|
|||
SchedulerName string
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
// PodList is a list of Pods.
|
||||
type PodList struct {
|
||||
metav1.TypeMeta
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ type (
|
|||
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).
|
||||
type Pod struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
|
@ -178,6 +180,8 @@ type PodSpec struct {
|
|||
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.
|
||||
type PodList struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
|
|
|
|||
|
|
@ -467,6 +467,9 @@ func (s *SimpleStream) Close() error {
|
|||
}
|
||||
|
||||
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) {
|
||||
s.version = version
|
||||
|
|
@ -3761,6 +3764,13 @@ type UnregisteredAPIObject struct {
|
|||
func (obj *UnregisteredAPIObject) GetObjectKind() schema.ObjectKind {
|
||||
return schema.EmptyObjectKind
|
||||
}
|
||||
func (obj *UnregisteredAPIObject) DeepCopyObject() runtime.Object {
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
clone := *obj
|
||||
return &clone
|
||||
}
|
||||
|
||||
func TestWriteJSONDecodeError(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,14 @@ type TestPatchSubType struct {
|
|||
StringField string `json:"theField"`
|
||||
}
|
||||
|
||||
func (obj *testPatchType) DeepCopyObject() runtime.Object {
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
clone := *obj
|
||||
return &clone
|
||||
}
|
||||
|
||||
func TestPatchAnonymousField(t *testing.T) {
|
||||
testGV := schema.GroupVersion{Group: "", Version: "v"}
|
||||
scheme.AddKnownTypes(testGV, &testPatchType{})
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
)
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
type TestType struct {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
type Simple struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata"`
|
||||
|
|
@ -29,6 +31,8 @@ type Simple struct {
|
|||
Labels map[string]string `json:"labels,omitempty"`
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
type SimpleRoot struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata"`
|
||||
|
|
@ -38,6 +42,8 @@ type SimpleRoot struct {
|
|||
Labels map[string]string `json:"labels,omitempty"`
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
type SimpleGetOptions struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
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 {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ListMeta `json:"metadata,inline"`
|
||||
|
|
@ -59,6 +67,8 @@ type SimpleList struct {
|
|||
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
|
||||
// same group as its parent resource.
|
||||
type SimpleXGSubresource struct {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
)
|
||||
|
|
@ -42,6 +43,9 @@ var _ rest.ResourceStreamer = &LocationStreamer{}
|
|||
func (obj *LocationStreamer) GetObjectKind() schema.ObjectKind {
|
||||
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,
|
||||
// a null stream is returned.
|
||||
|
|
|
|||
|
|
@ -319,6 +319,8 @@ type StorageMetadata 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
|
||||
type ConnectRequest struct {
|
||||
// Name is the name of the object on which the connect request was made
|
||||
|
|
|
|||
|
|
@ -36,6 +36,12 @@ type IgnoredList struct {
|
|||
|
||||
func (obj *Ignored) 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) {
|
||||
table := map[string]struct {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
type TestResource struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata"`
|
||||
|
|
|
|||
Loading…
Reference in New Issue