Skip to content

Commit

Permalink
fix(operator): Use empty initiliazed pod status map when no pods (#14314
Browse files Browse the repository at this point in the history
)
  • Loading branch information
periklis authored Oct 1, 2024
1 parent 11b92ee commit 6f533ed
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
9 changes: 9 additions & 0 deletions operator/internal/status/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func appendPodStatus(ctx context.Context, k k8s.Client, component, stack, ns str
status := podStatus(&pod)
psm[status] = append(psm[status], pod.Name)
}

if len(psm) == 0 {
psm = lokiv1.PodStatusMap{
lokiv1.PodFailed: []string{},
lokiv1.PodPending: []string{},
lokiv1.PodRunning: []string{},
lokiv1.PodReady: []string{},
}
}
return psm, nil
}

Expand Down
46 changes: 38 additions & 8 deletions operator/internal/status/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func setupListClient(t *testing.T, stack *lokiv1.LokiStack, componentPods map[st
}

func TestGenerateComponentStatus(t *testing.T) {
empty := lokiv1.PodStatusMap{
lokiv1.PodFailed: []string{},
lokiv1.PodPending: []string{},
lokiv1.PodRunning: []string{},
lokiv1.PodReady: []string{},
}

tt := []struct {
desc string
componentPods map[string]*corev1.PodList
Expand All @@ -83,14 +90,14 @@ func TestGenerateComponentStatus(t *testing.T) {
manifests.LabelGatewayComponent: {},
},
wantComponentStatus: &lokiv1.LokiStackComponentStatus{
Compactor: lokiv1.PodStatusMap{},
Distributor: lokiv1.PodStatusMap{},
IndexGateway: lokiv1.PodStatusMap{},
Ingester: lokiv1.PodStatusMap{},
Querier: lokiv1.PodStatusMap{},
QueryFrontend: lokiv1.PodStatusMap{},
Gateway: lokiv1.PodStatusMap{},
Ruler: lokiv1.PodStatusMap{},
Compactor: empty,
Distributor: empty,
IndexGateway: empty,
Ingester: empty,
Querier: empty,
QueryFrontend: empty,
Gateway: empty,
Ruler: empty,
},
},
{
Expand All @@ -116,6 +123,29 @@ func TestGenerateComponentStatus(t *testing.T) {
Ruler: lokiv1.PodStatusMap{lokiv1.PodRunning: {"ruler-pod-0"}},
},
},
{
desc: "all pods without ruler",
componentPods: map[string]*corev1.PodList{
manifests.LabelCompactorComponent: createPodList(manifests.LabelCompactorComponent, false, corev1.PodRunning),
manifests.LabelDistributorComponent: createPodList(manifests.LabelDistributorComponent, false, corev1.PodRunning),
manifests.LabelIngesterComponent: createPodList(manifests.LabelIngesterComponent, false, corev1.PodRunning),
manifests.LabelQuerierComponent: createPodList(manifests.LabelQuerierComponent, false, corev1.PodRunning),
manifests.LabelQueryFrontendComponent: createPodList(manifests.LabelQueryFrontendComponent, false, corev1.PodRunning),
manifests.LabelIndexGatewayComponent: createPodList(manifests.LabelIndexGatewayComponent, false, corev1.PodRunning),
manifests.LabelRulerComponent: {},
manifests.LabelGatewayComponent: createPodList(manifests.LabelGatewayComponent, false, corev1.PodRunning),
},
wantComponentStatus: &lokiv1.LokiStackComponentStatus{
Compactor: lokiv1.PodStatusMap{lokiv1.PodRunning: {"compactor-pod-0"}},
Distributor: lokiv1.PodStatusMap{lokiv1.PodRunning: {"distributor-pod-0"}},
IndexGateway: lokiv1.PodStatusMap{lokiv1.PodRunning: {"index-gateway-pod-0"}},
Ingester: lokiv1.PodStatusMap{lokiv1.PodRunning: {"ingester-pod-0"}},
Querier: lokiv1.PodStatusMap{lokiv1.PodRunning: {"querier-pod-0"}},
QueryFrontend: lokiv1.PodStatusMap{lokiv1.PodRunning: {"query-frontend-pod-0"}},
Gateway: lokiv1.PodStatusMap{lokiv1.PodRunning: {"lokistack-gateway-pod-0"}},
Ruler: empty,
},
},
}

for _, tc := range tt {
Expand Down

0 comments on commit 6f533ed

Please sign in to comment.