@@ -56,7 +56,7 @@ func main() {
5656 log .Fatal (err )
5757 }
5858
59- var imagesInstalled [] HelmChartInfo
59+ uniqImagesByNs := make ( map [ string ] map [ string ] string )
6060 for ns , images := range imagesByNs {
6161 log .Println ("Processing namespace:" , ns )
6262 for _ , img := range images {
@@ -65,11 +65,10 @@ func main() {
6565 log .Printf ("Matched %s -> %s\n " , img , rule .ApplicationName )
6666 if v , ok := normalizeSemVer (rule .VersionRegex .FindString (img ), versionRe ); ok {
6767 log .Printf ("Normalized %-90s -> %s\n " , img , v )
68- imagesInstalled = append (imagesInstalled , HelmChartInfo {
69- ChartName : rule .ApplicationName ,
70- Version : v ,
71- Namespace : ns ,
72- })
68+ if _ , ok := uniqImagesByNs [ns ]; ! ok {
69+ uniqImagesByNs [ns ] = make (map [string ]string )
70+ }
71+ uniqImagesByNs [ns ][rule.ApplicationName ] = v
7372 } else {
7473 log .Printf ("%-90s -> no version\n " , img )
7574 }
@@ -78,6 +77,17 @@ func main() {
7877 }
7978 }
8079
80+ var imagesInstalled []HelmChartInfo
81+ for ns , versionedImage := range uniqImagesByNs {
82+ for v , i := range versionedImage {
83+ imagesInstalled = append (imagesInstalled , HelmChartInfo {
84+ ChartName : i ,
85+ Version : v ,
86+ Namespace : ns ,
87+ })
88+ }
89+ }
90+
8191 clusterName := getClusterName ()
8292 kubeVersion := getKubernetesVersion (clientset )
8393 output := ClusterInfo {
@@ -100,7 +110,7 @@ func CollectNamespaceImages(
100110) (map [string ][]string , error ) {
101111
102112 // accumulate to internal set
103- acc := make (map [string ]map [string ]struct {} )
113+ acc := make (map [string ]map [string ]int )
104114
105115 namespaces , err := client .CoreV1 ().Namespaces ().List (ctx , metav1.ListOptions {})
106116 if err != nil {
@@ -111,7 +121,7 @@ func CollectNamespaceImages(
111121 nsName := ns .Name
112122
113123 if _ , ok := acc [nsName ]; ! ok {
114- acc [nsName ] = make (map [string ]struct {} )
124+ acc [nsName ] = make (map [string ]int )
115125 }
116126
117127 if err := collectFromDeployments (ctx , client , nsName , acc ); err != nil {
@@ -139,21 +149,21 @@ func CollectNamespaceImages(
139149func collectImages (
140150 spec corev1.PodSpec ,
141151 ns string ,
142- acc map [string ]map [string ]struct {} ,
152+ acc map [string ]map [string ]int ,
143153) {
144154 for _ , c := range spec .Containers {
145- acc [ns ][c.Image ] = struct {}{}
155+ acc [ns ][c.Image ] = 1
146156 }
147157 for _ , c := range spec .InitContainers {
148- acc [ns ][c.Image ] = struct {}{}
158+ acc [ns ][c.Image ] = 1
149159 }
150160}
151161
152162func collectFromDeployments (
153163 ctx context.Context ,
154164 client kubernetes.Interface ,
155165 ns string ,
156- acc map [string ]map [string ]struct {} ,
166+ acc map [string ]map [string ]int ,
157167) error {
158168 deploys , err := client .AppsV1 ().Deployments (ns ).List (ctx , metav1.ListOptions {})
159169 if err != nil {
@@ -170,7 +180,7 @@ func collectFromStatefulSets(
170180 ctx context.Context ,
171181 client kubernetes.Interface ,
172182 ns string ,
173- acc map [string ]map [string ]struct {} ,
183+ acc map [string ]map [string ]int ,
174184) error {
175185 sets , err := client .AppsV1 ().StatefulSets (ns ).List (ctx , metav1.ListOptions {})
176186 if err != nil {
@@ -187,7 +197,7 @@ func collectFromDaemonSets(
187197 ctx context.Context ,
188198 client kubernetes.Interface ,
189199 ns string ,
190- acc map [string ]map [string ]struct {} ,
200+ acc map [string ]map [string ]int ,
191201) error {
192202 sets , err := client .AppsV1 ().DaemonSets (ns ).List (ctx , metav1.ListOptions {})
193203 if err != nil {
0 commit comments