-
Notifications
You must be signed in to change notification settings - Fork 979
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
Add restart_policy option for init containers #2449
base: main
Are you sure you want to change the base?
Conversation
@@ -587,6 +587,19 @@ func containerFields(isUpdatable bool) map[string]*schema.Schema { | |||
Schema: resourcesFieldV1(isUpdatable), | |||
}, | |||
}, | |||
"restart_policy": { |
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.
From first glance be sure to include a test case for this new field. You also want to make sure to add a changelog-entry, this is mentioned in CHANGELOG_GUIDE
The changelog entry and new test should be added into the description of the PR also.
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.
Although you added the changelog you are still missing a testcase that adds this. You would be adding this inside
terraform-provider-kubernetes/kubernetes/resource_kubernetes_deployment_v1_test.go
Lines 90 to 196 in bff3ae2
func TestAccKubernetesDeploymentV1_initContainerForceNew(t *testing.T) { | |
var conf1, conf2 appsv1.Deployment | |
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | |
namespace := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) | |
resourceName := "kubernetes_deployment_v1.test" | |
imageName := busyboxImage | |
imageName1 := agnhostImage | |
initCommand := "until nslookup " + name + "-init-service." + namespace + ".svc.cluster.local; do echo waiting for init-service; sleep 2; done" | |
resource.ParallelTest(t, resource.TestCase{ | |
PreCheck: func() { testAccPreCheck(t) }, | |
IDRefreshIgnore: []string{"metadata.0.resource_version"}, | |
ProviderFactories: testAccProviderFactories, | |
CheckDestroy: testAccCheckKubernetesDeploymentV1Destroy, | |
Steps: []resource.TestStep{ | |
{ | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName1, "64Mi", "testvar", | |
"initcontainer2", initCommand, "IfNotPresent"), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesDeploymentV1Exists(resourceName, &conf1), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.0.image", imageName), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.0.resources.0.requests.memory", "64Mi"), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.0.env.2.value", "testvar"), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.name", "initcontainer2"), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.image", imageName1), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.command.2", initCommand), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.image_pull_policy", "IfNotPresent"), | |
), | |
}, | |
{ // Test for non-empty plans. No modification. | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName1, "64Mi", "testvar", | |
"initcontainer2", initCommand, "IfNotPresent"), | |
PlanOnly: true, | |
}, | |
{ // Modify resources.limits.memory. | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName1, "80Mi", "testvar", | |
"initcontainer2", initCommand, "IfNotPresent"), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesDeploymentV1Exists(resourceName, &conf2), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.0.resources.0.requests.memory", "80Mi"), | |
testAccCheckKubernetesDeploymentForceNew(&conf1, &conf2, false), | |
), | |
}, | |
{ // Modify name of environment variable. | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName1, "64Mi", "testvar", | |
"initcontainer2", initCommand, "IfNotPresent"), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesDeploymentV1Exists(resourceName, &conf2), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.0.env.2.value", "testvar"), | |
testAccCheckKubernetesDeploymentForceNew(&conf1, &conf2, false), | |
), | |
}, | |
{ // Modify init_container's command. | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName1, "64Mi", "testvar", | |
"initcontainer2", "echo done", "IfNotPresent"), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesDeploymentV1Exists(resourceName, &conf2), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.command.2", "echo done"), | |
testAccCheckKubernetesDeploymentForceNew(&conf1, &conf2, false), | |
), | |
}, | |
{ // Modify init_container's image_pull_policy. | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName1, "64Mi", "testvar", | |
"initcontainer2", "echo done", "Never"), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesDeploymentV1Exists(resourceName, &conf2), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.image_pull_policy", "Never"), | |
testAccCheckKubernetesDeploymentForceNew(&conf1, &conf2, false), | |
), | |
}, | |
{ // Modify init_container's image | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName, "64Mi", "testvar", | |
"initcontainer2", "echo done", "Never"), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesDeploymentV1Exists(resourceName, &conf2), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.image", imageName), | |
testAccCheckKubernetesDeploymentForceNew(&conf1, &conf2, false), | |
), | |
}, | |
{ // Modify init_container's name. | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesDeploymentV1Config_initContainer( | |
namespace, name, imageName, imageName, "64Mi", "testvar", | |
"initcontainertwo", "echo done", "Never"), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesDeploymentV1Exists(resourceName, &conf2), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.init_container.1.name", "initcontainertwo"), | |
testAccCheckKubernetesDeploymentForceNew(&conf1, &conf2, false), | |
), | |
}, | |
}, | |
}) | |
} |
as well as
terraform-provider-kubernetes/kubernetes/resource_kubernetes_pod_v1_test.go
Lines 143 to 187 in bff3ae2
func TestAccKubernetesPodV1_initContainer_updateForcesNew(t *testing.T) { | |
var conf1, conf2 api.Pod | |
podName := acctest.RandomWithPrefix("tf-acc-test") | |
image := busyboxImage | |
image1 := agnhostImage | |
resourceName := "kubernetes_pod_v1.test" | |
resource.ParallelTest(t, resource.TestCase{ | |
PreCheck: func() { testAccPreCheck(t) }, | |
ProviderFactories: testAccProviderFactories, | |
CheckDestroy: testAccCheckKubernetesPodV1Destroy, | |
Steps: []resource.TestStep{ | |
{ | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesPodV1ConfigWithInitContainer(podName, image), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesPodV1Exists(resourceName, &conf1), | |
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", podName), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.container.0.name", "container"), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.init_container.0.name", "initcontainer"), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.init_container.0.image", image), | |
), | |
}, | |
{ | |
ResourceName: resourceName, | |
ImportState: true, | |
ImportStateVerify: true, | |
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"}, | |
}, | |
{ | |
Config: testAccKubernetesConfig_ignoreAnnotations() + | |
testAccKubernetesPodV1ConfigWithInitContainer(podName, image1), | |
Check: resource.ComposeAggregateTestCheckFunc( | |
testAccCheckKubernetesPodV1Exists(resourceName, &conf2), | |
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", podName), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.container.0.name", "container"), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.init_container.0.name", "initcontainer"), | |
resource.TestCheckResourceAttr(resourceName, "spec.0.init_container.0.image", image1), | |
testAccCheckKubernetesPodForceNew(&conf1, &conf2, true), | |
), | |
}, | |
}, | |
}) | |
} |
Refer to the contribution guideline to learn how to run tests locally on your machine
@arthurgur do you need some help with the implementation of tests ? |
@arthurgur any blockers that you're running into? |
@arthurgur: Any update on this PR? This would be a great enhancement. |
Agree, this would be very useful. |
This will be unblocked once #2561 is merged. |
is this still blocked? This would be very useful |
@mdering This is still marked as blocked due to being a |
Description
Resolve #2446
Acceptance tests
Output from acceptance testing:
Release Note
Release note for CHANGELOG:
References
Community Note