-
Notifications
You must be signed in to change notification settings - Fork 160
restore DeepCopy generation #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 2 commits into
openshift:master
from
joelddiaz:rawextension-aws-conditions
Jun 25, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| set -x | ||
|
|
||
| # set the passed in directory as a usable GOPATH | ||
| # that deepcopy-gen can operate in | ||
| ensure-temp-gopath() { | ||
| fake_gopath=$1 | ||
|
|
||
| # set up symlink pointing to our repo root | ||
| fake_repopath=$fake_gopath/src/github.com/openshift/cloud-credential-operator | ||
| mkdir -p "$(dirname "${fake_repopath}")" | ||
| ln -s "$REPO_FULL_PATH" "${fake_repopath}" | ||
| } | ||
|
|
||
| SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. | ||
| REPO_FULL_PATH=$(realpath ${SCRIPT_ROOT}) | ||
| cd ${REPO_FULL_PATH} | ||
|
|
||
| CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../../../k8s.io/code-generator)} | ||
|
|
||
| verify="${VERIFY:-}" | ||
|
|
||
| valid_gopath=$(realpath $REPO_FULL_PATH/../../../..) | ||
| if [[ "$(realpath ${valid_gopath}/src/github.com/openshift/cloud-credential-operator)" == "${REPO_FULL_PATH}" ]]; then | ||
| temp_gopath=${valid_gopath} | ||
| else | ||
| TMP_DIR=$(mktemp -d -t cloud-credential-operator-codegen.XXXX) | ||
| function finish { | ||
| chmod -R +w ${TMP_DIR} | ||
| # ok b/c we will symlink to the original repo | ||
| rm -r ${TMP_DIR} | ||
| } | ||
| trap finish EXIT | ||
|
|
||
| ensure-temp-gopath ${TMP_DIR} | ||
|
|
||
| temp_gopath=${TMP_DIR} | ||
| fi | ||
|
|
||
| GOPATH="${temp_gopath}" GOFLAGS="" bash ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \ | ||
| github.com/openshift/cloud-credential-operator/pkg/client \ | ||
| github.com/openshift/cloud-credential-operator/pkg/apis \ | ||
| "cloudcredential:v1" \ | ||
| --go-header-file ${REPO_FULL_PATH}/hack/boilerplate.go.txt \ | ||
| ${verify} | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/bash | ||
|
|
||
| SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. | ||
| VERIFY=--verify-only ${SCRIPT_ROOT}/hack/update-codegen.sh |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| 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 { | ||
| if in == nil { | ||
| return nil | ||
| } | ||
| out := new(AWSProviderSpec) | ||
| 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 | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func deepCopyIAMPolicyCondition(ipc IAMPolicyCondition) IAMPolicyCondition { | ||
| cp := make(IAMPolicyCondition) | ||
| for key, val := range ipc { | ||
| if val != nil { | ||
| cp[key] = make(IAMPolicyConditionKeyValue) | ||
| for subKey, subVal := range val { | ||
| cp[key][subKey] = 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) | ||
| } | ||
| 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 | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package v1 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestAWSProviderSpecDeepCopy(t *testing.T) { | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| providerSpec *AWSProviderSpec | ||
| }{ | ||
| { | ||
| name: "basic provider spec", | ||
| providerSpec: &AWSProviderSpec{ | ||
| StatementEntries: []StatementEntry{ | ||
| { | ||
| Effect: "Allow", | ||
| Action: []string{ | ||
| "iam:Action1", | ||
| "iam:Action2", | ||
| }, | ||
| Resource: "*", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "with conditions", | ||
| providerSpec: &AWSProviderSpec{ | ||
| StatementEntries: []StatementEntry{ | ||
| { | ||
| Effect: "Allow", | ||
| Action: []string{ | ||
| "iam:Action1", | ||
| "iam:Action2", | ||
| }, | ||
| Resource: "*", | ||
| PolicyCondition: IAMPolicyCondition{ | ||
| "StringEquals": IAMPolicyConditionKeyValue{ | ||
| "aws:userid": "testuser", | ||
| }, | ||
| "StringNotEquals": IAMPolicyConditionKeyValue{ | ||
| "aws:SourceVpc": "vpc-12345", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "nil provider spec", | ||
| providerSpec: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| dCopy := test.providerSpec.DeepCopy() | ||
| assert.Equal(t, test.providerSpec, dCopy, "expected the DeepCopy() results to be deeply equal") | ||
|
|
||
| if test.providerSpec != nil { | ||
| newAWSProviderSpec := &AWSProviderSpec{} | ||
| test.providerSpec.DeepCopyInto(newAWSProviderSpec) | ||
| assert.Equal(t, test.providerSpec, newAWSProviderSpec, "expected the DeepCopyInto() results to be deeply equal") | ||
|
|
||
| dCopyObject := test.providerSpec.DeepCopyObject() | ||
| testProviderSpecObject := runtime.Object(test.providerSpec) | ||
| assert.Equal(t, testProviderSpecObject, dCopyObject, "expected the DeepCopyObject() results to be equal") | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason you don't just always do the fake go path? It seems to me that there's less chance to have issues with other things in the real gopath if you do have one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was an optimization suggested by @staebler so that we wouldn't have to wait for the various pieces to be downloaded to the GOPATH if your usable GOPATH already had them in there. Works out that the TMP_DIR holds around 174MB of data on disk.
I'll un-WIP and squash some things up and reduce the verbosity of the deepcopy generation in a moment.