@@ -10,6 +10,7 @@ import (
1010 "log"
1111 "net/http"
1212 "os"
13+ "strings"
1314
1415 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516 "k8s.io/client-go/kubernetes"
@@ -35,6 +36,9 @@ type HelmRelease struct {
3536 Version string `json:"version"`
3637 } `json:"metadata"`
3738 } `json:"chart"`
39+ Info struct {
40+ Status string `json:"status"`
41+ } `json:"info"`
3842}
3943
4044func main () {
@@ -49,9 +53,26 @@ func main() {
4953 log .Fatalf ("Failed to create clientset: %v" , err )
5054 }
5155
52- clusterName := getClusterName (clientset )
56+ clusterName := getClusterName ()
5357 kubeVersion := getKubernetesVersion (clientset )
5458
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 {
5576 var helmCharts []HelmChartInfo
5677
5778 namespaces , err := clientset .CoreV1 ().Namespaces ().List (context .TODO (), metav1.ListOptions {})
@@ -99,6 +120,10 @@ func main() {
99120 continue
100121 }
101122
123+ if strings .ToLower (helmRelease .Info .Status ) != "deployed" {
124+ continue
125+ }
126+
102127 helmCharts = append (helmCharts , HelmChartInfo {
103128 ChartName : helmRelease .Chart .Metadata .Name ,
104129 Version : helmRelease .Chart .Metadata .Version ,
@@ -107,20 +132,8 @@ func main() {
107132 }
108133 }
109134
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
122136}
123-
124137func sendDataToAPI (jsonData []byte ) {
125138 apiURL := os .Getenv ("API_URL" )
126139 apiToken := os .Getenv ("API_TOKEN" )
@@ -154,7 +167,7 @@ func sendDataToAPI(jsonData []byte) {
154167 }
155168}
156169
157- func getClusterName (clientset * kubernetes. Clientset ) string {
170+ func getClusterName () string {
158171 if envClusterName := os .Getenv ("CLUSTER_NAME" ); envClusterName != "" {
159172 log .Printf ("Using cluster name from environment: %s" , envClusterName )
160173 return envClusterName
0 commit comments