|
26 | 26 | from ..utils.console import xpk_exit, xpk_print
|
27 | 27 | from .common import set_cluster_command
|
28 | 28 | from .workload import get_workload_list
|
| 29 | +from .kind import set_local_cluster_command |
29 | 30 |
|
30 | 31 |
|
31 | 32 | def inspector_run_command_helper(
|
@@ -124,52 +125,63 @@ def inspector(args) -> None:
|
124 | 125 | final_return_code = 0
|
125 | 126 | xpk_print(args)
|
126 | 127 |
|
127 |
| - add_zone_and_project(args) |
128 |
| - set_cluster_command_code = set_cluster_command(args) |
| 128 | + if not args.kind_cluster: |
| 129 | + add_zone_and_project(args) |
| 130 | + set_cluster_command_code = set_cluster_command(args) |
| 131 | + else: |
| 132 | + set_cluster_command_code = set_local_cluster_command(args) |
| 133 | + |
129 | 134 | if set_cluster_command_code != 0:
|
130 | 135 | xpk_exit(set_cluster_command_code)
|
131 | 136 |
|
132 | 137 | inspector_file = write_tmp_file(
|
133 | 138 | '==================\nXPK inspector OUTPUT:\n==================\n'
|
134 | 139 | )
|
135 |
| - command_and_descriptions = [ |
136 |
| - ('gcloud version', 'Local Setup: gcloud version'), |
137 |
| - ( |
138 |
| - ( |
139 |
| - 'gcloud config get project; gcloud config get compute/zone;' |
140 |
| - ' gcloud config get compute/region' |
141 |
| - ), |
142 |
| - 'Local Setup: Project / Zone / Region', |
143 |
| - ), |
144 |
| - ( |
145 |
| - ( |
146 |
| - 'gcloud beta container clusters list --project' |
147 |
| - f' {args.project} --region {zone_to_region(args.zone)} | grep -e' |
148 |
| - f' NAME -e {args.cluster}' |
149 |
| - ), |
150 |
| - 'GKE: Cluster Details', |
151 |
| - ), |
152 |
| - ( |
153 |
| - ( |
154 |
| - 'kubectl get configmap' |
155 |
| - f' {args.cluster}-{CLUSTER_METADATA_CONFIGMAP} -o yaml' |
156 |
| - ), |
157 |
| - 'GKE: Cluster Metadata ConfigMap Details', |
158 |
| - ), |
159 |
| - ( |
160 |
| - ( |
161 |
| - 'kubectl get configmap' |
162 |
| - f' {args.cluster}-{CLUSTER_RESOURCES_CONFIGMAP} -o yaml' |
163 |
| - ), |
164 |
| - 'GKE: Cluster Resources ConfigMap Details', |
165 |
| - ), |
166 |
| - ( |
167 |
| - ( |
168 |
| - f'gcloud beta container node-pools list --cluster {args.cluster} ' |
169 |
| - f' --project={args.project} --region={zone_to_region(args.zone)}' |
170 |
| - ), |
171 |
| - 'GKE: Node pool Details', |
172 |
| - ), |
| 140 | + |
| 141 | + gcloud_commands_and_descriptions = [] |
| 142 | + if not args.kind_cluster: |
| 143 | + gcloud_commands_and_descriptions = [ |
| 144 | + ('gcloud version', 'Local Setup: gcloud version'), |
| 145 | + ( |
| 146 | + ( |
| 147 | + 'gcloud config get project; gcloud config get compute/zone;' |
| 148 | + ' gcloud config get compute/region' |
| 149 | + ), |
| 150 | + 'Local Setup: Project / Zone / Region', |
| 151 | + ), |
| 152 | + ( |
| 153 | + ( |
| 154 | + 'gcloud beta container clusters list --project' |
| 155 | + f' {args.project} --region {zone_to_region(args.zone)} | grep' |
| 156 | + f' -e NAME -e {args.cluster}' |
| 157 | + ), |
| 158 | + 'GKE: Cluster Details', |
| 159 | + ), |
| 160 | + ( |
| 161 | + ( |
| 162 | + 'kubectl get configmap' |
| 163 | + f' {args.cluster}-{CLUSTER_METADATA_CONFIGMAP} -o yaml' |
| 164 | + ), |
| 165 | + 'GKE: Cluster Metadata ConfigMap Details', |
| 166 | + ), |
| 167 | + ( |
| 168 | + ( |
| 169 | + 'kubectl get configmap' |
| 170 | + f' {args.cluster}-{CLUSTER_RESOURCES_CONFIGMAP} -o yaml' |
| 171 | + ), |
| 172 | + 'GKE: Cluster Resources ConfigMap Details', |
| 173 | + ), |
| 174 | + ( |
| 175 | + ( |
| 176 | + 'gcloud beta container node-pools list --cluster' |
| 177 | + f' {args.cluster} ' |
| 178 | + f' --project={args.project} --region={zone_to_region(args.zone)}' |
| 179 | + ), |
| 180 | + 'GKE: Node pool Details', |
| 181 | + ), |
| 182 | + ] |
| 183 | + |
| 184 | + kubectl_commands_and_descriptions = [ |
173 | 185 | (
|
174 | 186 | (
|
175 | 187 | "kubectl get node -o custom-columns='NODE_NAME:metadata.name,"
|
@@ -234,6 +246,9 @@ def inspector(args) -> None:
|
234 | 246 | ),
|
235 | 247 | ]
|
236 | 248 |
|
| 249 | + command_and_descriptions = ( |
| 250 | + gcloud_commands_and_descriptions + kubectl_commands_and_descriptions |
| 251 | + ) |
237 | 252 | for command, description in command_and_descriptions:
|
238 | 253 | return_code = inspector_run_command_helper(
|
239 | 254 | args, command, description, inspector_file
|
@@ -311,45 +326,46 @@ def inspector(args) -> None:
|
311 | 326 |
|
312 | 327 | # Cloud Console Links:
|
313 | 328 | workload_links = []
|
314 |
| - if args.workload: |
| 329 | + if args.workload and not args.kind_cluster: |
315 | 330 | workload_links = [(
|
316 | 331 | f'Cloud Console for the workload {args.workload}',
|
317 | 332 | # pylint: disable=line-too-long
|
318 | 333 | f'https://console.cloud.google.com/kubernetes/service/{zone_to_region(args.zone)}/{args.cluster}/default/{args.workload}/details?project={args.project}',
|
319 | 334 | )]
|
320 | 335 |
|
321 |
| - links = [ |
322 |
| - ( |
323 |
| - 'Cloud Console for the GKE Cluster', |
324 |
| - # pylint: disable=line-too-long |
325 |
| - f'https://console.cloud.google.com/kubernetes/clusters/details/{zone_to_region(args.zone)}/{args.cluster}/details?project={args.project}', |
326 |
| - ), |
327 |
| - ( |
328 |
| - 'Cloud Console for all workloads in GKE Cluster', |
329 |
| - # pylint: disable=line-too-long |
330 |
| - f'https://console.cloud.google.com/kubernetes/workload/overview?project={args.project}&pageState=((gke%2F{zone_to_region(args.zone)}%2F{args.cluster}))', |
331 |
| - ), |
332 |
| - ( |
333 |
| - 'Cloud Console for IAM Permissions', |
334 |
| - f'https://console.cloud.google.com/iam-admin/iam?project={args.project}', |
335 |
| - ), |
336 |
| - ( |
337 |
| - 'Cloud Console for Quotas', |
338 |
| - f'https://console.cloud.google.com/iam-admin/quotas?project={args.project}', |
339 |
| - ), |
340 |
| - ] |
341 |
| - links.extend(workload_links) |
342 |
| - |
343 |
| - for description, workload_link in links: |
344 |
| - return_code = inspector_output_link_helper( |
345 |
| - args, workload_link, description, inspector_file |
346 |
| - ) |
347 |
| - if return_code != 0: |
348 |
| - final_return_code = return_code |
349 |
| - xpk_print( |
350 |
| - f'inspector failed in link: {workload_link} description:' |
351 |
| - f' {description} return code: {return_code}' |
| 336 | + if not args.kind_cluster: |
| 337 | + links = [ |
| 338 | + ( |
| 339 | + 'Cloud Console for the GKE Cluster', |
| 340 | + # pylint: disable=line-too-long |
| 341 | + f'https://console.cloud.google.com/kubernetes/clusters/details/{zone_to_region(args.zone)}/{args.cluster}/details?project={args.project}', |
| 342 | + ), |
| 343 | + ( |
| 344 | + 'Cloud Console for all workloads in GKE Cluster', |
| 345 | + # pylint: disable=line-too-long |
| 346 | + f'https://console.cloud.google.com/kubernetes/workload/overview?project={args.project}&pageState=((gke%2F{zone_to_region(args.zone)}%2F{args.cluster}))', |
| 347 | + ), |
| 348 | + ( |
| 349 | + 'Cloud Console for IAM Permissions', |
| 350 | + f'https://console.cloud.google.com/iam-admin/iam?project={args.project}', |
| 351 | + ), |
| 352 | + ( |
| 353 | + 'Cloud Console for Quotas', |
| 354 | + f'https://console.cloud.google.com/iam-admin/quotas?project={args.project}', |
| 355 | + ), |
| 356 | + ] |
| 357 | + links.extend(workload_links) |
| 358 | + |
| 359 | + for description, workload_link in links: |
| 360 | + return_code = inspector_output_link_helper( |
| 361 | + args, workload_link, description, inspector_file |
352 | 362 | )
|
| 363 | + if return_code != 0: |
| 364 | + final_return_code = return_code |
| 365 | + xpk_print( |
| 366 | + f'inspector failed in link: {workload_link} description:' |
| 367 | + f' {description} return code: {return_code}' |
| 368 | + ) |
353 | 369 |
|
354 | 370 | # Summarize inspector:
|
355 | 371 | xpk_print(f'Find xpk inspector output file: {inspector_file.name}')
|
|
0 commit comments