Skip to content

Commit bbb120a

Browse files
committed
refactor: optimize birdseye printing
1 parent e0fe915 commit bbb120a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pkg/kt/command/birdseye.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,29 @@ func Birdseye() error {
3939
}
4040

4141
if opt.Get().Birdseye.ShowConnector {
42+
log.Info().Msgf("---- User connecting to cluster ----")
4243
unknownUserCount := 0
4344
users := birdseye.GetConnectors(pods, apps)
4445
for _, user := range users {
4546
if user == birdseye.UnknownUser {
4647
unknownUserCount++
4748
} else {
48-
log.Info().Msgf(user)
49+
log.Info().Msgf("> %s", user)
4950
}
5051
}
5152
if unknownUserCount > 0 {
52-
log.Info().Msgf("%d unknown users", unknownUserCount)
53+
log.Info().Msgf("%d users in total (including %d unknown users)",
54+
len(users) + unknownUserCount, unknownUserCount)
55+
} else {
56+
log.Info().Msgf("%d users in total", len(users))
5357
}
5458
}
5559

5660
// service-name, service-description
5761
allServices := birdseye.GetServiceStatus(ktSvcs, pods, svcs)
62+
log.Info().Msgf("---- Service in namespace %s ----", opt.Get().Global.Namespace)
5863
for _, svc := range allServices {
59-
log.Info().Msgf("%s - %s", svc[0], svc[1])
64+
log.Info().Msgf("> %s - %s", svc[0], svc[1])
6065
}
6166
return nil
6267
}

pkg/kt/command/birdseye/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func GetServiceStatus(ktSvcs []coreV1.Service, pods []coreV1.Pod, svcs []coreV1.
5757
for _, svc := range ktSvcs {
5858
for _, p := range pods {
5959
if p.Labels[util.KtRole] == util.RolePreviewShadow && util.MapContains(svc.Spec.Selector, p.Labels) {
60-
allServices = append(allServices, []string{svc.Name, "previewing by " + getUserName(p)})
60+
allServices = append(allServices, []string{svc.Name, fmt.Sprintf("previewing by [%s]", getUserName(p))})
6161
break
6262
}
6363
}
@@ -67,7 +67,7 @@ func GetServiceStatus(ktSvcs []coreV1.Service, pods []coreV1.Pod, svcs []coreV1.
6767
for _, p := range pods {
6868
if util.MapContains(svc.Spec.Selector, p.Labels) {
6969
if role := p.Labels[util.KtRole]; role == util.RoleExchangeShadow {
70-
allServices = append(allServices, []string{svc.Name, "exchanged by " + getUserName(p)})
70+
allServices = append(allServices, []string{svc.Name, fmt.Sprintf("exchanged by [%s]", getUserName(p))})
7171
continue svcLoop
7272
} else if role == util.RoleRouter {
7373
allServices = append(allServices, []string{svc.Name, "meshed (auto) by " +
@@ -113,7 +113,7 @@ func getMeshedUserNames(svcs []coreV1.Service, pods []coreV1.Pod, namePrefix str
113113
if len(users) == 0 {
114114
return UnknownUser
115115
}
116-
return strings.Join(users, ", ")
116+
return "[" + strings.Join(users, "], [") + "]"
117117
}
118118

119119
func checkConnector(labels map[string]string, annotations map[string]string) string {

0 commit comments

Comments
 (0)