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

k8s_cluster_info.py Add warn for resorce missing kind field #795

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions plugins/modules/k8s_cluster_info.py
Copy link
Member

Choose a reason for hiding this comment

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

Have you found a particular case where there's an error? As far as I'm aware this shouldn't be necessary. The check should already be happening in https://github.com/kubernetes-client/python/blob/07fb11f2bc6a6356854e9dabcd7d65a62e849feb/kubernetes/base/dynamic/resource.py#L29

Copy link
Author

Choose a reason for hiding this comment

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

yes; specifically i ran into this while using kiali-operator: https://github.com/kiali/kiali-operator/blob/master/roles/default/kiali-deploy/tasks/main.yml#L23

But i imagine it's generally a good idea to check/warn for exception as it is used in many places. In general, cluster api should almost always have kind field but for whatever reason I have one k8 cluster where it failed.

Copy link
Member

Choose a reason for hiding this comment

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

Can you reproduce the error? I'm not opposed to adding a check if it's necessary, but it doesn't look to me like your change would fix that problem.

Copy link
Author

@AnthonyWC AnthonyWC Nov 19, 2024

Choose a reason for hiding this comment

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

My change isn't meant to fix the error but to warn on which resource caused the error. The fix should be applied on kubernetes api side (on specific resource).

Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def execute_module(module, client):
if resource.group == ""
else "/".join([resource.group, resource.group_version.split("/")[-1]])
)

kind = getattr(resource, "kind", None)
if not kind:
module.warn(f"Resource is missing 'kind': {resource}")
continue

results[key][resource.kind] = {
"categories": resource.categories if resource.categories else [],
"name": resource.name,
Expand Down