forked from openshift/cloud-credential-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more auto deepcopy functions (less manual)
and fix up bug around incomplete DeepCopy (where changing the source object would change parts of the copied object). add test cases remove assert library for these tests (not appropriate for openshift/api)
- Loading branch information
Joel Diaz
committed
Aug 17, 2020
1 parent
0296575
commit cbab0ed
Showing
4 changed files
with
213 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,50 @@ | ||
package v1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
// DeepCopyInto will perform a DeepCopy into the provided AWSProviderSpec | ||
func (in *AWSProviderSpec) DeepCopyInto(out *AWSProviderSpec) { | ||
*out = *in | ||
out.TypeMeta = in.TypeMeta | ||
if in.StatementEntries != nil { | ||
in, out := &in.StatementEntries, &out.StatementEntries | ||
*out = make([]StatementEntry, len(*in)) | ||
for i := range *in { | ||
(*in)[i].DeepCopyInto(&(*out)[i]) | ||
} | ||
} | ||
return | ||
} | ||
|
||
// DeepCopy will DeepCopy and return a pointer to a | ||
// new AWSProviderSpec | ||
func (in *AWSProviderSpec) DeepCopy() *AWSProviderSpec { | ||
// DeepCopy is a deepcopy function, copying the receiver, creating a new IAMPolicyCondition. | ||
func (in *IAMPolicyCondition) DeepCopy() *IAMPolicyCondition { | ||
if in == nil { | ||
return nil | ||
} | ||
out := new(AWSProviderSpec) | ||
out := new(IAMPolicyCondition) | ||
in.DeepCopyInto(out) | ||
return out | ||
} | ||
|
||
// DeepCopyObject will return a DeepCopied AWSProviderSpec | ||
// as a runtime.Object | ||
func (in *AWSProviderSpec) DeepCopyObject() runtime.Object { | ||
if c := in.DeepCopy(); c != nil { | ||
return c | ||
// DeepCopyInto is a deepcopy function, copying the receiver, writing into out. in must be non-nil. | ||
func (in *IAMPolicyCondition) DeepCopyInto(out *IAMPolicyCondition) { | ||
if *in == nil { | ||
return | ||
} | ||
return nil | ||
} | ||
|
||
func deepCopyIAMPolicyCondition(ipc IAMPolicyCondition) IAMPolicyCondition { | ||
cp := make(IAMPolicyCondition) | ||
for key, val := range ipc { | ||
*out = make(IAMPolicyCondition, len(*in)) | ||
tgt := *out | ||
|
||
for key, val := range *in { | ||
if val != nil { | ||
cp[key] = make(IAMPolicyConditionKeyValue) | ||
tgt[key] = make(IAMPolicyConditionKeyValue, len(val)) | ||
for subKey, subVal := range val { | ||
cp[key][subKey] = subVal | ||
tgt[key][subKey] = copyStringOrStringSlice(subVal) | ||
} | ||
} | ||
} | ||
|
||
return cp | ||
} | ||
|
||
// DeepCopyInto will perform a DeepCopy into the provided StatementEntry | ||
func (in *StatementEntry) DeepCopyInto(out *StatementEntry) { | ||
*out = *in | ||
if in.Action != nil { | ||
in, out := &in.Action, &out.Action | ||
*out = make([]string, len(*in)) | ||
copy(*out, *in) | ||
func copyStringOrStringSlice(from interface{}) interface{} { | ||
var to interface{} | ||
|
||
switch v := from.(type) { | ||
case string: | ||
// simple assignment creates copy | ||
to = from | ||
case []string: | ||
toSlice := make([]string, len(v)) | ||
copy(toSlice, v) | ||
to = toSlice | ||
default: | ||
// unexpected type, this could mean we're not | ||
// doing a deepcopy | ||
to = from | ||
} | ||
if in.PolicyCondition != nil { | ||
out.PolicyCondition = deepCopyIAMPolicyCondition(in.PolicyCondition) | ||
} | ||
|
||
return | ||
} | ||
|
||
// DeepCopy will DeepCopy and return a pointer to a | ||
// new StatementEntry | ||
func (in *StatementEntry) DeepCopy() *StatementEntry { | ||
if in == nil { | ||
return nil | ||
} | ||
out := new(StatementEntry) | ||
in.DeepCopyInto(out) | ||
return out | ||
return to | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.