-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
openshift inventory plugin: fix exception when auth fails #45826
openshift inventory plugin: fix exception when auth fails #45826
Conversation
I'd rather not use (would be good to have a helper function to do that, I want to make the same change in k8s/raw.py too) |
9152b23
to
065bf81
Compare
Done. Note that we loose the original backtrace. Once merged, I will ask if backports (2.7 and 2.6) are allowed (if so, i will create backport PRs) and create another PR in order to use |
15af713
to
e804f24
Compare
Fix 'ForbiddenError' object has no attribute 'message': [WARNING]: * Failed to parse test.yml with openshift plugin: 'ForbiddenError' object has no attribute 'message' File "ansible/lib/ansible/inventory/manager.py", line 270, in parse_source plugin.parse(self._inventory, self._loader, source, cache=cache) File "ansible/lib/ansible/plugins/inventory/openshift.py", line 122, in parse self.setup(config_data, cache, cache_key) File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 58, in setup self.fetch_objects(connections) File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 250, in fetch_objects super(OpenShiftInventoryHelper, self).fetch_objects(connections) File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 81, in fetch_objects namespaces = self.get_available_namespaces(client) File "ansible/lib/ansible/module_utils/k8s/inventory.py", line 95, in get_available_namespaces raise K8sInventoryException('Error fetching Namespace list: {0}'.format(exc.message)) Don't try to get 'message' attribute from: - K8sInventoryException instances - Exception instances - KubernetesException instances (because KubernetesException can be Exception)
e804f24
to
9d06668
Compare
@pilou- that looks great. I'm not clear why we lose the backtrace though, and if there's anything we can do to get it back (is it just that it was part of e.message?) We can presumably use the |
inventory plugin specific code should not be located in lib/ansible/module_utils directory. Then ansible.utils methods can be reused (for example Display).
About the traceback: it is not possible to use something like Now |
cache_key = self._get_cache_prefix(path) | ||
config_data = self._read_config_data(path) | ||
self.setup(config_data, cache, cache_key) | ||
helper = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused since 4d77878.
NAME = 'k8s' | ||
|
||
transport = 'kubectl' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? kubectl is not used at all by ansible, afaik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt' add it, it comes from:
transport = 'kubectl' |
It is used there in order to define connection plugin (kubectl
or oc
) which will be used with the generated inventory:
ansible/lib/ansible/module_utils/k8s/inventory.py
Lines 161 to 167 in f73996e
self.inventory.set_variable(container_name, 'ansible_connection', self.transport) | |
self.inventory.set_variable(container_name, 'ansible_{0}_pod'.format(self.transport), | |
pod_name) | |
self.inventory.set_variable(container_name, 'ansible_{0}_container'.format(self.transport), | |
container.name) | |
self.inventory.set_variable(container_name, 'ansible_{0}_namespace'.format(self.transport), | |
namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kubectl
is a valid connection plugin, without looking into the code further I assume that's being used as the transport backend in that inventory plugin.
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/connection/kubectl.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, ansible_connection
selects the connection plugin :)
bot_status |
Componentslib/ansible/module_utils/k8s/common.py lib/ansible/module_utils/k8s/inventory.py lib/ansible/module_utils/k8s/scale.py lib/ansible/plugins/inventory/k8s.py lib/ansible/plugins/inventory/openshift.py Metadatawaiting_on: maintainer |
shipit |
rebuild_merge |
SUMMARY
Fix
ForbiddenError
object has no attributemessage
:Don't try to get
message
attribute from:K8sInventoryException
instancesException
instancesKubernetesException
instances (becauseKubernetesException
can beException
)ISSUE TYPE
COMPONENT NAME
lib/ansible/plugins/inventory/openshift.py
ANSIBLE VERSION