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

Do not deepcopy, instance can be nil #1185

Merged
merged 2 commits into from
Dec 16, 2019
Merged

Do not deepcopy, instance can be nil #1185

merged 2 commits into from
Dec 16, 2019

Conversation

alenkacz
Copy link
Contributor

No description provided.

Copy link
Member

@nfnt nfnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't actually needed, DeepCopy() handles the case that instance is nil:

func (in *TestType) DeepCopy() *TestType {
	if in == nil {
		return nil
	}
	out := new(TestType)
	in.DeepCopyInto(out)
	return out
}

(neat Go trick btw)

@alenkacz
Copy link
Contributor Author

oh, goland was complaining... I would still probably prefer to merge this in even though it's not fixing anything. Might be handy for people (and IDEs) who don't know deepcopy implementation and might freak them out as it did freak out me :D

@nfnt
Copy link
Member

nfnt commented Dec 16, 2019

But instance might still be nil after calling getInstance when it isn't found.
Hmm, looks like the existing code is wrong here, becase the apierrors.IsNotFound isn't necessary or should be in a different place.

@alenkacz
Copy link
Contributor Author

omg yeah, you're right... I am starting to feel like we should get rid of these special getXX methods returning nil because it's just confusing, when it returns something different than k8s client. WDYT?

@nfnt
Copy link
Member

nfnt commented Dec 16, 2019

I'm fine with having helper functions.
Though, the code is actually right: getInstance doesn't do what's documented, it doesn't return nil, nil if an instance isn't found. Let's remove the wrong documentation comment.

Though there is similar code in pkg/kudoctl/util/kudo that returns nil, nil in that case. We should at least be consistent here, so that manager and CLI can share more code. #1002 is supposed to go in this direction and provide a KUDO API that could be used by the manager, the CLI and probably external projects as well.

@alenkacz
Copy link
Contributor Author

Oh I was questioning the fact of returning nil vs not found error - I think it's confusing if 10% of code does nil, the rest err, also you need to check for nil etc. anyway so the code does not get that much nicer. But then I see that I already changed it here #850 just did not update the docs :D

@kensipe kensipe merged commit ef07673 into master Dec 16, 2019
@kensipe kensipe deleted the av/deepcopy branch December 16, 2019 23:08
ANeumann82 pushed a commit that referenced this pull request Feb 13, 2020
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants