Skip to content
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

[TK-1957] Update container.resources schema for Pod, DaemonSet and Deployment #1889

Merged
merged 5 commits into from
Nov 18, 2022

Conversation

arybolovlev
Copy link
Contributor

@arybolovlev arybolovlev commented Nov 1, 2022

Description

This PR does the following changes:

  • 🐛 fix an issue when empty values of spec.container.resources.limits or spec.container.resources.requests produce continuous diff output during plan although no real changes were made. Affected resources: kubernetes_pod, kubernetes_pod_v1, kubernetes_daemonset, kubernetes_daemon_set_v1, kubernetes_deployment, kubernetes_deployment_v1.
  • 🐛 fix an issue when changing values of spec.container.resources.limits or spec.container.resources.requests does not update appropriate Kubernetes resources. Affected resources: kubernetes_pod, kubernetes_pod_v1.
  • ✨ changing values of spec.container.resources.limits or spec.container.resources.requests will force resource recreation. Affected resources: kubernetes_pod, kubernetes_pod_v1.

Related documentation changes are in the different PR: #1882

Acceptance tests

  • Have you added an acceptance test for the functionality being added?
  • Have you run the acceptance tests on this branch?

Output from acceptance testing:

$ make testacc TESTARGS="-count 1 -run ^TestAccKubernetesDaemonSet_with_resource_requirements"
...
=== RUN   TestAccKubernetesDaemonSet_with_resource_requirements
--- PASS: TestAccKubernetesDaemonSet_with_resource_requirements (6.57s)

$ make testacc TESTARGS="-count 1 -run ^TestAccKubernetesDeployment_with_resource_requirements"
...
=== RUN   TestAccKubernetesDeployment_with_resource_requirements
--- PASS: TestAccKubernetesDeployment_with_resource_requirements (6.15s)

$ make testacc TESTARGS="-count 1 -run ^TestAccKubernetesPod_with_resource_requirements"
...
=== RUN   TestAccKubernetesPod_with_resource_requirements
--- PASS: TestAccKubernetesPod_with_resource_requirements (19.99s)

Release Note

Release note for CHANGELOG:

ENHANCEMENT:

* `r/kubernetes_pod_v1`: changing values of `spec.container.resources.limits` or `spec.container.resources.requests` will force resource recreation.
* `r/kubernetes_pod`: changing values of `spec.container.resources.limits` or `spec.container.resources.requests` will force resource recreation.

BUG FIXES:

* Fix an issue when changing values of `spec.container.resources.limits` or `spec.container.resources.requests` does not update appropriate Kubernetes resources. Affected resources: `kubernetes_pod`, `kubernetes_pod_v1`.
* Fix an issue when empty values of `spec.container.resources.limits` or `spec.container.resources.requests` produce continuous diff output during `plan` although no real changes were made. Affected resources: `kubernetes_pod`, `kubernetes_pod_v1`, `kubernetes_daemonset`, `kubernetes_daemon_set_v1`, `kubernetes_deployment`, `kubernetes_deployment_v1`.

References

Fix: #1880

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

@arybolovlev arybolovlev changed the title Update container.resources schema for Pod, DaemonSet and Deployment [TK-1957] Update container.resources schema for Pod, DaemonSet and Deployment Nov 1, 2022
@arybolovlev arybolovlev force-pushed the fix-contatner-resource-computed branch 2 times, most recently from f499226 to 24bb7d9 Compare November 1, 2022 15:39
@@ -348,15 +348,11 @@ func flattenContainerPorts(in []v1.ContainerPort) []interface{} {
return att
}

func flattenContainerResourceRequirements(in v1.ResourceRequirements) ([]interface{}, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the error return from this function since we never return any errors, just nil.

if len(in.Requests) > 0 {
att["requests"] = flattenResourceList(in.Requests)
}
return []interface{}{att}, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove length validation here and accept an empty map from flattenResourceList to store empty values instead of null in the Terraform state file.

@arybolovlev arybolovlev force-pushed the fix-contatner-resource-computed branch from f0ac63e to ddc8450 Compare November 14, 2022 10:22
You can also skip this and just allow Terraform to destroy and recreate the resource, but this is not recommended for resources like `kubernetes_service` and `kubernetes_deployment`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what exactly has changed here, this is the result of 'make website-lint-fix'.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just trailing whitespace being remove

@arybolovlev arybolovlev marked this pull request as ready for review November 14, 2022 11:29
@arybolovlev arybolovlev merged commit 2f50988 into main Nov 18, 2022
@arybolovlev arybolovlev deleted the fix-contatner-resource-computed branch November 18, 2022 08:45
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

1 similar comment
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubernetes_deployment resources
2 participants