mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
deepcopy: misc fixes for static deepcopy compilation
- port direct calls to deepcopy funcs - apimachinery: fix types in unstructured converter test - federation: fix deepcopy registration
This commit is contained in:
parent
39d95b9b06
commit
2bbe72d4e0
@ -61,7 +61,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
if err := scheme.AddGeneratedDeepCopyFuncs(
|
if err := scheme.AddGeneratedDeepCopyFuncs(
|
||||||
conversion.GeneratedDeepCopyFunc{
|
conversion.GeneratedDeepCopyFunc{
|
||||||
Fn: metav1.DeepCopy_v1_Time,
|
Fn: func(in, out interface{}, c *conversion.Cloner) error {
|
||||||
|
in.(*metav1.Time).DeepCopyInto(out.(*metav1.Time))
|
||||||
|
return nil
|
||||||
|
},
|
||||||
InType: reflect.TypeOf(&metav1.Time{}),
|
InType: reflect.TypeOf(&metav1.Time{}),
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -109,10 +109,7 @@ func (c *CRDFinalizer) sync(key string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
crd := &apiextensions.CustomResourceDefinition{}
|
crd := cachedCRD.DeepCopy()
|
||||||
if err := apiextensions.DeepCopy_apiextensions_CustomResourceDefinition(cachedCRD, crd, cloner); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the status condition. This cleanup could take a while.
|
// update the status condition. This cleanup could take a while.
|
||||||
apiextensions.SetCRDCondition(crd, apiextensions.CustomResourceDefinitionCondition{
|
apiextensions.SetCRDCondition(crd, apiextensions.CustomResourceDefinitionCondition{
|
||||||
@ -320,18 +317,8 @@ func (c *CRDFinalizer) updateCustomResourceDefinition(oldObj, newObj interface{}
|
|||||||
// is likely to be the originator, so requeuing would hot-loop us. Failures are requeued by the workqueue directly.
|
// is likely to be the originator, so requeuing would hot-loop us. Failures are requeued by the workqueue directly.
|
||||||
// This is a low traffic and scale resource, so the copy is terrible. It's not good, so better ideas
|
// This is a low traffic and scale resource, so the copy is terrible. It's not good, so better ideas
|
||||||
// are welcome.
|
// are welcome.
|
||||||
oldCopy := &apiextensions.CustomResourceDefinition{}
|
oldCopy := oldCRD.DeepCopy()
|
||||||
if err := apiextensions.DeepCopy_apiextensions_CustomResourceDefinition(oldCRD, oldCopy, cloner); err != nil {
|
newCopy := newCRD.DeepCopy()
|
||||||
utilruntime.HandleError(err)
|
|
||||||
c.enqueue(newCRD)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
newCopy := &apiextensions.CustomResourceDefinition{}
|
|
||||||
if err := apiextensions.DeepCopy_apiextensions_CustomResourceDefinition(newCRD, newCopy, cloner); err != nil {
|
|
||||||
utilruntime.HandleError(err)
|
|
||||||
c.enqueue(newCRD)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
oldCopy.ResourceVersion = ""
|
oldCopy.ResourceVersion = ""
|
||||||
newCopy.ResourceVersion = ""
|
newCopy.ResourceVersion = ""
|
||||||
apiextensions.RemoveCRDCondition(oldCopy, apiextensions.Terminating)
|
apiextensions.RemoveCRDCondition(oldCopy, apiextensions.Terminating)
|
||||||
|
@ -251,11 +251,7 @@ func (c *NamingConditionController) sync(key string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
crd := &apiextensions.CustomResourceDefinition{}
|
crd := inCustomResourceDefinition.DeepCopy()
|
||||||
if err := apiextensions.DeepCopy_apiextensions_CustomResourceDefinition(inCustomResourceDefinition, crd, cloner); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
crd.Status.AcceptedNames = acceptedNames
|
crd.Status.AcceptedNames = acceptedNames
|
||||||
apiextensions.SetCRDCondition(crd, namingCondition)
|
apiextensions.SetCRDCondition(crd, namingCondition)
|
||||||
apiextensions.SetCRDCondition(crd, establishedCondition)
|
apiextensions.SetCRDCondition(crd, establishedCondition)
|
||||||
|
@ -21,8 +21,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
"k8s.io/apimachinery/pkg/util/diff"
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
)
|
)
|
||||||
@ -73,25 +71,7 @@ type F struct {
|
|||||||
I []float32 `json:"fi"`
|
I []float32 `json:"fi"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement runtime.Object to make types usable for tests.
|
func doRoundTrip(t *testing.T, item interface{}) {
|
||||||
|
|
||||||
func (c *C) GetObjectKind() schema.ObjectKind {
|
|
||||||
return schema.EmptyObjectKind
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *D) GetObjectKind() schema.ObjectKind {
|
|
||||||
return schema.EmptyObjectKind
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *E) GetObjectKind() schema.ObjectKind {
|
|
||||||
return schema.EmptyObjectKind
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *F) GetObjectKind() schema.ObjectKind {
|
|
||||||
return schema.EmptyObjectKind
|
|
||||||
}
|
|
||||||
|
|
||||||
func doRoundTrip(t *testing.T, item runtime.Object) {
|
|
||||||
data, err := json.Marshal(item)
|
data, err := json.Marshal(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error when marshaling object: %v", err)
|
t.Errorf("Error when marshaling object: %v", err)
|
||||||
@ -127,7 +107,7 @@ func doRoundTrip(t *testing.T, item runtime.Object) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newObj := reflect.New(reflect.TypeOf(item).Elem()).Interface().(runtime.Object)
|
newObj := reflect.New(reflect.TypeOf(item).Elem()).Interface()
|
||||||
err = DefaultConverter.FromUnstructured(newUnstr, newObj)
|
err = DefaultConverter.FromUnstructured(newUnstr, newObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("FromUnstructured failed: %v", err)
|
t.Errorf("FromUnstructured failed: %v", err)
|
||||||
@ -142,7 +122,7 @@ func doRoundTrip(t *testing.T, item runtime.Object) {
|
|||||||
func TestRoundTrip(t *testing.T) {
|
func TestRoundTrip(t *testing.T) {
|
||||||
intVal := int64(42)
|
intVal := int64(42)
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
obj runtime.Object
|
obj interface{}
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
// This (among others) tests nil map, slice and pointer.
|
// This (among others) tests nil map, slice and pointer.
|
||||||
@ -223,7 +203,7 @@ func TestRoundTrip(t *testing.T) {
|
|||||||
// 1) serialized json -> object
|
// 1) serialized json -> object
|
||||||
// 2) serialized json -> map[string]interface{} -> object
|
// 2) serialized json -> map[string]interface{} -> object
|
||||||
// produces the same object.
|
// produces the same object.
|
||||||
func doUnrecognized(t *testing.T, jsonData string, item runtime.Object, expectedErr error) {
|
func doUnrecognized(t *testing.T, jsonData string, item interface{}, expectedErr error) {
|
||||||
unmarshalledObj := reflect.New(reflect.TypeOf(item).Elem()).Interface()
|
unmarshalledObj := reflect.New(reflect.TypeOf(item).Elem()).Interface()
|
||||||
err := json.Unmarshal([]byte(jsonData), &unmarshalledObj)
|
err := json.Unmarshal([]byte(jsonData), &unmarshalledObj)
|
||||||
if (err != nil) != (expectedErr != nil) {
|
if (err != nil) != (expectedErr != nil) {
|
||||||
@ -237,7 +217,7 @@ func doUnrecognized(t *testing.T, jsonData string, item runtime.Object, expected
|
|||||||
t.Errorf("Error when unmarshaling to unstructured: %v", err)
|
t.Errorf("Error when unmarshaling to unstructured: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newObj := reflect.New(reflect.TypeOf(item).Elem()).Interface().(runtime.Object)
|
newObj := reflect.New(reflect.TypeOf(item).Elem()).Interface()
|
||||||
err = DefaultConverter.FromUnstructured(unstr, newObj)
|
err = DefaultConverter.FromUnstructured(unstr, newObj)
|
||||||
if (err != nil) != (expectedErr != nil) {
|
if (err != nil) != (expectedErr != nil) {
|
||||||
t.Errorf("Unexpected error in FromUnstructured: %v, expected: %v", err, expectedErr)
|
t.Errorf("Unexpected error in FromUnstructured: %v, expected: %v", err, expectedErr)
|
||||||
@ -251,7 +231,7 @@ func doUnrecognized(t *testing.T, jsonData string, item runtime.Object, expected
|
|||||||
func TestUnrecognized(t *testing.T) {
|
func TestUnrecognized(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
data string
|
data string
|
||||||
obj runtime.Object
|
obj interface{}
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -22,8 +22,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
"k8s.io/apimachinery/pkg/apimachinery/announced"
|
||||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -260,11 +258,7 @@ func (b *batchBackend) ProcessEvents(ev ...*auditinternal.Event) {
|
|||||||
for i, e := range ev {
|
for i, e := range ev {
|
||||||
// Per the audit.Backend interface these events are reused after being
|
// Per the audit.Backend interface these events are reused after being
|
||||||
// sent to the Sink. Deep copy and send the copy to the queue.
|
// sent to the Sink. Deep copy and send the copy to the queue.
|
||||||
event := new(auditinternal.Event)
|
event := e.DeepCopy()
|
||||||
if err := auditinternal.DeepCopy_audit_Event(e, event, b.cloner); err != nil {
|
|
||||||
glog.Errorf("failed to clone audit event: %v: %#v", err, e)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case b.buffer <- event:
|
case b.buffer <- event:
|
||||||
|
@ -206,10 +206,7 @@ func (c *autoRegisterController) checkAPIService(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we have an entry and we have a desired, now we deconflict. Only a few fields matter.
|
// we have an entry and we have a desired, now we deconflict. Only a few fields matter.
|
||||||
apiService := &apiregistration.APIService{}
|
apiService := curr.DeepCopy()
|
||||||
if err := apiregistration.DeepCopy_apiregistration_APIService(curr, apiService, cloner); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
apiService.Spec = desired.Spec
|
apiService.Spec = desired.Spec
|
||||||
_, err = c.apiServiceClient.APIServices().Update(apiService)
|
_, err = c.apiServiceClient.APIServices().Update(apiService)
|
||||||
return err
|
return err
|
||||||
@ -226,12 +223,7 @@ func (c *autoRegisterController) AddAPIServiceToSync(in *apiregistration.APIServ
|
|||||||
c.apiServicesToSyncLock.Lock()
|
c.apiServicesToSyncLock.Lock()
|
||||||
defer c.apiServicesToSyncLock.Unlock()
|
defer c.apiServicesToSyncLock.Unlock()
|
||||||
|
|
||||||
apiService := &apiregistration.APIService{}
|
apiService := in.DeepCopy()
|
||||||
if err := apiregistration.DeepCopy_apiregistration_APIService(in, apiService, cloner); err != nil {
|
|
||||||
// this shouldn't happen
|
|
||||||
utilruntime.HandleError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if apiService.Labels == nil {
|
if apiService.Labels == nil {
|
||||||
apiService.Labels = map[string]string{}
|
apiService.Labels = map[string]string{}
|
||||||
}
|
}
|
||||||
|
@ -113,10 +113,7 @@ func (c *AvailableConditionController) sync(key string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
apiService := &apiregistration.APIService{}
|
apiService := inAPIService.DeepCopy()
|
||||||
if err := apiregistration.DeepCopy_apiregistration_APIService(inAPIService, apiService, cloner); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
availableCondition := apiregistration.APIServiceCondition{
|
availableCondition := apiregistration.APIServiceCondition{
|
||||||
Type: apiregistration.Available,
|
Type: apiregistration.Available,
|
||||||
|
Loading…
Reference in New Issue
Block a user