Interpret projected configMap volume names

Append hashes to configMap names under the projected configMap volume,
for Kind: Deployment and StatefulSet
This commit is contained in:
George Angel
2018-07-11 10:28:57 +01:00
parent 3305be9589
commit aa729229e2
3 changed files with 105 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ var secret = schema.GroupVersionKind{Version: "v1", Kind: "Secret"}
var cmap = schema.GroupVersionKind{Version: "v1", Kind: "ConfigMap"}
var ns = schema.GroupVersionKind{Version: "v1", Kind: "Namespace"}
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}
var statefulset = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}
var foo = schema.GroupVersionKind{Group: "example.com", Version: "v1", Kind: "Foo"}
var crd = schema.GroupVersionKind{Group: "apiwctensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"}
var job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"}

View File

@@ -35,6 +35,14 @@ func TestNameReferenceRun(t *testing.T) {
"name": "someprefix-cm1-somehash",
},
}),
resource.NewResId(cmap, "cm2"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "someprefix-cm2-somehash",
},
}),
resource.NewResId(secret, "secret1"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -111,6 +119,13 @@ func TestNameReferenceRun(t *testing.T) {
"configMap": map[string]interface{}{
"name": "cm1",
},
"projected": map[string]interface{}{
"sources": map[string]interface{}{
"configMap": map[string]interface{}{
"name": "cm2",
},
},
},
"secret": map[string]interface{}{
"secretName": "secret1",
},
@@ -122,6 +137,36 @@ func TestNameReferenceRun(t *testing.T) {
},
},
}),
resource.NewResId(statefulset, "statefulset1"): resource.NewResourceFromMap(
map[string]interface{}{
"group": "apps",
"apiVersion": "v1",
"kind": "StatefulSet",
"metadata": map[string]interface{}{
"name": "statefulset1",
},
"spec": map[string]interface{}{
"template": map[string]interface{}{
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"name": "nginx",
"image": "nginx:1.7.9",
},
},
"volumes": map[string]interface{}{
"projected": map[string]interface{}{
"sources": map[string]interface{}{
"configMap": map[string]interface{}{
"name": "cm2",
},
},
},
},
},
},
},
}),
}
expected := resmap.ResMap{
@@ -133,6 +178,14 @@ func TestNameReferenceRun(t *testing.T) {
"name": "someprefix-cm1-somehash",
},
}),
resource.NewResId(cmap, "cm2"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "someprefix-cm2-somehash",
},
}),
resource.NewResId(secret, "secret1"): resource.NewResourceFromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -209,6 +262,13 @@ func TestNameReferenceRun(t *testing.T) {
"configMap": map[string]interface{}{
"name": "someprefix-cm1-somehash",
},
"projected": map[string]interface{}{
"sources": map[string]interface{}{
"configMap": map[string]interface{}{
"name": "someprefix-cm2-somehash",
},
},
},
"secret": map[string]interface{}{
"secretName": "someprefix-secret1-somehash",
},
@@ -220,6 +280,36 @@ func TestNameReferenceRun(t *testing.T) {
},
},
}),
resource.NewResId(statefulset, "statefulset1"): resource.NewResourceFromMap(
map[string]interface{}{
"group": "apps",
"apiVersion": "v1",
"kind": "StatefulSet",
"metadata": map[string]interface{}{
"name": "statefulset1",
},
"spec": map[string]interface{}{
"template": map[string]interface{}{
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"name": "nginx",
"image": "nginx:1.7.9",
},
},
"volumes": map[string]interface{}{
"projected": map[string]interface{}{
"sources": map[string]interface{}{
"configMap": map[string]interface{}{
"name": "someprefix-cm2-somehash",
},
},
},
},
},
},
},
}),
}
nrt, err := NewDefaultingNameReferenceTransformer()

View File

@@ -146,6 +146,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false,
},
{
GroupVersionKind: &schema.GroupVersionKind{
Kind: "Deployment",
},
Path: []string{"spec", "template", "spec", "volumes", "projected", "sources", "configMap", "name"},
CreateIfNotPresent: false,
},
{
GroupVersionKind: &schema.GroupVersionKind{
Kind: "ReplicaSet",
@@ -251,6 +258,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false,
},
{
GroupVersionKind: &schema.GroupVersionKind{
Kind: "StatefulSet",
},
Path: []string{"spec", "template", "spec", "volumes", "projected", "sources", "configMap", "name"},
CreateIfNotPresent: false,
},
{
GroupVersionKind: &schema.GroupVersionKind{
Kind: "Job",