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