Skip to content

Add events command #195

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

Merged
merged 4 commits into from
Feb 9, 2025
Merged

Add events command #195

merged 4 commits into from
Feb 9, 2025

Conversation

clarku
Copy link
Contributor

@clarku clarku commented Jan 18, 2025

This PR adds the omc events command. Closes #183 .

I implemented the command from scratch as it didn't seem possible to directly port it from oc events. That being said, I've kept the same behaviour wherever possible.

Notes about the implementation:

  • Getting the timestamp for the LAST SEEN column uses the same logic as omc get. Specifically, it will use .lastTimestamp with .metadata.creationTimestamp as a fallback.
  • Events are automatically sorted using the same timestamp.
  • KindGroupNamespaced() from get/helpers.go now returns singular resource name and is exportable so that it can be used to determine the correct resource when using --for.

This is useful when the kind name (e.g Pod) instead of the resource name (e.g pods) is needed.
@oarribas
Copy link

@clarku , will this also replace the omc get events behavior? or will only work for a new omc events sub-command? I'm asking because I see some few changes also in the get code, but not sure about the behavior.

@clarku
Copy link
Contributor Author

clarku commented Feb 6, 2025

Hi @oarribas, this PR shouldn't make any changes to the behaviour of the omc get events command and is only for a new omc events command.

To be more specific, the changes to the get command code were to make the --for argument work as I noted earlier.

KindGroupNamespaced() from get/helpers.go now returns singular resource name and is exportable so that it can be used to determine the correct resource when using --for.

I'll provide further information on this.

For the omc events command, the --for argument will filter events for a named resource and will be in the format kind/name. For example, using the command

omc events --for pod/test

will filter for a resource with a kind of "pod" which has the name of "test". One part of getting this to work is that the user's inputted kind (pod, in this case) will need to be compared to the kind found in the event. This is complicated by the fact that the input kind can be specified in multiple formats such as singular (pod), plural (pods), or short name (po). This means that the input kind will need to be converted before it can be compared to the event. The aforementioned KindGroupNamespaced function can be used for this conversion but a new return value had to be added so that it would return the kind (which is singular).

@gmeghnag gmeghnag merged commit 0de13a9 into gmeghnag:main Feb 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

omc events ?
3 participants