-
Notifications
You must be signed in to change notification settings - Fork 143
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 & k8s_info: Support Cluster Operator Info Gathering #869
Comments
Upon reflection, as this module is meant to return only the rest object, does it make sense to have another module. What I am asking for is the interpretation of the rest object, which, in my estimation should be logically in the |
I believe if it's a primarily openshift-specific feature, it would land in https://github.com/openshift/community.okd , however it could make sense to add a module/extend the k8s_info module to have more logic for handling the conditions since they are a pain to parse. I think if you wanted to go the community.okd route, you are pretty free to build whatever openshift-specific logic is the most helpful for the use case. For this repo it would need to be more generalized/have a use to the broader community as well. |
On further reflection and spending some time looking at this, I think the best thing may be to just add this functionality to this collection. It should be straightforward to do so. I believe all you will need to do is add a
ClusterOperator and your new function here:
After that, you should be able to call k8s_info like:
Can you also add a unit test for the new function? It can go in https://github.com/ansible-collections/kubernetes.core/blob/main/tests/unit/module_utils/test_waiter.py and you should be able to follow how it's done for the other resources. The changes are isolated and the new logic mostly covered by unit tests so I think it's ok if there's no integration test for it. |
thanks for the reply! I have tried to work through integration tests but I am not exactly sure how to mock out Cluster Operators in this situation. I have written some test integrations with my own openshift cluster but I am unsure how to make a test without a cluster to test against. If I have a kubeconfig and a working cluster, the integration test will run as expected. However, what I am struggling with is the assumption that I don't have an OpenShift cluster to test against. Normally I would have json files representing different states (one for both a healthy and an unhealthy cluster). However, I can't seem to dig up information on how to override a section of the module in order to reference the file instead of connecting to a cluster. I suppose the question is, is this even a valid approach? I am pretty sure k8s does not have ClusterOperators and therefor a standard integration test is not likely to work. I see that waiter is using pytest, so I will look more into this before speaking too much out of turn Thanks! |
You won't be able to write integration tests for this because, as you point out, k8s doesn't have ClusterOperators. We don't test this collection against openshift. In this case, I don't think we need an integration test, though, as what you're doing can be sufficiently covered by unit tests. You can look at
|
Thanks for the pointers. I have been able to construct something fairly simple. I have general questions. given that the predicates return simply true or false, if the situation is false, how would you know what is failing? As far as I can tell, you would catch the failure and then get the Is this a correct statement? If it is, does that mean the more general question of what is failing falls outside the scope of this collection? |
SUMMARY
During an OpenShift installation, one of the checks to see that the cluster is ready to proceed with configuration is to check to ensure that the Cluster Operators are in an
Available: True
Degraded: False
Progressing: False
state. While you can currently use thek8s_info
module to get a json response, the resulting json needs to be iterated over several times to get the appropriate status. This is convoluted and ugly trying to use Ansible's native abilities to parse and loop over JSON.This feature should have the option to return the individual states of all operators as well as the overall state of the cluster in a true/false format. If all the operators are
Available: True
Degraded: False
Progressing: False
then the overall state of the cluster should be trueISSUE TYPE
COMPONENT NAME
This is probably best placed in the
k8s_info
module.ADDITIONAL INFORMATION
The checking of the Cluster Operators is widely used to determine whether other automation against clusters should continue. It is also used for a broadly defined health check.
In python, a simple loop gets you the status of the individual operators. The json file below was gathered using the
k8s_info
module and dumped to disk for easier processingThe data structure of info is
The output obviously is just POC and looks like
I am happy to take on the work of a PR, if this type of feature would be acceptable
The text was updated successfully, but these errors were encountered: