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

Set node_name to hostname if NODE_NAME envvar is not found #2123

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

lambdanis
Copy link
Contributor

@lambdanis lambdanis commented Feb 19, 2024

This enables node_name field in the standalone (non-k8s) mode.

Set events node_name field to the hostname in the standalone (non-k8s) mode.

@lambdanis lambdanis added kind/bug Something isn't working release-note/bug This PR fixes an issue in a previous release of Tetragon. labels Feb 19, 2024
Copy link
Member

@tixxdz tixxdz left a comment

Choose a reason for hiding this comment

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

LGTM minor comments on caching, errors, fixing tests and maybe add test to ensure that it returns /proc/sys/kernel/hostname if no envs are set.

}
return os.Getenv("NODE_NAME")
if nodeName == "" {
nodeName, _ = os.Hostname()
Copy link
Member

Choose a reason for hiding this comment

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

l would cache this using a read once just to avoid extra calls in a global environment to be consistent too with k8s. The hostname may change during runtime but I don't think we care. cc @jrfastab

Also we need to report an error here if os.Hostname() fails for some reasons! and maybe use the old utsname but you have to convert then the output from int8 to byte then strings ... a bit complicated. the Hostname() seems to call explicitly /proc at this location where we may have it configured --procfs but this is an extreme case, so up to you, just warning on Hostname() errors should be enough.

Thank you @lambdanis

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I added a warning log.

@lambdanis lambdanis force-pushed the pr/lambdanis/hostname branch from f5657ad to 40f1937 Compare February 19, 2024 19:18
@lambdanis lambdanis marked this pull request as ready for review February 19, 2024 19:19
@lambdanis lambdanis requested a review from a team as a code owner February 19, 2024 19:19
@lambdanis lambdanis requested a review from jrfastab February 19, 2024 19:19
@lambdanis lambdanis changed the title Use hostname as node_name if NODE_NAME envvar is not found Set node_name to hostname if NODE_NAME envvar is not found Feb 19, 2024
@lambdanis lambdanis force-pushed the pr/lambdanis/hostname branch from 40f1937 to d803ecb Compare February 20, 2024 12:18
pkg/reader/node/node.go Outdated Show resolved Hide resolved
@lambdanis lambdanis force-pushed the pr/lambdanis/hostname branch from d803ecb to 1e77057 Compare February 20, 2024 14:25
This enables node_name field in the standalone (non-k8s) mode.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
@lambdanis lambdanis force-pushed the pr/lambdanis/hostname branch from 1e77057 to 2087f7e Compare February 20, 2024 15:48
@lambdanis
Copy link
Contributor Author

Ok, merging it, the only CI failure is the known #2010

@lambdanis lambdanis merged commit b2540c9 into cilium:main Feb 20, 2024
30 of 31 checks passed
@lambdanis lambdanis added the area/userspace Related to userspace Tetragon logic label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/userspace Related to userspace Tetragon logic kind/bug Something isn't working release-note/bug This PR fixes an issue in a previous release of Tetragon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants