Open MuraliK7hpe opened 2 years ago
There are many other deprecations and issues. I tried to monkey patch the issue described above and got other errors of the same kind
I hit this error, pointing my tests' kubeconfig/context at a v1.21 k8s cluster.
TL;DR: How do I find the version of kubetest (and accompanying kubernetes client package) that officially supports kubernetes v1.21? Neither 0.9.5 nor 0.9.4 seem to fit the bill.
I have enabled debug logging, but do not see any output until the exception is hit (expand excerpt below for detail).
I can talk to this cluster just fine using kubectl. Since my cluster is using v1.21, perhaps my setup is trying to use a newer Api version? Is a way to specify the Api version that kubetest's client should use? I haven't found anything in the kubetest docs about this, and assume that it automatically detects the k8s version.
My test itself is trivial. Since it's failing before ever loading my test, I believe my test code is irrelevant.
I'm using python 3.9 and kubetest 0.9.5 on Debian 11 and the following python package versions installed via poetry:
@MuraliK7hpe @tyxeron, it appears that the kubetest client object wrapping clusterrolebinding has a list of api versions, with specification for a "preferred" one:
class ClusterRoleBinding(ApiObject):
<snip>
api_clients = {
"preferred": client.RbacAuthorizationV1Api,
"rbac.authorization.k8s.io/v1": client.RbacAuthorizationV1Api,
"rbac.authorization.k8s.io/v1alpha1": client.RbacAuthorizationV1alpha1Api,
"rbac.authorization.k8s.io/v1beta1": client.RbacAuthorizationV1beta1Api,
}
Could there be a problem with this "preferred" mechanism? Why would we be getting this error if the client chose the preferred version first, i.e. rbac.authorization.k8s.io/v1
?
EDIT: I found this description in the ApiObject.api_client comment:
A mapping of all the supported api clients for the API object type. Various resources can have multiple versions, e.g. "apps/v1", "apps/v1beta1", etc. The preferred version for each resource type should be defined under the "preferred" key. The preferred API client will be used when the apiVersion is not specified for the resource.
This all appears to be the case for all the api objects in kubetest. I suspect we're just hitting clusterrolebinding first bc it's the first to be imported in the objects package.
For a second, I thought that these client api objects were choosing v1alpha1 because I have that specified in my kubeconfig file. I'm using EKS, and the aws eks update-kubeconfig
command to generate the kubeconfig for me. In the generated file, it specifies to use v1alpha1
in the command to fetch the auth token for the generated user:
However, I'm still getting the same kubetest exception after changing the user-exec apiVersion in my kubeconfig file to v1. :-(
In fact, changing this api version in my kubeconfig also breaks kubectl. It appears that this api version is the only one supported in my cluster for the initial fetch of api versions that kubectl does:
error: couldn't get available api versions from server: Get "https://blahblahblah.eks.amazonaws.com/api?timeout=32s": getting credentials: exec plugin is configured to use API version client.authentication.k8s.io/v1beta1, plugin returned version client.authentication.k8s.io/v1alpha1
My cluster is v1.21, which supports the following api versions per-resource:
So, it appears that my cluster supports rbac.authorization.k8s.io api version v1 and v1beta1, but not v1alpha1.
I'm really confused about why kubetest is failing to access my v1.21 cluster.
OK, wading my way through this, I see:
RbacAuthorizationV1alpha1Api
member.RbacAuthorizationV1Api
and no beta/alpha versions. THIS!So, I think what's needed in my case is to downgrade the kubernetes package on my system.
EDIT: Ugh, I see that I cannot simply downgrade kubernetes client package because it is being installed as a dependency of kubetest. I will instead downgrade kubetest itself until I get a previous version of the kubernetes client that supports RbacAuthorizationV1alpha1Api.
Removing kubetest and reinstalling kubetest pinned to 0.9.4 and kubernetes pinned to 21.7.0 (the most recent version that appears to include v1alpha/beta1), I run into similar issue in DaemonSet Api versioning:
File "/home/tim/.cache/pypoetry/virtualenvs/ps-wheel-infrastructure--Poruhia-py3.9/lib/python3.9/site-packages/kubetest/objects/daemonset.py", line 17, in <module>
class DaemonSet(ApiObject):
File "/home/tim/.cache/pypoetry/virtualenvs/ps-wheel-infrastructure--Poruhia-py3.9/lib/python3.9/site-packages/kubetest/objects/daemonset.py", line 35, in DaemonSet
"apps/v1beta1": client.AppsV1beta1Api,
AttributeError: module 'kubernetes.client' has no attribute 'AppsV1beta1Api'
I believe this is what @tyxeron was referring to.
How do I find the version of kubetest (and accompanying kubernetes client package) that officially supports kubernetes v1.21?
kubetest fails to run in latest version on K8s and following is the error observed
File "/usr/local/lib/python3.6/site-packages/kubetest/objects/clusterrolebinding.py", line 12, in
class ClusterRoleBinding(ApiObject):
File "/usr/local/lib/python3.6/site-packages/kubetest/objects/clusterrolebinding.py", line 30, in ClusterRoleBinding
'rbac.authorization.k8s.io/v1alpha1': client.RbacAuthorizationV1alpha1Api,
AttributeError: module 'kubernetes.client' has no attribute 'RbacAuthorizationV1alpha1Api'
Refer to K8s page: https://kubernetes.io/docs/reference/using-api/deprecation-guide/
RBAC resources The rbac.authorization.k8s.io/v1beta1 API version of ClusterRole, ClusterRoleBinding, Role, and RoleBinding is no longer served as of v1.22.
Migrate manifests and API clients to use the rbac.authorization.k8s.io/v1 API version, available since v1.8. All existing persisted objects are accessible via the new APIs No notable changes