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

[JENKINS-74992] Avoid NPE on informers #1630

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public class KubernetesCloud extends Cloud implements PodTemplateGroup {
* namespace -> informer
* Use to watch pod events per namespace.
*/
private transient Map<String, SharedIndexInformer<Pod>> informers = new ConcurrentHashMap<>();
private transient volatile Map<String, SharedIndexInformer<Pod>> informers = new ConcurrentHashMap<>();

@DataBoundConstructor
public KubernetesCloud(String name) {
Expand Down Expand Up @@ -1306,9 +1306,6 @@ private Object readResolve() {
if (containerCap != null && containerCap == 0) {
containerCap = null;
}
if (informers == null) {
informers = new ConcurrentHashMap<>();
}
return this;
}

Expand All @@ -1321,6 +1318,15 @@ public Cloud reconfigure(@NonNull StaplerRequest req, JSONObject form) throws De
}

public void registerPodInformer(KubernetesSlave node) {
// even having readResolve initializing informers is not enough, there are some special cases where XStream will
// not call it, so let us make sure it is initialized before using
if (informers == null) {
synchronized (this) {
if (informers == null) {
informers = new ConcurrentHashMap<>();
}
}
}
informers.computeIfAbsent(node.getNamespace(), (n) -> {
KubernetesClient client;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ private String formatPodStatus(PodCondition c, String phase, StringBuilder sb) {
// not interesting
return "";
}
String formatted = String.format("%n\tPod [%s][%s] %s", phase, c.getReason(), c.getMessage());
String message = c.getMessage();
String formatted =
String.format("%n\tPod [%s][%s] %s", phase, c.getReason(), message != null ? message : "No message");
Comment on lines +53 to +55
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated, but I just saw it during testing and thought it would be ok to slip it here :)

return sb.indexOf(formatted) == -1 ? formatted : "";
}

Expand Down
Loading