Fix KubernetesSlave NPE on getting Workspace after Jenkins Master Restart #446
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.
@carlossg Thanks a lot for your work on the kubernetes-plugin, it is greatly appreciated! 馃檪 Could you please let me know your thoughts on this?
How to reproduce the issue
Kubernetes-plugin 1.14.9
Jenkins LTS 2.164.1
Root cause
When fetching a Workspace for a Job we get a null value that triggers the aforementioned error. If we go deep on how Jenkins fetch the Workspace root path for Slaves, Jenkins queries a Map with Computers and KubernetesSlave (Node) is a key for such Map.
When Jenkins restarts and the agent gets reconnected that Map is re-instantiated, the KubernetesSlave instance is one of the keys but it is not equals() and has a different hashCode(). They differ on the template private field given that PodTemplate does not implements an equals()/hashCode().
Proposed Fix
Perhaps it is reasonable to assume that if agents have the same name they are the same independently of the PodTemplate definition. I have changed both equals() and hasCode() for KubernetesSlave in tune with that.
An alternative would be to implement equals()/hashCode() on the PodTemplate, let me know if you would like me to do it that way instead.