diff --git a/cmd/flux/get.go b/cmd/flux/get.go index a736e025..9103abaa 100644 --- a/cmd/flux/get.go +++ b/cmd/flux/get.go @@ -114,6 +114,11 @@ func statusMatches(conditionType, conditionStatus string, conditions []metav1.Co return false } +func readyStatusMatches(conditionType, conditionStatus string) bool { + return strings.EqualFold(conditionType, meta.ReadyCondition) && + strings.EqualFold(conditionStatus, string(metav1.ConditionTrue)) +} + func nameColumns(item named, includeNamespace bool, includeKind bool) []string { name := item.GetName() if includeKind { diff --git a/cmd/flux/get_alert.go b/cmd/flux/get_alert.go index 54b2afe6..657ad1fc 100644 --- a/cmd/flux/get_alert.go +++ b/cmd/flux/get_alert.go @@ -92,5 +92,5 @@ func (s alertListAdapter) headers(includeNamespace bool) []string { } func (s alertListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool { - return false + return readyStatusMatches(conditionType, conditionStatus) } diff --git a/cmd/flux/get_alertprovider.go b/cmd/flux/get_alertprovider.go index 11d50cb3..3119c88a 100644 --- a/cmd/flux/get_alertprovider.go +++ b/cmd/flux/get_alertprovider.go @@ -88,5 +88,5 @@ func (s alertProviderListAdapter) headers(includeNamespace bool) []string { } func (s alertProviderListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool { - return false + return readyStatusMatches(conditionType, conditionStatus) } diff --git a/cmd/flux/get_test.go b/cmd/flux/get_test.go index 90e77ce2..0281cc75 100644 --- a/cmd/flux/get_test.go +++ b/cmd/flux/get_test.go @@ -103,6 +103,39 @@ func Test_GetCmdStatusSelector(t *testing.T) { } } +func Test_GetCmdStatusSelectorSyntheticReady(t *testing.T) { + tmpl := map[string]string{ + "fluxns": allocateNamespace("flux-system"), + } + testEnv.CreateObjectFile("./testdata/get/notification_objects.yaml", tmpl, t) + + commands := []string{ + "get alerts", + "get alert-providers", + "get all", + } + for _, command := range commands { + t.Run(command, func(t *testing.T) { + unfilteredOutput, err := executeCommand(command + " -n " + tmpl["fluxns"]) + if err != nil { + t.Fatalf("%s failed: %v", command, err) + } + if unfilteredOutput == "" { + t.Fatalf("expected %s output for namespace with notification objects", command) + } + + filteredOutput, err := executeCommand(command + " --status-selector Ready=True -n " + tmpl["fluxns"]) + if err != nil { + t.Fatalf("%s with Ready=True status selector failed: %v", command, err) + } + + if filteredOutput != unfilteredOutput { + t.Fatalf("expected Ready=True filtered output to match unfiltered output:\nfiltered:\n%s\nunfiltered:\n%s", filteredOutput, unfilteredOutput) + } + }) + } +} + func Test_GetAllCmdStatusSelectorNoMatches(t *testing.T) { tmpl := map[string]string{ "fluxns": allocateNamespace("flux-system"), diff --git a/cmd/flux/testdata/get/notification_objects.yaml b/cmd/flux/testdata/get/notification_objects.yaml new file mode 100644 index 00000000..abdb7af3 --- /dev/null +++ b/cmd/flux/testdata/get/notification_objects.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .fluxns }} +--- +apiVersion: notification.toolkit.fluxcd.io/v1beta3 +kind: Provider +metadata: + name: slack + namespace: {{ .fluxns }} +spec: + address: https://hooks.slack.com/services/mock + channel: alerts + type: slack +--- +apiVersion: notification.toolkit.fluxcd.io/v1beta3 +kind: Alert +metadata: + name: flux-system + namespace: {{ .fluxns }} +spec: + eventSeverity: info + eventSources: + - kind: GitRepository + name: '*' + - kind: Kustomization + name: '*' + providerRef: + name: slack + summary: Slack notification