mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Jobs do not create a selector if not already present
This commit is contained in:
@@ -32,6 +32,7 @@ var ns = schema.GroupVersionKind{Version: "v1", Kind: "Namespace"}
|
|||||||
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}
|
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}
|
||||||
var foo = schema.GroupVersionKind{Group: "example.com", Version: "v1", Kind: "Foo"}
|
var foo = schema.GroupVersionKind{Group: "example.com", Version: "v1", Kind: "Foo"}
|
||||||
var crd = schema.GroupVersionKind{Group: "apiwctensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"}
|
var crd = schema.GroupVersionKind{Group: "apiwctensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"}
|
||||||
|
var job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"}
|
||||||
|
|
||||||
func TestLabelsRun(t *testing.T) {
|
func TestLabelsRun(t *testing.T) {
|
||||||
m := resmap.ResMap{
|
m := resmap.ResMap{
|
||||||
@@ -85,6 +86,51 @@ func TestLabelsRun(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
resource.NewResId(job, "job1"): resource.NewResourceFromMap(
|
||||||
|
map[string]interface{}{
|
||||||
|
"apiVersion": "batch/v1",
|
||||||
|
"kind": "Job",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "job1",
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"template": map[string]interface{}{
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"containers": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "nginx",
|
||||||
|
"image": "nginx:1.7.9",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
resource.NewResId(job, "job2"): resource.NewResourceFromMap(
|
||||||
|
map[string]interface{}{
|
||||||
|
"apiVersion": "batch/v1",
|
||||||
|
"kind": "Job",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "job2",
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"selector": map[string]interface{}{
|
||||||
|
"matchLabels": map[string]interface{}{
|
||||||
|
"old-label": "old-value",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"template": map[string]interface{}{
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"containers": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "nginx",
|
||||||
|
"image": "nginx:1.7.9",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
expected := resmap.ResMap{
|
expected := resmap.ResMap{
|
||||||
resource.NewResId(cmap, "cm1"): resource.NewResourceFromMap(
|
resource.NewResId(cmap, "cm1"): resource.NewResourceFromMap(
|
||||||
@@ -161,6 +207,73 @@ func TestLabelsRun(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
resource.NewResId(job, "job1"): resource.NewResourceFromMap(
|
||||||
|
map[string]interface{}{
|
||||||
|
"apiVersion": "batch/v1",
|
||||||
|
"kind": "Job",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "job1",
|
||||||
|
"labels": map[string]interface{}{
|
||||||
|
"label-key1": "label-value1",
|
||||||
|
"label-key2": "label-value2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"template": map[string]interface{}{
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"labels": map[string]interface{}{
|
||||||
|
"label-key1": "label-value1",
|
||||||
|
"label-key2": "label-value2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"containers": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "nginx",
|
||||||
|
"image": "nginx:1.7.9",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
resource.NewResId(job, "job2"): resource.NewResourceFromMap(
|
||||||
|
map[string]interface{}{
|
||||||
|
"apiVersion": "batch/v1",
|
||||||
|
"kind": "Job",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "job2",
|
||||||
|
"labels": map[string]interface{}{
|
||||||
|
"label-key1": "label-value1",
|
||||||
|
"label-key2": "label-value2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"selector": map[string]interface{}{
|
||||||
|
"matchLabels": map[string]interface{}{
|
||||||
|
"label-key1": "label-value1",
|
||||||
|
"label-key2": "label-value2",
|
||||||
|
"old-label": "old-value",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"template": map[string]interface{}{
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"labels": map[string]interface{}{
|
||||||
|
"label-key1": "label-value1",
|
||||||
|
"label-key2": "label-value2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"spec": map[string]interface{}{
|
||||||
|
"containers": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "nginx",
|
||||||
|
"image": "nginx:1.7.9",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
lt, err := NewDefaultingLabelsMapTransformer(map[string]string{"label-key1": "label-value1", "label-key2": "label-value2"})
|
lt, err := NewDefaultingLabelsMapTransformer(map[string]string{"label-key1": "label-value1", "label-key2": "label-value2"})
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ var defaultLabelsPathConfigs = []PathConfig{
|
|||||||
{
|
{
|
||||||
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "Job"},
|
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "Job"},
|
||||||
Path: []string{"spec", "selector", "matchLabels"},
|
Path: []string{"spec", "selector", "matchLabels"},
|
||||||
CreateIfNotPresent: true,
|
CreateIfNotPresent: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "Job"},
|
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "Job"},
|
||||||
|
|||||||
Reference in New Issue
Block a user