@@ -2,6 +2,7 @@ package service
22
33import (
44 "context"
5+ "github.com/pluralsh/deployment-operator/pkg/client"
56 "strings"
67
78 "github.com/Masterminds/semver/v3"
@@ -12,72 +13,80 @@ import (
1213func (s * ServiceReconciler ) ScrapeKube (ctx context.Context ) {
1314 logger := log .FromContext (ctx )
1415 logger .Info ("attempting to collect all runtime services for the cluster" )
15- runtimeServices := map [string ]string {}
16+ runtimeServices := map [string ]* client. NamespaceVersion {}
1617 deployments , err := s .clientset .AppsV1 ().Deployments ("" ).List (ctx , metav1.ListOptions {})
1718 if err == nil {
1819 logger .Info ("aggregating from deployments" )
1920 for _ , deployment := range deployments .Items {
20- AddRuntimeServiceInfo (deployment .GetLabels (), runtimeServices )
21+ AddRuntimeServiceInfo (deployment .Namespace , deployment . GetLabels (), runtimeServices )
2122 }
2223 }
2324
2425 statefulSets , err := s .clientset .AppsV1 ().StatefulSets ("" ).List (ctx , metav1.ListOptions {})
2526 if err == nil {
2627 logger .Info ("aggregating from statefulsets" )
2728 for _ , ss := range statefulSets .Items {
28- AddRuntimeServiceInfo (ss .GetLabels (), runtimeServices )
29+ AddRuntimeServiceInfo (ss .Namespace , ss . GetLabels (), runtimeServices )
2930 }
3031 }
3132
3233 daemonSets , err := s .clientset .AppsV1 ().DaemonSets ("" ).List (ctx , metav1.ListOptions {})
3334 if err == nil {
3435 logger .Info ("aggregating from daemonsets" )
35- for _ , ss := range daemonSets .Items {
36- AddRuntimeServiceInfo (ss .GetLabels (), runtimeServices )
36+ for _ , ds := range daemonSets .Items {
37+ AddRuntimeServiceInfo (ds . Namespace , ds .GetLabels (), runtimeServices )
3738 }
3839 }
3940 if err := s .consoleClient .RegisterRuntimeServices (runtimeServices , nil ); err != nil {
4041 logger .Error (err , "failed to register runtime services, this is an ignorable error but could mean your console needs to be upgraded" )
4142 }
4243}
4344
44- func AddRuntimeServiceInfo (labels map [string ]string , acc map [string ]string ) {
45+ func AddRuntimeServiceInfo (namespace string , labels map [string ]string , acc map [string ]* client. NamespaceVersion ) {
4546 if labels == nil {
4647 return
4748 }
4849
4950 if vsn , ok := labels ["app.kubernetes.io/version" ]; ok {
5051 if name , ok := labels ["app.kubernetes.io/name" ]; ok {
5152 addVersion (acc , name , vsn )
53+ acc [name ].Namespace = namespace
54+ if partOf , ok := labels ["app.kubernetes.io/part-of" ]; ok {
55+ acc [name ].PartOf = partOf
56+ }
5257 return
5358 }
5459
5560 if name , ok := labels ["app.kubernetes.io/part-of" ]; ok {
5661 addVersion (acc , name , vsn )
62+ acc [name ].Namespace = namespace
5763 }
5864 }
65+
5966}
6067
61- func addVersion (services map [string ]string , name , vsn string ) {
68+ func addVersion (services map [string ]* client. NamespaceVersion , name , vsn string ) {
6269 old , ok := services [name ]
6370 if ! ok {
64- services [name ] = vsn
71+ services [name ] = & client.NamespaceVersion {
72+ Version : vsn ,
73+ }
6574 return
6675 }
6776
68- parsedOld , err := semver .NewVersion (strings .TrimPrefix (old , "v" ))
77+ parsedOld , err := semver .NewVersion (strings .TrimPrefix (old . Version , "v" ))
6978 if err != nil {
70- services [name ] = vsn
79+ services [name ]. Version = vsn
7180 return
7281 }
7382
7483 parsedNew , err := semver .NewVersion (strings .TrimPrefix (vsn , "v" ))
7584 if err != nil {
76- services [name ] = vsn
85+ services [name ]. Version = vsn
7786 return
7887 }
7988
8089 if parsedNew .LessThan (parsedOld ) {
81- services [name ] = vsn
90+ services [name ]. Version = vsn
8291 }
8392}
0 commit comments