Skip to content
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

Deep copy gen generates invalid code if struct has an _ field #133

Closed
cholman-zd opened this issue Jan 17, 2019 · 13 comments
Closed

Deep copy gen generates invalid code if struct has an _ field #133

cholman-zd opened this issue Jan 17, 2019 · 13 comments
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@cholman-zd
Copy link

Running deepcopy-gen against structs that have _ fields in them generates invalid go code.

Source struct:

type CreateBucketConfiguration struct {
	_ struct{} `type:"structure"`

	LocationConstraint BucketLocationConstraint `type:"string" enum:"true"`
}
type BucketLocationConstraint string

doc.go directives to deepcopy:

// +k8s:deepcopy-gen=package,register

deepcopy directives above structs that the above struct is a child of (not sure if this makes a difference or not - this is autogenerated code from the operator sdk)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Output by deepcopy-gen:

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CreateBucketConfiguration) DeepCopyInto(out *CreateBucketConfiguration) {
	*out = *in
	out._ = in._
	return
}

Setting or accessing _ fields is invalid.

I applied the following patch locally and it outputs correct code (ie does not attempt to copy the _ field). No idea if this is the correct way to solve the problem though.

diff --git a/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy.go b/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy.go
index 4548108..1d90578 100644
--- a/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy.go
+++ b/vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy.go
@@ -823,6 +823,9 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {

 	// Now fix-up fields as needed.
 	for _, m := range ut.Members {
+		if m.Name == "_" {
+			continue
+		}
 		ft := m.Type
 		uft := underlyingType(ft)

After applying this patch, output is as expected:

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *CreateBucketConfiguration) DeepCopyInto(out *CreateBucketConfiguration) {
	*out = *in
	return
}
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 18, 2019
@cholman-zd
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 21, 2019
@cholman-zd
Copy link
Author

There is an open PR #134 to fix this and it would be great if someone could help get that merged and applied.

@lavalamp
Copy link
Member

lavalamp commented Apr 22, 2019 via email

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 21, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 20, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@lavalamp
Copy link
Member

lavalamp commented Sep 19, 2019 via email

@k8s-ci-robot
Copy link
Contributor

@lavalamp: Reopened this issue.

In response to this:

/reopen
/lifecycle frozen

On Thu, Sep 19, 2019 at 10:55 AM Kubernetes Prow Robot <
[email protected]> wrote:

@fejta-bot https://github.com/fejta-bot: Closing this issue.

In response to this
#133 (comment):

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta
https://github.com/fejta.
/close

Instructions for interacting with me using PR comments are available here
https://git.k8s.io/community/contributors/guide/pull-requests.md. If
you have questions or suggestions related to my behavior, please file an
issue against the kubernetes/test-infra
https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:
repository.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#133,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAE6BFWX3W3QOQ3G7E4ZLILQKO4JHANCNFSM4GQ3Z7GQ
.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot reopened this Sep 19, 2019
@k8s-ci-robot k8s-ci-robot added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Sep 19, 2019
@grim-fendango
Copy link

/reopen
/lifecycle frozen

@thockin
Copy link
Member

thockin commented Jan 28, 2024

gengo/v2 (#259) moves deepcopy-gen to k8s.io/code-generator.

@thockin
Copy link
Member

thockin commented Mar 10, 2024

@thockin thockin closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

No branches or pull requests

6 participants