Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing setup_kubernetes_cr exception #3658

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions paasta_tools/setup_kubernetes_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from typing import Sequence

import yaml
from kubernetes.client.exceptions import ApiException

from paasta_tools.cli.utils import LONG_RUNNING_INSTANCE_TYPE_HANDLERS
from paasta_tools.flink_tools import get_flink_ingress_url_root
Expand Down Expand Up @@ -154,6 +155,7 @@ def setup_all_custom_resources(
) -> bool:

got_results = False
succeeded = False
# We support two versions due to our upgrade to 1.22
# this functions runs succefully when any of the two apiextensions
# succeed to update the CRDs as the cluster could be in any version
Expand All @@ -162,12 +164,18 @@ def setup_all_custom_resources(
kube_client.apiextensions,
kube_client.apiextensions_v1_beta1,
]:
cluster_crds = {
crd.spec.names.kind
for crd in apiextension.list_custom_resource_definition(

try:
crds_list = apiextension.list_custom_resource_definition(
label_selector=paasta_prefixed("service")
).items
}
except ApiException:
log.debug(
"Listing CRDs with apiextensions/v1 not supported on this cluster, falling back to v1beta1"
)
crds_list = []

cluster_crds = {crd.spec.names.kind for crd in crds_list}
log.debug(f"CRDs found: {cluster_crds}")
results = []
for crd in custom_resource_definitions:
Expand Down Expand Up @@ -202,11 +210,11 @@ def setup_all_custom_resources(
if results:
got_results = True
if any(results):
return True
succeeded = True
# we want to return True if we never called `setup_custom_resources`
# (i.e., we noop'd) or if any call to `setup_custom_resources`
# succeed (handled above) - otherwise, we want to return False
return not got_results
return succeeded or not got_results


def setup_custom_resources(
Expand Down
4 changes: 4 additions & 0 deletions tests/test_setup_kubernetes_cr.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def test_setup_all_custom_resources_flink():
mock.Mock(items=[flink_crd])
)

mock_client.apiextensions_v1_beta1.list_custom_resource_definition.return_value = mock.Mock(
items=[]
)

custom_resource_definitions = [
mock.Mock(
kube_kind=mock.Mock(plural="flinks", singular="flink", kind="Flink")
Expand Down
Loading