Skip to content

Commit

Permalink
Switch to namespace-aware metadata for cron jobtemplate and sts templ…
Browse files Browse the repository at this point in the history
…ate (#2362)

* Switch to namespace-aware metadata for cron jobtemplate and sts template

* Adds namespace field in the modified version as well

* linting fixes

Signed-off-by: Bernard Grymonpon <[email protected]>

* Added changelog entry for PR 2362

Signed-off-by: Bernard Grymonpon <[email protected]>

---------

Signed-off-by: Bernard Grymonpon <[email protected]>
Co-authored-by: Mauricio Alvarez Leon <[email protected]>
  • Loading branch information
wonko and BBBmau authored Dec 7, 2023
1 parent eae8fa7 commit 0d9471d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .changelog/2362.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
`resource/kubernetes_cron_job_v1`: Change the schema to include a namespace in `jobTemplate`
`resource/kubernetes_stateful_set_v1`: Change the schema to include a namespace in `template`
```
6 changes: 5 additions & 1 deletion kubernetes/resource_kubernetes_cron_job_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestAccKubernetesCronJobV1_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.successful_jobs_history_limit", "10"),
resource.TestCheckResourceAttr(resourceName, "spec.0.suspend", "true"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.metadata.0.annotations.cluster-autoscaler.kubernetes.io/safe-to-evict", "false"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.metadata.0.namespace", "ns-test"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.parallelism", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.backoff_limit", "2"),
resource.TestCheckResourceAttr(resourceName, "spec.0.job_template.0.spec.0.template.0.metadata.0.annotations.controller.kubernetes.io/pod-deletion-cost", "10000"),
Expand Down Expand Up @@ -211,6 +212,7 @@ func testAccKubernetesCronJobV1Config_basic(name, imageName string) string {
annotations = {
"cluster-autoscaler.kubernetes.io/safe-to-evict" = "false"
}
namespace = "ns-test"
}
spec {
backoff_limit = 2
Expand Down Expand Up @@ -242,7 +244,9 @@ func testAccKubernetesCronJobV1Config_modified(name, imageName string) string {
spec {
schedule = "1 0 * * *"
job_template {
metadata {}
metadata {
namespace = "ns-test"
}
spec {
parallelism = 2
template {
Expand Down
2 changes: 2 additions & 0 deletions kubernetes/resource_kubernetes_stateful_set_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestAccKubernetesStatefulSetV1_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.labels.%", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.labels.app", "ss-test"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.namespace", "ns-test"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.name", "ss-test"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.image", imageName),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.0.container_port", "80"),
Expand Down Expand Up @@ -503,6 +504,7 @@ func testAccKubernetesStatefulSetV1ConfigBasic(name, imageName string) string {
labels = {
app = "ss-test"
}
namespace = "ns-test"
}
spec {
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/schema_cron_job_spec_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func cronJobSpecFieldsV1() map[string]*schema.Schema {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"metadata": metadataSchema("jobTemplateSpec", true),
"metadata": namespacedMetadataSchema("jobTemplateSpec", true),
"spec": {
Type: schema.TypeList,
Description: "Specification of the desired behavior of the job",
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/schema_pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func podTemplateFields(owner string) map[string]*schema.Schema {
s := map[string]*schema.Schema{
"metadata": metadataSchema(owner, true),
"metadata": namespacedMetadataSchema(owner, true),
"spec": {
Type: schema.TypeList,
Description: fmt.Sprintf("Spec of the pods owned by the %s", owner),
Expand Down

0 comments on commit 0d9471d

Please sign in to comment.