Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cli/pkg/detect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,11 @@ func (c *Collector) getStrimziStatus() StrimziInfo {
info.CRDsPresent = len(missingCRDs) == 0
info.Health.MissingCRDs = missingCRDs

// Find the deployment for strimzi operator (with permission-friendly namespace fallback)
// Find the deployment for strimzi operator (with permission-friendly namespace fallback).
// A refusal is an error from kubectl; the JSON of every deployment in the
// cluster may say "error" anywhere, a --log-level=error argument included.
depOut, err := c.exec.Exec("kubectl", "get", "deployment", "-A", "-o", "json")
if err != nil || depOut == "" || strings.Contains(depOut, "Forbidden") || strings.Contains(depOut, "error") {
if err != nil || depOut == "" {
// Fallback: check in the kafka namespace
depOut, _ = c.exec.Exec("kubectl", "get", "deployment", "-n", "kafka", "-o", "json")
}
Expand Down
19 changes: 19 additions & 0 deletions cli/pkg/detect/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ func TestCollect_NoStrimzi(t *testing.T) {
}
}

// The lookup read any "error" in the JSON of every deployment as a failed
// kubectl, so one --log-level=error argument anywhere sent it to namespace
// kafka, and an operator in strimzi-system went unseen.
func TestGetStrimziStatus_FindsTheOperatorBesideAnErrorLogLevel(t *testing.T) {
m := NewMockExecutor()
m.Set(`{"items":[
{"metadata":{"name":"ingress-nginx-controller","namespace":"ingress"},
"spec":{"template":{"spec":{"containers":[{"image":"ingress-nginx:1.12","args":["--log-level=error"]}]}}}},
{"metadata":{"name":"strimzi-cluster-operator","namespace":"strimzi-system"},
"spec":{"template":{"spec":{"containers":[{"image":"quay.io/strimzi/operator:0.48.0"}]}}},
"status":{"readyReplicas":1,"replicas":1}}]}`,
"kubectl", "get", "deployment", "-A", "-o", "json")

info := NewCollector(m).getStrimziStatus()
if !info.Running || info.Namespace != "strimzi-system" || info.Image != "quay.io/strimzi/operator:0.48.0" {
t.Errorf("Running %v in %q with image %q, want the operator in strimzi-system", info.Running, info.Namespace, info.Image)
}
}

func TestCollect_SingleZone(t *testing.T) {
singleNodeJSON := `{
"items": [
Expand Down
Loading