Skip to content

Commit bde2f5f

Browse files
small fixes and refactors
1 parent 672d9c4 commit bde2f5f

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

internal/scout/advise/k8s.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func K8s(
5555
}
5656

5757
for _, pod := range pods {
58-
fmt.Println(scout.EmojiFingerPointRight, pod.Name)
5958
err = Advise(ctx, cfg, pod)
6059
if err != nil {
6160
return errors.Wrap(err, "could not advise")
@@ -84,6 +83,7 @@ func Advise(ctx context.Context, cfg *scout.Config, pod v1.Pod) error {
8483
advice = append(advice, storageAdvice)
8584
}
8685

86+
fmt.Println(scout.EmojiFingerPointRight, pod.Name)
8787
for _, msg := range advice {
8888
fmt.Println(msg)
8989
}
@@ -105,7 +105,7 @@ func getUsageMetrics(ctx context.Context, cfg *scout.Config, pod v1.Pod) ([]scou
105105
Limits: map[string]scout.Resources{},
106106
}
107107

108-
if err = kube.GetLimits(ctx, cfg, &pod, containerMetrics); err != nil {
108+
if err = kube.AddLimits(ctx, cfg, &pod, containerMetrics); err != nil {
109109
return usages, errors.Wrap(err, "failed to get get container metrics")
110110
}
111111

internal/scout/constants.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package scout
33
const (
44
ABillion float64 = 1_000_000_000
55
EmojiFingerPointRight = "👉"
6-
FailureEmoji = "🛑"
76
FlashingLightEmoji = "🚨"
8-
HourglassEmoji = "⌛"
97
SuccessEmoji = "✅"
108
WarningSign = "⚠️ " // why does this need an extra space to align?!?!
119
)

internal/scout/kube/kube.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func GetPodMetrics(ctx context.Context, cfg *scout.Config, pod corev1.Pod) (*met
9090
//
9191
// It returns:
9292
// - Any error that occurred while fetching resource limits
93-
func GetLimits(ctx context.Context, cfg *scout.Config, pod *corev1.Pod, containerMetrics *scout.ContainerMetrics) error {
93+
func AddLimits(ctx context.Context, cfg *scout.Config, pod *corev1.Pod, containerMetrics *scout.ContainerMetrics) error {
9494
for _, container := range pod.Spec.Containers {
9595
containerName := container.Name
9696
capacity, err := GetPvcCapacity(ctx, cfg, container, pod)

internal/scout/usage/k8s.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,12 @@ func renderSinglePodUsageTable(ctx context.Context, cfg *scout.Config, pods []co
5858
return errors.Wrapf(err, "could not get pod with name %s", cfg.Pod)
5959
}
6060

61-
podMetrics, err := kube.GetPodMetrics(ctx, cfg, pod)
62-
if err != nil {
63-
return errors.Wrap(err, "while attempting to fetch pod metrics")
64-
}
65-
6661
containerMetrics := &scout.ContainerMetrics{
6762
PodName: cfg.Pod,
6863
Limits: map[string]scout.Resources{},
6964
}
70-
if err = kube.GetLimits(ctx, cfg, &pod, containerMetrics); err != nil {
71-
return errors.Wrap(err, "failed to get get container metrics")
65+
if err = kube.AddLimits(ctx, cfg, &pod, containerMetrics); err != nil {
66+
return errors.Wrap(err, "failed to add limits to container metrics")
7267
}
7368

7469
columns := []table.Column{
@@ -82,6 +77,11 @@ func renderSinglePodUsageTable(ctx context.Context, cfg *scout.Config, pods []co
8277
}
8378
var rows []table.Row
8479

80+
podMetrics, err := kube.GetPodMetrics(ctx, cfg, pod)
81+
if err != nil {
82+
return errors.Wrap(err, "while attempting to fetch pod metrics")
83+
}
84+
8585
for _, container := range podMetrics.Containers {
8686
stats, err := kube.GetUsage(ctx, cfg, *containerMetrics, pod, container)
8787
if err != nil {
@@ -114,15 +114,16 @@ func renderUsageTable(ctx context.Context, cfg *scout.Config, pods []corev1.Pod)
114114
PodName: pod.Name,
115115
Limits: map[string]scout.Resources{},
116116
}
117+
118+
if err := kube.AddLimits(ctx, cfg, &pod, containerMetrics); err != nil {
119+
return errors.Wrap(err, "failed to get get container metrics")
120+
}
121+
117122
podMetrics, err := kube.GetPodMetrics(ctx, cfg, pod)
118123
if err != nil {
119124
return errors.Wrap(err, "while attempting to fetch pod metrics")
120125
}
121126

122-
if err = kube.GetLimits(ctx, cfg, &pod, containerMetrics); err != nil {
123-
return errors.Wrap(err, "failed to get get container metrics")
124-
}
125-
126127
for _, container := range podMetrics.Containers {
127128
stats, err := kube.GetUsage(ctx, cfg, *containerMetrics, pod, container)
128129
if err != nil {

0 commit comments

Comments
 (0)