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] Print relevant pod status changes in build logs #1627

Merged
merged 14 commits into from
Dec 18, 2024

Conversation

amuniz
Copy link
Member

@amuniz amuniz commented Dec 13, 2024

JENKINS-74992

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@amuniz amuniz requested a review from a team as a code owner December 13, 2024 12:35
@Vlatombe
Copy link
Member

Spotless issues

@amuniz amuniz requested a review from Vlatombe December 16, 2024 09:12
Copy link
Member

@Vlatombe Vlatombe left a comment

Choose a reason for hiding this comment

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

This is moving nicely!

* namespace -> informer
* Use to watch pod events per namespace.
*/
private transient Map<String, SharedIndexInformer<Pod>> informers = new ConcurrentHashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

Need to be careful on what would happen to these informers if/when a KubernetesCloud gets removed.

Copy link
Member Author

@amuniz amuniz Dec 16, 2024

Choose a reason for hiding this comment

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

AFAICT the informers map would be unreachable and it would be garbage collected, so the DefaultSharedIndexInformer would be collected too and with it the informerExecutor (each instance has an executor), so the resync would stop happening (I've checked it actually stops reporting events).

Comment on lines 152 to 153
// register a namespace informer (if not registered yet) to show relevant pod events in build logs
cloud.registerPodInformer(node, client, namespace);
Copy link
Member

@Vlatombe Vlatombe Dec 16, 2024

Choose a reason for hiding this comment

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

What would happen on controller restart ? Do we care about re-attaching existing nodes or do we only care about new nodes? I guess events are mostly relevant on agent initialization but just to be sure...

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I think once the pod is running and containers ready, these pod events are less interesting (actually there are usually no events until the pod is deleted).
IMO we can live without this, until it proves to be needed.

@Vlatombe Vlatombe added the enhancement Improvements label Dec 16, 2024
@Vlatombe
Copy link
Member

Worth backlinking #1167 & #1192

* Informer register logic moved to Kubernetes cloud
* Create a new client connection instead of reusing one
* Log the cloud name
@Vlatombe
Copy link
Member

Interactive testing:

Created Pod: kubernetes kubernetes-plugin-test/pp-46-hxh1j-ntnm0-j1f39
[PodInfo] kubernetes-plugin-test/pp-46-hxh1j-ntnm0-j1f39
	Container [maven] waiting [PodInitializing] No message
	Pod [Pending][ContainersNotInitialized] containers with incomplete status: [set-up-jenkins-agent]
	Pod [Pending][ContainersNotReady] containers with unready status: [maven]
	Pod [Pending][ContainersNotReady] containers with unready status: [maven]
[PodInfo] kubernetes-plugin-test/pp-46-hxh1j-ntnm0-j1f39
	Container [maven] waiting [PodInitializing] No message
	Pod [Pending][ContainersNotReady] containers with unready status: [maven]
	Pod [Pending][ContainersNotReady] containers with unready status: [maven]

I see same events multiple times, can we avoid them?

@amuniz
Copy link
Member Author

amuniz commented Dec 17, 2024

Those are pod conditions as they come from K8s, not really duplicated. I can try to implement some sort of equals and not print the repeated ones. I'll have a look.

@amuniz
Copy link
Member Author

amuniz commented Dec 17, 2024

The type is what's making them different. Output printing the condition.type:

[PodInfo] kubernetes-plugin-test/test-12-m8mct-w2wf0-hfd9m
	Container [jnlp] waiting [ContainerCreating] No message
	Container [shell] waiting [ContainerCreating] No message
	Pod [Pending][ContainersNotReady][Ready] containers with unready status: [shell jnlp]
	Pod [Pending][ContainersNotReady][ContainersReady] containers with unready status: [shell jnlp]

This is what the client library is giving us. I can try to make it up on our side by ignoring the type and not printing "duplicates".

@amuniz
Copy link
Member Author

amuniz commented Dec 17, 2024

Workaround applied. Output now:

Created Pod: kubernetes kubernetes-plugin-test/test-13-62tdj-khn15-ftdm3
[PodInfo] kubernetes-plugin-test/test-13-62tdj-khn15-ftdm3
	Container [jnlp] waiting [ContainerCreating] No message
	Container [shell] waiting [ContainerCreating] No message
	Pod [Pending][ContainersNotReady] containers with unready status: [shell jnlp]

@amuniz amuniz requested a review from Vlatombe December 18, 2024 15:16
@Vlatombe Vlatombe merged commit 1b39d4f into jenkinsci:master Dec 18, 2024
9 checks passed
@jglick
Copy link
Member

jglick commented Dec 18, 2024

The PR title is potentially misleading. This PR is only listing changes to values to some .status subfields. It is not printing “pod events” in the sense of

kubectl events --for pod/$name --watch

which would potentially print interesting things in various unusual configurations, for example if there are special controllers running that interact with the agent pod to do something, such as provision ephemeral volumes.

@amuniz amuniz changed the title [JENKINS-74992] Print relevant pod provisioning events in build logs [JENKINS-74992] Print relevant pod status changes in build logs Dec 19, 2024
@amuniz
Copy link
Member Author

amuniz commented Dec 19, 2024

OK. Title updated (here, in released notes and Jira).

@amuniz amuniz deleted the JENKINS-74992 branch December 19, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants