Add port-conflict diagnose suite
What does this PR do?
Add a diagnose suite to check issues around port conflicts.
Motivation
This is a common issue for users, at best a log can indicate that we couldn't bind to some address but finding it and fixing it might be hard. Having a diagnose suite which automatically finds ports in the config and tells you whether they are unused, used by the agent, or used by some other process, can help with that.
Additional Notes
The code in pkg/util/port is copied from https://github.com/tailscale/tailscale/tree/main, it can be simplified and reduced a lot eventually, but for now using it as is simpler.
It was copied in the agent repo because I had to make minor changes to be able to use it, and at some point I'd like to refactor it a lot more.
Possible Drawbacks / Trade-offs
The library that was copied to get port/process information has a native implementation on Linux, but uses netstat and lsof on Windows and Darwin. We might need to re-implement these parts of the code natively at some point.
Describe how to test/QA your changes
Check that the diagnose suite works properly for Linux, Windows, and Darwin:
- when the agent isn't running and there is no port issue
- when the agent is running and there is no port issue (the agent is detected as being the agent, so no issue is raised)
- when some port is used by another process, it is reported
You can use netcat to bind to a port
netcat -nvlp 6062
Reviewer's Checklist
- [ ] If known, an appropriate milestone has been selected; otherwise the
Triagemilestone is set. - [ ] Use the
major_changelabel if your change either has a major impact on the code base, is impacting multiple teams or is changing important well-established internals of the Agent. This label will be use during QA to make sure each team pay extra attention to the changed behavior. For any customer facing change use a releasenote. - [ ] A release note has been added or the
changelog/no-changeloglabel has been applied. - [ ] Changed code has automated tests for its functionality.
- [ ] Adequate QA/testing plan information is provided if the
qa/skip-qalabel is not applied. - [ ] At least one
team/..label has been applied, indicating the team(s) that should QA this change. - [ ] If applicable, docs team has been notified or an issue has been opened on the documentation repo.
- [ ] If applicable, the
need-change/operatorandneed-change/helmlabels have been applied. - [ ] If applicable, the
k8s/<min-version>label, indicating the lowest Kubernetes version compatible with this feature. - [ ] If applicable, the config template has been updated.