Skip to content

Commit

Permalink
Merge pull request #17 from ryane/fix-service-selector-labels
Browse files Browse the repository at this point in the history
remove helm labels from Service selector
  • Loading branch information
etiennetremel authored Nov 29, 2018
2 parents eba076c + 82b63ac commit 973cc68
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/transformers/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ RESOURCES_LOOP:
}

func (t *labelsTransformer) removeLabels(config *ktypes.Kustomization, resources *types.Resources) error {
paths := []string{"matchLabels", "labels"}
paths := []string{"matchLabels", "labels", "selector"}
for id := range resources.ResMap {
obj := resources.ResMap[id].Map()
for _, path := range paths {
Expand Down
131 changes: 130 additions & 1 deletion pkg/transformers/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,138 @@ func TestLabelsRun(t *testing.T) {
},
},
},
{
name: "it should remove helm labels",
input: &labelsTransformerArgs{
config: &ktypes.Kustomization{},
resources: &types.Resources{
ResMap: resmap.ResMap{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "cm1",
"labels": map[string]interface{}{
"chart": "nginx",
"heritage": "Tiller",
"release": "nginx",
},
},
}),
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "deploy1",
"labels": map[string]interface{}{
"chart": "nginx",
"heritage": "Tiller",
"release": "nginx",
},
},
}),
resid.NewResId(service, "service1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
"metadata": map[string]interface{}{
"name": "service1",
"labels": map[string]interface{}{
"chart": "nginx",
"heritage": "Tiller",
"release": "nginx",
},
},
"spec": map[string]interface{}{
"selector": map[string]interface{}{
"chart": "nginx",
"heritage": "Tiller",
"release": "nginx",
},
},
}),
resid.NewResId(service, "poddisruptionbudget1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "policy/v1beta1",
"kind": "PodDisruptionBudget",
"metadata": map[string]interface{}{
"name": "poddisruptionbudget1",
"labels": map[string]interface{}{
"chart": "nginx",
"heritage": "Tiller",
"release": "nginx",
},
},
"spec": map[string]interface{}{
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"chart": "nginx",
"heritage": "Tiller",
"release": "nginx",
},
},
},
}),
},
},
},
expected: &labelsTransformerArgs{
config: &ktypes.Kustomization{},
resources: &types.Resources{
ResMap: resmap.ResMap{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "cm1",
"labels": map[string]interface{}{},
},
}),
resid.NewResId(deploy, "deploy1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "deploy1",
"labels": map[string]interface{}{},
},
}),
resid.NewResId(service, "service1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
"metadata": map[string]interface{}{
"name": "service1",
"labels": map[string]interface{}{},
},
"spec": map[string]interface{}{
"selector": map[string]interface{}{},
},
}),
resid.NewResId(service, "poddisruptionbudget1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "policy/v1beta1",
"kind": "PodDisruptionBudget",
"metadata": map[string]interface{}{
"name": "poddisruptionbudget1",
"labels": map[string]interface{}{},
},
"spec": map[string]interface{}{
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{},
},
},
}),
},
},
},
},
} {
t.Run(fmt.Sprintf("%s", test.name), func(t *testing.T) {
lt := NewLabelsTransformer([]string{})
lt := NewLabelsTransformer([]string{"chart", "release", "heritage"})
err := lt.Transform(test.input.config, test.input.resources)

if err != nil {
Expand Down

0 comments on commit 973cc68

Please sign in to comment.