x-kubernetes-preserve-unknown-fields in CRD causes Terraform to delete and recreate manifest #7979
Replies: 3 comments 8 replies
-
I do not see anything that would be invalid in our CRD definition. It is an object without a defined structure, so we preserve the unknown fields. And it certainly it does not say anything about needing to delete and recreate the resource. So I have no idea why Terraform behaves like that - that is probably something you would need to ask them. Changing this just like that would be a high-risk change as these things tend to often fix something for one tool and break it for 5 other tools. |
Beta Was this translation helpful? Give feedback.
-
See the note from the person from Hashicorp I linked to in my OP
Labels, annotations and even config are a defined structure. It's just the property names aren't known. But by using the following you're specifying any additional properties will have a value of type string thus allowing something like terraform to validate the document.
|
Beta Was this translation helpful? Give feedback.
-
I'm just experiencing the same issue and every time i change something in the configs it destroys my resources including topic storage |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Please use this to only for bug reports. For questions or when you need help, you can use the GitHub Discussions, our #strimzi Slack channel or out user mailing list.
Describe the bug
I deploy the kafka strimzi manifest using the Terraform
kubernetes_manifest
resource. It uses the CRD schema to determine if a resource can be updated or has to be recreated.When objects specify the
x-kubernetes-preserve-unknown-fields
option in the CRD schema the Kubernetes Terraform provider can't tell if it's safe to update the fields so it instead deletes and recreates the manifest in Kubernetes. See this note for more background: hashicorp/terraform-provider-kubernetes#1928 (comment)I recently tried to update the labels we use for the Kafka pods deployed by Strimzi. But by doing this it's causing Terraform to delete and recreate the Kafka cluster which isn't ideal and causes an outage.
I looked at the Strimzi CRD for Kafka cluster and for annotations and labels it uses the
x-kubernetes-preserve-unknown-fields
I have looked at other CRDs that seem to handle this ok like RabbitMQ and they use another option instead.
I believe the correct way to specify the unknown keys under the labels and annotations objects is to use this
addtionalProperties
key.https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties
The same should apply to other unknown key values such as config options (see cruieseControl config in the terraform snippet below)
To Reproduce
Steps to reproduce the behavior:
kubernetes_manifest
terraform resource typeExpected behavior
I would expect to see Terraform simply update the Kuberntes manifest rather than deleting and recreating.
Environment (please complete the following information):
YAML files and logs
Terraform examples files: https://gist.github.com/warwick-mitchell1/3942059e431fbbc6f82ca97147d0e682
Terraform output
Additional context
Beta Was this translation helpful? Give feedback.
All reactions