Fix the exception of taint/untaint node operation in VIM

If Kubernetes node has images without tag and digest
("crictl images" shows <none>:<none>), taint/untaint node
operations in VIM(triggerd by host lock/unlock) that send
the requests to Kubernetes to read/patch node via python
Kubernetes client will raise this exception.
  "Invalid value for `names`, must not be `None`"

The exception is raised in python Kubernetes client but not
from kubernetes. The node is actually patched successfully.

Implement a workaround to replace V1ContainerImage.names
in the python Kubernetes in the python Kubernete client
to bypass the "none image" check.

This workaround should be removed if the proposed solutions
can be made in kubernetes or a workaround can be implemented
in containerd.
https://github.com/kubernetes/kubernetes/pull/79018
https://github.com/containerd/containerd/issues/4771

Closes-Bug: 1905481
Signed-off-by: Angie Wang <angie.wang@windriver.com>
Change-Id: I747b5309747007204033d8dc2a850d3f824ddc5d
This commit is contained in:
Angie Wang 2020-12-01 20:46:01 -05:00
parent f529a7e337
commit ab4b667f9a

View File

@ -5,6 +5,7 @@
#
import kubernetes
from kubernetes.client.models.v1_container_image import V1ContainerImage
from kubernetes.client.rest import ApiException
from six.moves import http_client as httplib
@ -14,6 +15,32 @@ from nfv_common.helpers import Result
DLOG = debug.debug_get_logger('nfv_plugins.nfvi_plugins.clients.kubernetes_client')
# https://github.com/kubernetes-client/python/issues/895
# If a container image contains no tag or digest, node
# related requests sent via python Kubernetes client will be
# returned with exception because python Kubernetes client
# deserializes the ContainerImage response from kube-apiserver
# and it fails the validation due to the empty image name.
#
# Implement this workaround to replace the V1ContainerImage.names
# in the python Kubernetes client to bypass the "none image"
# check because the error is not from kubernetes.
#
# This workaround should be removed if the proposed solutions
# can be made in kubernetes or a workaround can be implemented
# in containerd.
# https://github.com/kubernetes/kubernetes/pull/79018
# https://github.com/containerd/containerd/issues/4771
def names(self, names):
"""Monkey patch V1ContainerImage with this to set the names."""
self._names = names
# Replacing address of "names" in V1ContainerImage
# with the "names" defined above
V1ContainerImage.names = V1ContainerImage.names.setter(names)
def get_client():
kubernetes.config.load_kube_config('/etc/kubernetes/admin.conf')