Fix 'flux get all --status-selector' for Alert and Provider
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"),
|
||||
|
||||
+31
@@ -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
|
||||
Reference in New Issue
Block a user