gavinbunney / terraform-provider-kubectl

Terraform provider to handle raw kubernetes manifest yaml files
https://registry.terraform.io/providers/gavinbunney/kubectl
Mozilla Public License 2.0
630 stars 108 forks source link

Using `kubectl apply` with long annotations fails #188

Closed mgrzybek closed 2 years ago

mgrzybek commented 2 years ago

Some CRDs have very long annotations that cannot be created using kubectl apply but using kubectl create.

module.kafka.kubectl_manifest.kafka-cluster: Creating...
module.kafka.kubectl_manifest.kafka-users-crd: Creating...
module.kafka.kubectl_manifest.kafka-topics-crd: Creating...
module.kafka.kubectl_manifest.kafka-topics-crd: Creation complete after 0s [id=/apis/apiextensions.k8s.io/v1/customresourcedefinitions/kafkatopics.kafka.banzaicloud.io]
module.kafka.kubectl_manifest.kafka-users-crd: Creation complete after 0s [id=/apis/apiextensions.k8s.io/v1/customresourcedefinitions/kafkausers.kafka.banzaicloud.io]
module.kafka.kubectl_manifest.kafka-clusters-crd: Creating...
╷
│ Error: kafkaclusters.kafka.banzaicloud.io failed to run apply: error when creating "/tmp/214526343kubectl_manifest.yaml": CustomResourceDefinition.apiextensions.k8s.io "kafkaclusters.kafka.banzaicloud.io" is invalid: metadata.annotations: Too long: must have at most 262144 bytes
│ 
│   with module.kafka.kubectl_manifest.kafka-clusters-crd,
│   on kafka/kafka-install.tf line 29, in resource "kubectl_manifest" "kafka-clusters-crd":
│   29: resource "kubectl_manifest" "kafka-clusters-crd" {
│ 
╵
╷

For example, this CRD is too long :

As a consequence, could you add an option in the resource definition ?

Example :

resource "kubectl_manifest" "kafka-clusters-crd" {
  yaml_body = file("${path.module}/kafka-clusters.crds.yaml")

  # Parameter to add
  method = "create"
}

Thanks,
Mathieu
williamclot commented 2 years ago

Have you tried using server_side_apply ?

resource "kubectl_manifest" "kafka-clusters-crd" {
  yaml_body = file("${path.module}/kafka-clusters.crds.yaml")
  server_side_apply = true
}
mgrzybek commented 2 years ago

That solves the problem.