@@ -10,6 +10,7 @@ import (
10
10
"log"
11
11
"net/http"
12
12
"os"
13
+ "strings"
13
14
14
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
16
"k8s.io/client-go/kubernetes"
@@ -35,6 +36,9 @@ type HelmRelease struct {
35
36
Version string `json:"version"`
36
37
} `json:"metadata"`
37
38
} `json:"chart"`
39
+ Info struct {
40
+ Status string `json:"status"`
41
+ } `json:"info"`
38
42
}
39
43
40
44
func main () {
@@ -49,9 +53,26 @@ func main() {
49
53
log .Fatalf ("Failed to create clientset: %v" , err )
50
54
}
51
55
52
- clusterName := getClusterName (clientset )
56
+ clusterName := getClusterName ()
53
57
kubeVersion := getKubernetesVersion (clientset )
54
58
59
+ helmCharts := getLatestHelmReleases (clientset )
60
+
61
+ output := ClusterInfo {
62
+ ClusterName : clusterName ,
63
+ KubeVersion : kubeVersion ,
64
+ HelmCharts : helmCharts ,
65
+ }
66
+
67
+ jsonData , err := json .MarshalIndent (output , "" , " " )
68
+ if err != nil {
69
+ log .Fatalf ("Failed to convert to JSON: %v" , err )
70
+ }
71
+
72
+ sendDataToAPI (jsonData )
73
+ }
74
+
75
+ func getLatestHelmReleases (clientset * kubernetes.Clientset ) []HelmChartInfo {
55
76
var helmCharts []HelmChartInfo
56
77
57
78
namespaces , err := clientset .CoreV1 ().Namespaces ().List (context .TODO (), metav1.ListOptions {})
@@ -99,6 +120,10 @@ func main() {
99
120
continue
100
121
}
101
122
123
+ if strings .ToLower (helmRelease .Info .Status ) != "deployed" {
124
+ continue
125
+ }
126
+
102
127
helmCharts = append (helmCharts , HelmChartInfo {
103
128
ChartName : helmRelease .Chart .Metadata .Name ,
104
129
Version : helmRelease .Chart .Metadata .Version ,
@@ -107,20 +132,8 @@ func main() {
107
132
}
108
133
}
109
134
110
- output := ClusterInfo {
111
- ClusterName : clusterName ,
112
- KubeVersion : kubeVersion ,
113
- HelmCharts : helmCharts ,
114
- }
115
-
116
- jsonData , err := json .MarshalIndent (output , "" , " " )
117
- if err != nil {
118
- log .Fatalf ("Failed to convert to JSON: %v" , err )
119
- }
120
-
121
- sendDataToAPI (jsonData )
135
+ return helmCharts
122
136
}
123
-
124
137
func sendDataToAPI (jsonData []byte ) {
125
138
apiURL := os .Getenv ("API_URL" )
126
139
apiToken := os .Getenv ("API_TOKEN" )
@@ -154,7 +167,7 @@ func sendDataToAPI(jsonData []byte) {
154
167
}
155
168
}
156
169
157
- func getClusterName (clientset * kubernetes. Clientset ) string {
170
+ func getClusterName () string {
158
171
if envClusterName := os .Getenv ("CLUSTER_NAME" ); envClusterName != "" {
159
172
log .Printf ("Using cluster name from environment: %s" , envClusterName )
160
173
return envClusterName
0 commit comments