-
Notifications
You must be signed in to change notification settings - Fork 985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
r/pod: Fix a crash caused by wrong field name (config map volume source) #19
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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}" | ||
} | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be worth adding some validation to this to the schema too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I'll add validation. |
||
} | ||
} | ||
} | ||
} | ||
`, secretName, podName, imageName) | ||
} | ||
|
||
func testAccKubernetesPodConfigWithResourceRequirements(podName, imageName string) string { | ||
return fmt.Sprintf(` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed on Slack, I could see this causing confusion - would it be worth making this a type String instead until we've better options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on Slack - I generally agree that this is confusing.
I’m just not sure it’s worth implementing a dirty solution (
TypeString
) which may require state migration + config change once we implement the right solution.I’ll take a look into the schema internals and see how hard it would be to implement
IntRepresentation
into the schema. Then if we do it would be just a matter of adding a single line to the existing schema, which seems much cleaner.