Fix labels encode
If more than one label is applied in the 'labelSelector' the result retrieved from the query corresponds only to the first label in the lists of labels, since K8S API do not recognize the '&' applied when the labels are anded in the encode. This commit fix the issue by replacing with ','. Change-Id: I5c2154f399667cd3a7acc4925e78ebd32bfb591a Closes-Bug: 1806911 Partially Implements: blueprint k8s-network-policies
This commit is contained in:
parent
85db5353a2
commit
a2085717a3
|
@ -189,6 +189,9 @@ class NetworkPolicyDriver(base.NetworkPolicyDriver):
|
|||
cidrs = []
|
||||
namespace_label = urlencode(namespace_selector[
|
||||
'matchLabels'])
|
||||
# NOTE(maysams): K8s API does not accept &, so we need to replace
|
||||
# it with ',' or '%2C' instead
|
||||
namespace_label = namespace_label.replace('&', ',')
|
||||
matching_namespaces = self.kubernetes.get(
|
||||
'{}/namespaces?labelSelector={}'.format(
|
||||
constants.K8S_API_BASE, namespace_label)).get('items')
|
||||
|
|
|
@ -34,6 +34,9 @@ def _get_kuryrnetpolicy_crds(labels=None, namespace='default'):
|
|||
labels.pop('pod-template-hash', None)
|
||||
# removing pod-template-hash is necessary to fetch the proper list
|
||||
labels = urlencode(labels)
|
||||
# NOTE(maysams): K8s API does not accept &, so we need to replace
|
||||
# it with ',' or '%2C' instead
|
||||
labels = labels.replace('&', ',')
|
||||
knp_path = '{}/{}/kuryrnetpolicies?labelSelector={}'.format(
|
||||
constants.K8S_API_CRD_NAMESPACES, namespace, labels)
|
||||
LOG.debug("K8s API Query %s", knp_path)
|
||||
|
|
Loading…
Reference in New Issue