in gcpdiag/runbook/gke/logs.py [0:0]
def execute(self):
"""Checks the provided parameters."""
project = op.get(flags.PROJECT_ID)
project_path = crm.get_project(project)
# Checks if there are clusters in the project
clusters = gke.get_clusters(
op.get_new_context(project_id=op.get(flags.PROJECT_ID)))
if not clusters:
op.add_skipped(
project_path,
reason=('No GKE clusters found in project {}').format(project))
return
# The following checks adjust based on the input provided:
# - Both cluster name and location: Verify if that specific cluster exists at that location.
cluster_name = op.get(flags.NAME)
cluster_location = op.get(flags.LOCATION)
found_cluster = False
found_cluster_with_location = False
found_clusters_at_location = False
if cluster_name and cluster_location:
for cluster in clusters.values():
if cluster_name == str(cluster).rsplit('/', maxsplit=1)[-1] \
and cluster_location == str(cluster).split('/')[-3]:
found_cluster_with_location = True
break
if not found_cluster_with_location and cluster_location and cluster_name:
op.add_skipped(
project_path,
reason=('Cluster with the name {} in {} does not exist in project {}'
).format(cluster_name, cluster_location, project))
# next check includes found_cluster_with_location because we found a cluster at a particular
# location thus we cannot skip these checks
elif not found_cluster and not found_cluster_with_location and cluster_name:
op.add_skipped(
project_path,
reason=(
'Cluster with the name {} does not exist in project {}').format(
cluster_name, project))
elif not found_clusters_at_location and not found_cluster_with_location and cluster_location:
op.add_skipped(
project_path,
reason=('No clusters found at location {} in project {}').format(
cluster_location, project))