Merge "Fix host unlock when sriov-fec-operator is used"

This commit is contained in:
Zuul 2022-12-06 14:31:53 +00:00 committed by Gerrit Code Review
commit 7c3ac2b916
2 changed files with 56 additions and 0 deletions

View File

@ -3511,6 +3511,36 @@ class HostController(rest.RestController):
except TypeError:
sriov_numvfs = 0
# Get the custom resource of the SRIOV fec operator app.
# If fec operator is managing the device of the host,
# it updates the sriov parameters in sysfs.
# The expected_numvfs is not used. The checks below are skipped.
sriovfec_list = self._kube_operator.list_namespaced_custom_resources(
"sriovfec.intel.com",
"v2",
"sriov-fec-system",
"sriovfecclusterconfigs")
if sriovfec_list:
for sriovfec_crd in sriovfec_list:
if sriovfec_crd:
LOG.debug("sriovfec custom resource={}".format(sriovfec_crd))
spec = sriovfec_crd.get('spec', None)
if spec:
nodeselector = spec.get('nodeSelector', None)
hostname = nodeselector.get('kubernetes.io/hostname', None)
if hostname and hostname == host['hostname']:
accelerator_selector = spec.get('acceleratorSelector', None)
pci_address = accelerator_selector.get('pciAddress', None)
if pci_address == dev.pciaddr:
LOG.debug("Found device %s on host %s managed by "
"FEC operator" %
(dev.pciaddr, host['hostname']))
return
LOG.debug("Device %s on host %s not managed by FEC operator" %
(dev.pciaddr, host['hostname']))
else:
LOG.debug("No sriovfec custom resource found, continue")
if dev.extra_info:
extra_info = ast.literal_eval(dev.extra_info)
expected_numvfs = int(extra_info['expected_numvfs'])

View File

@ -664,6 +664,32 @@ class KubeOperator(object):
else:
return cr_obj_list.get("items")
def list_namespaced_custom_resources(self, group, version, namespace, plural,
pretty=False, label_selector="",
resource_version="", watch=False):
custom_resource_api = self._get_kubernetesclient_custom_objects()
try:
cr_obj_list = custom_resource_api.list_namespaced_custom_object(
group,
version,
namespace,
plural,
pretty=pretty,
label_selector=label_selector,
resource_version=resource_version,
watch=watch
)
except ApiException as e:
if e.status == httplib.NOT_FOUND:
return None
else:
LOG.error("Fail to list namespaced custom resources:%s. %s"
% (plural, e))
raise
else:
return cr_obj_list.get("items")
def get_custom_resource(self, group, version, namespace, plural, name):
custom_resource_api = self._get_kubernetesclient_custom_objects()