mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
add suffix field to ResId
This commit is contained in:
@@ -122,8 +122,8 @@ func (m ResMap) DeepCopy(rf *resource.Factory) ResMap {
|
||||
}
|
||||
|
||||
// FilterBy returns a subset ResMap containing ResIds with
|
||||
// the same namespace and leftmost name prefix as the
|
||||
// inputId. If inputId is a cluster level resource, this
|
||||
// the same namespace and leftmost name prefix and rightmost name
|
||||
// as the inputId. If inputId is a cluster level resource, this
|
||||
// returns the original ResMap.
|
||||
func (m ResMap) FilterBy(inputId resid.ResId) ResMap {
|
||||
if inputId.Gvk().IsClusterKind() {
|
||||
@@ -131,7 +131,7 @@ func (m ResMap) FilterBy(inputId resid.ResId) ResMap {
|
||||
}
|
||||
result := ResMap{}
|
||||
for id, res := range m {
|
||||
if id.Namespace() == inputId.Namespace() && id.HasSameLeftmostPrefix(inputId) {
|
||||
if id.Namespace() == inputId.Namespace() && id.HasSameLeftmostPrefix(inputId) && id.HasSameRightmostSuffix(inputId) {
|
||||
result[id] = res
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func TestFilterBy(t *testing.T) {
|
||||
expected ResMap
|
||||
}{
|
||||
"different namespace": {
|
||||
resMap: ResMap{resid.NewResIdWithPrefixNamespace(cmap, "config-map", "prefix", "namespace1"): rf.FromMap(
|
||||
resMap: ResMap{resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map", "prefix", "suffix", "namespace1"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -134,11 +134,11 @@ func TestFilterBy(t *testing.T) {
|
||||
},
|
||||
}),
|
||||
},
|
||||
filter: resid.NewResIdWithPrefixNamespace(cmap, "config-map", "prefix", "namespace2"),
|
||||
filter: resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map", "prefix", "suffix", "namespace2"),
|
||||
expected: ResMap{},
|
||||
},
|
||||
"different prefix": {
|
||||
resMap: ResMap{resid.NewResIdWithPrefixNamespace(cmap, "config-map", "prefix1", "namespace"): rf.FromMap(
|
||||
resMap: ResMap{resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map", "prefix1", "suffix", "namespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -147,7 +147,20 @@ func TestFilterBy(t *testing.T) {
|
||||
},
|
||||
}),
|
||||
},
|
||||
filter: resid.NewResIdWithPrefixNamespace(cmap, "config-map", "prefix2", "namespace"),
|
||||
filter: resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map", "prefix2", "suffix", "namespace"),
|
||||
expected: ResMap{},
|
||||
},
|
||||
"different suffix": {
|
||||
resMap: ResMap{resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map", "prefix", "suffix1", "namespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "config-map",
|
||||
},
|
||||
}),
|
||||
},
|
||||
filter: resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map", "prefix", "suffix2", "namespace"),
|
||||
expected: ResMap{},
|
||||
},
|
||||
"same namespace, same prefix": {
|
||||
@@ -171,6 +184,48 @@ func TestFilterBy(t *testing.T) {
|
||||
}),
|
||||
},
|
||||
},
|
||||
"same namespace, same suffix": {
|
||||
resMap: ResMap{resid.NewResIdWithSuffixNamespace(cmap, "config-map1", "suffix", "namespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "config-map1",
|
||||
},
|
||||
}),
|
||||
},
|
||||
filter: resid.NewResIdWithSuffixNamespace(cmap, "config-map2", "suffix", "namespace"),
|
||||
expected: ResMap{resid.NewResIdWithSuffixNamespace(cmap, "config-map1", "suffix", "namespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "config-map1",
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
"same namespace, same prefix, same suffix": {
|
||||
resMap: ResMap{resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map1", "prefix", "suffix", "namespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "config-map",
|
||||
},
|
||||
}),
|
||||
},
|
||||
filter: resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map2", "prefix", "suffix", "namespace"),
|
||||
expected: ResMap{resid.NewResIdWithPrefixSuffixNamespace(cmap, "config-map1", "prefix", "suffix", "namespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "config-map",
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
"filter by cluster-level Gvk": {
|
||||
resMap: ResMap{resid.NewResIdWithPrefixNamespace(cmap, "config-map", "prefix", "namespace"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user