feat: refactor label creation in state.go (#1758)
* feat: refactor label creation in state.go Signed-off-by: yxxhero <aiopsclub@163.com> * fix more Signed-off-by: yxxhero <aiopsclub@163.com> * fix test Signed-off-by: yxxhero <aiopsclub@163.com> * fix more issue Signed-off-by: yxxhero <aiopsclub@163.com> --------- Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
eb6425c20d
commit
1464bd2bfa
|
|
@ -186,8 +186,8 @@ global kube-system true true incubator/raw
|
|||
environment: "development",
|
||||
selectors: []string{"app=test"},
|
||||
expected: `NAME NAMESPACE ENABLED INSTALLED LABELS CHART VERSION
|
||||
external-secrets default true true app:test,chart:raw,name:external-secrets,namespace:default incubator/raw
|
||||
my-release default true true app:test,chart:raw,name:my-release,namespace:default incubator/raw
|
||||
external-secrets default true true app:test incubator/raw
|
||||
my-release default true true app:test incubator/raw
|
||||
`,
|
||||
}, cfg)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -2268,10 +2269,12 @@ func markExcludedReleases(releases []ReleaseSpec, selectors []string, commonLabe
|
|||
filters = append(filters, f)
|
||||
}
|
||||
for _, r := range releases {
|
||||
// Do not add any label without any filter, see #276
|
||||
if len(filters) > 0 {
|
||||
orginReleaseLabel := maps.Clone(r.Labels)
|
||||
if r.Labels == nil {
|
||||
r.Labels = map[string]string{}
|
||||
} else {
|
||||
// Make a copy of the labels to avoid mutating the original
|
||||
r.Labels = maps.Clone(r.Labels)
|
||||
}
|
||||
// Let the release name, namespace, and chart be used as a tag
|
||||
r.Labels["name"] = r.Name
|
||||
|
|
@ -2283,7 +2286,7 @@ func markExcludedReleases(releases []ReleaseSpec, selectors []string, commonLabe
|
|||
for k, v := range commonLabels {
|
||||
r.Labels[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
var filterMatch bool
|
||||
for _, f := range filters {
|
||||
if r.Labels == nil {
|
||||
|
|
@ -2299,6 +2302,8 @@ func markExcludedReleases(releases []ReleaseSpec, selectors []string, commonLabe
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse condition in release %s: %w", r.Name, err)
|
||||
}
|
||||
// reset the labels to the original
|
||||
r.Labels = orginReleaseLabel
|
||||
res := Release{
|
||||
ReleaseSpec: r,
|
||||
Filtered: (len(filters) > 0 && !filterMatch) || (!conditionMatch),
|
||||
|
|
|
|||
Loading…
Reference in New Issue