Skip to content

Commit

Permalink
r/pod: Fix a crash caused by wrong field name
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jul 4, 2017
1 parent 659705c commit 380e750
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 7 deletions.
84 changes: 79 additions & 5 deletions kubernetes/resource_kubernetes_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,38 @@ func TestAccKubernetesPod_with_volume_mount(t *testing.T) {
})
}

func TestAccKubernetesPod_with_cfg_map_volume_mount(t *testing.T) {
var conf api.Pod

podName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
cfgMap := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

imageName := "nginx:1.7.9"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKubernetesPodDestroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesPodConfigWithConfigMapVolume(cfgMap, podName, imageName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPodExists("kubernetes_pod.test", &conf),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.container.0.image", imageName),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.container.0.volume_mount.#", "1"),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.container.0.volume_mount.0.mount_path", "/tmp/my_path"),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.container.0.volume_mount.0.name", "cfg"),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.container.0.volume_mount.0.read_only", "false"),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.container.0.volume_mount.0.sub_path", ""),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.volume.0.name", "cfg"),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.volume.0.config_map.0.name", cfgMap),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.volume.0.config_map.0.default_mode", "511"), // 0777 in decimal
),
},
},
})
}

func TestAccKubernetesPod_with_resource_requirements(t *testing.T) {
var conf api.Pod

Expand Down Expand Up @@ -642,14 +674,14 @@ resource "kubernetes_pod" "test" {
container {
image = "%s"
name = "containername"
volume_mount {
mount_path = "/tmp/my_path"
name = "db"
}
volume_mount {
mount_path = "/tmp/my_path"
name = "db"
}
}
volume {
name = "db"
secret = {
secret {
secret_name = "${kubernetes_secret.test.metadata.0.name}"
}
}
Expand All @@ -658,6 +690,48 @@ resource "kubernetes_pod" "test" {
`, secretName, podName, imageName)
}

func testAccKubernetesPodConfigWithConfigMapVolume(secretName, podName, imageName string) string {
return fmt.Sprintf(`
resource "kubernetes_config_map" "test" {
metadata {
name = "%s"
}
data {
one = "first"
}
}
resource "kubernetes_pod" "test" {
metadata {
labels {
app = "pod_label"
}
name = "%s"
}
spec {
container {
image = "%s"
name = "containername"
volume_mount {
mount_path = "/tmp/my_path"
name = "cfg"
}
}
volume {
name = "cfg"
config_map {
name = "${kubernetes_config_map.test.metadata.0.name}"
default_mode = 0777
}
}
}
}
`, secretName, podName, imageName)
}

func testAccKubernetesPodConfigWithResourceRequirements(podName, imageName string) string {
return fmt.Sprintf(`
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/structures_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func expandConfigMapVolumeSource(l []interface{}) *v1.ConfigMapVolumeSource {
}
in := l[0].(map[string]interface{})
obj := &v1.ConfigMapVolumeSource{
DefaultMode: ptrToInt32(int32(in["default_mode "].(int))),
DefaultMode: ptrToInt32(int32(in["default_mode"].(int))),
}

if v, ok := in["name"].(string); ok {
Expand All @@ -493,7 +493,7 @@ func expandDownwardAPIVolumeSource(l []interface{}) (*v1.DownwardAPIVolumeSource
}
in := l[0].(map[string]interface{})
obj := &v1.DownwardAPIVolumeSource{
DefaultMode: ptrToInt32(int32(in["default_mode "].(int))),
DefaultMode: ptrToInt32(int32(in["default_mode"].(int))),
}
if v, ok := in["items"].([]interface{}); ok && len(v) > 0 {
var err error
Expand Down

0 comments on commit 380e750

Please sign in to comment.