...
1#!/bin/bash
2# Copyright 2022 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# This script is intended to gather diagnostic data
17# that helps with debugging Config Connector
18#
19#
20function main {
21 echo "DIAGNOSTIC INFORMATION:
22"
23 print_kubernetes_version
24 echo
25 print_config_connector_version
26 echo
27 print_cnrm_system_status
28 echo
29 print_namespace_annotations
30 echo
31 # after this point, we have to do specific commands for namespace / non-namespace mode
32 mode=$(kubectl get ConfigConnector -o jsonpath='{.items[0].spec.mode}')
33 echo "CONFIG CONNECTOR MODE:
34$mode"
35 echo
36 if [ "$mode" == "cluster" ] ; then
37 print_cluster_mode_diagnostics
38 elif [ "$mode" == "namespaced" ] ; then
39 print_namespace_mode_diagnostics
40 else
41 echo "
42invalid cluster mode: $mode. Please apply a ConfigConnector spec.mode that is one of
43(cluster, namespaced)
44"
45 fi
46}
47
48function print_kubernetes_version {
49 echo "KUBERNETES VERSION:"
50 kubectl version --short
51}
52
53function print_config_connector_version {
54 echo "CONFIG CONNECTOR VERSION:"
55 kubectl get ns cnrm-system -o jsonpath='{.metadata.annotations.cnrm\.cloud\.google\.com/version}'
56 echo
57}
58
59function print_cnrm_system_status {
60 echo "CNRM-SYSTEM RESOURCE STATUS:"
61 kubectl get all -n cnrm-system
62 echo
63}
64
65function print_namespace_annotations {
66 echo "CONFIG CONNECTOR NAMESPACE ANNOTATIONS:
67List of Kubernetes namespaces and the Config Connector project / folder / org annotations.
68If no such annotations exist, Config Connector defaults to the project whose id is the same
69as the namespace.
70"
71
72 kubectl get namespace -o jsonpath="
73{range .items[*]}{.metadata.name}
74 {'project-id: '}{.metadata.annotations['cnrm\.cloud\.google\.com/project-id']}
75 {'folder-id: '}{.metadata.annotations['cnrm\.cloud\.google\.com/folder-id']}
76 {'organization-id: '}{.metadata.annotations['cnrm\.cloud\.google\.com/organization-id']}
77"
78}
79
80# CLUSTER MODE DIAGNOSTICS
81
82function print_cluster_mode_diagnostics {
83 echo "CLUSTER MODE DIAGNOSTICS
84
85CONFIG CONNECTOR KIND:
86"
87 kubectl describe ConfigConnector
88}
89
90# NAMESPACE MODE DIAGNOSTICS
91
92function print_namespace_mode_diagnostics {
93 echo "NAMESPACE MODE DIAGNOSTICS
94
95CONFIG CONNECTOR CONTEXTS:
96"
97 kubectl describe ConfigConnectorContext --all-namespaces
98}
99
100main
View as plain text