Skip to content

Commit

Permalink
Add check to ensure CRDs are in place
Browse files Browse the repository at this point in the history
Signed-off-by: Salvatore Daniele <[email protected]>
  • Loading branch information
SalDaniele committed Jun 24, 2024
1 parent 42417d3 commit ea031b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extraConfigSriov.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def _sno_make_deploy(
break

# Future proof for when sriov moves to new switchdev implementation: https://github.com/k8snetworkplumbingwg/sriov-network-operator/blob/master/doc/design/switchdev-refactoring.md
client.wait_for_crd(name="default", cr_name="sriovoperatorconfig", namespace="openshift-sriov-network-operator")
client.oc("apply -f manifests/nicmode/sriov-operator-config.yaml")


Expand Down Expand Up @@ -152,8 +153,8 @@ def ExtraConfigSriovSubscription(cc: ClustersConfig, cfg: ExtraConfigArgs, futur
client.oc("create -f manifests/nicmode/sriov-operator-group.yaml")
client.oc("create -f manifests/nicmode/sriov-subscription.yaml")

client.wait_for_crd(name="default", cr_name="sriovoperatorconfig", namespace="openshift-sriov-network-operator")
client.oc("apply -f manifests/nicmode/sriov-operator-config.yaml")

_check_sriov_installed(client)


Expand Down
13 changes: 13 additions & 0 deletions k8sClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,16 @@ def wait_for_mcp(self, mcp_name: str, resource: str = "resource") -> None:
time.sleep(60)
minutes, seconds = divmod(int(time.time() - start), 60)
logger.info(f"It took {minutes}m {seconds}s for {resource} (attempts: {iteration})")


def wait_for_crd(self, name: str, cr_name: str, namespace: str) -> None:
logger.info(f"Waiting for crd {cr_name} to become available")
ret = self.oc(f"get {cr_name}/{name} -n {namespace}")
retries = 10
while ret.returncode != 0:
time.sleep(10)
ret = self.oc(f"get {cr_name}/{name} -n {namespace}")
retries -= 1
if retries <= 0:
logger.error_and_exit(f"Failed to get cr {cr_name}/{name}")

0 comments on commit ea031b8

Please sign in to comment.