From 1aa0f47736ae6015493d6bc32e5b5b6c3aa934f3 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Fri, 1 Oct 2021 19:59:15 +0100 Subject: [PATCH] ilm: Correctly show tags in tabular info when this non AND tag (#3819) Tag can be set directly under Filter tag and not always under Filter.And in the lifecycle document. In that case, the tag won't be properly showed in the tabular info of the ILM listing. This PR fixes it. --- cmd/ilm/tabular_info.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/ilm/tabular_info.go b/cmd/ilm/tabular_info.go index 8e1d6fe1..7f409b50 100644 --- a/cmd/ilm/tabular_info.go +++ b/cmd/ilm/tabular_info.go @@ -269,10 +269,16 @@ func getStorageClassName(rule lifecycle.Rule) string { // Array of Tag strings, each in key:value format func getTagArr(rule lifecycle.Rule) []string { - if rule.RuleFilter.And.IsEmpty() { + var tagArr []lifecycle.Tag + switch { + case !rule.RuleFilter.Tag.IsEmpty(): + tagArr = []lifecycle.Tag{rule.RuleFilter.Tag} + case !rule.RuleFilter.And.IsEmpty(): + tagArr = rule.RuleFilter.And.Tags + default: return []string{} } - tagArr := rule.RuleFilter.And.Tags + tagLth := len(tagArr) tagCellArr := make([]string, len(tagArr)) for tagIdx := 0; tagIdx < tagLth; tagIdx++ { @@ -308,16 +314,18 @@ func getILMShowDataWithoutTags(cellInfo *[][]string, rowCheck map[string]int, in for index := 0; index < len(info.Rules); index++ { rule := info.Rules[index] + // Ignore this rule if it has tag filter in it + if len(getTagArr(rule)) > 0 { + continue + } + showExpiry := !rule.Expiration.IsNull() transitionSet := !rule.Transition.IsNull() skipExpTran := (showOpts.expiry && !showExpiry) || (showOpts.transition && !transitionSet) if skipExpTran { continue } - tagPresent := !rule.RuleFilter.And.IsEmpty() - if tagPresent { - continue - } + *cellInfo = append(*cellInfo, make([]string, 0)) checkAddTableCell(&((*cellInfo)[count]), rowCheck, tableCellInfo{label: rule.ID, labelKey: idLabel, columnWidth: idColumnWidth, align: leftAlign}) @@ -348,15 +356,18 @@ func getILMShowDataWithTags(cellInfo *[][]string, newRows map[string][]string, r for index := 0; index < len(info.Rules); index++ { rule := info.Rules[index] + // Ignore printing this rule if it doesn't have any tag filter in it + if len(getTagArr(rule)) == 0 { + continue + } + showExpiry := !rule.Expiration.IsNull() transitionSet := !rule.Transition.IsNull() skipExpTran := (showOpts.expiry && !showExpiry) || (showOpts.transition && !transitionSet) if skipExpTran { continue } - if len(getTagArr(rule)) == 0 { - continue - } + *cellInfo = append(*cellInfo, make([]string, 0)) checkAddTableCell(&((*cellInfo)[count]), rowCheck, tableCellInfo{label: rule.ID, labelKey: idLabel, columnWidth: idColumnWidth, align: leftAlign})