Terraform-provider-kubernetes: Kubernetes deployment: setting strategy.type not possible

Created on 18 Dec 2018  路  14Comments  路  Source: hashicorp/terraform-provider-kubernetes

I have a kubernetes deployment where I need to set the strategy type to "Recreate". See https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#strategy

I have specified the definition as following:

resource "kubernetes_deployment" "my-sftp" {
  metadata {
    name = "sftp"
    namespace = "${kubernetes_namespace.stage.metadata.0.name}"

    labels {
      app  = "my-sftp"
    }
  }


  spec {
    replicas = 1

    # because we are using azure disks, we can not attach the storage at the same time to multiple containers

    strategy {
      type = "Recreate" 
    }


    selector {
      match_labels {
        app = "my-sftp"
      }
    }

    template {
      metadata {
        name = "my-sftp"

        labels {
          app  = "my-sftp"
        }
      }

      spec {

        container {
          image = "${var.registry_host}/sftp-server:v1"
       ...

When I execute terraform, it recognizes a change is needed:

~ module.k8s-alpha.kubernetes_deployment.my-sftp
      spec.0.strategy.#:                "0" => "1"
      spec.0.strategy.0.type:           "" => "Recreate"

After execution the field is however not changed, which I can verify by displaying yaml definition directly in kubernetes. Also subsequent executions will try to update the field with no effect. The same is happening, if I try to edit rolling_update{} section.

Terraform Version

Terraform v0.11.7
+ provider.azurerm v1.17.0
+ provider.kubernetes v1.4.0
+ provider.random v2.0.0

Most helpful comment

I can also confirm same issue

Environment

Terraform v0.11.11
+ provider.google v1.20.0
+ provider.kubernetes v1.4.0

Code snippet
```resource "kubernetes_deployment" "myapp" {
metadata {
name = "myapp"
labels {
app = "myapp"
}
}
spec {
replicas = 1
strategy {
type = "RollingUpdate"
rolling_update {
max_surge = "1"
max_unavailable = "1"
}
}
...


Terraform will perform the following actions:
~ kubernetes_deployment.myapp
spec.0.strategy.#: "0" => "1"
spec.0.strategy.0.rolling_update.#: "0" => "1"
spec.0.strategy.0.rolling_update.0.max_surge: "" => "1"
spec.0.strategy.0.rolling_update.0.max_unavailable: "" => "1"
spec.0.strategy.0.type: "" => "RollingUpdate"
```
I hope this helps.

All 14 comments

Seeing same behavior with a slightly newer version of terraform:

Terraform v0.11.10
+ provider.kubernetes v1.4.0

can confirm experiencing the same issue

$ terraform version
Terraform v0.11.10
+ provider.kubernetes v1.4.0

I can also confirm same issue

Environment

Terraform v0.11.11
+ provider.google v1.20.0
+ provider.kubernetes v1.4.0

Code snippet
```resource "kubernetes_deployment" "myapp" {
metadata {
name = "myapp"
labels {
app = "myapp"
}
}
spec {
replicas = 1
strategy {
type = "RollingUpdate"
rolling_update {
max_surge = "1"
max_unavailable = "1"
}
}
...


Terraform will perform the following actions:
~ kubernetes_deployment.myapp
spec.0.strategy.#: "0" => "1"
spec.0.strategy.0.rolling_update.#: "0" => "1"
spec.0.strategy.0.rolling_update.0.max_surge: "" => "1"
spec.0.strategy.0.rolling_update.0.max_unavailable: "" => "1"
spec.0.strategy.0.type: "" => "RollingUpdate"
```
I hope this helps.

Still happening with provider.kubernetes v1.5

This issue is breaking my deployment on azure kubernetes as disks can only be bound to one container.

@alexsomesan can you help with this?

@jeff1985 you can switch to a Stateful Set for now, that's how I'm working around it

Any update on this? Is there a fix without switching to a stateful set?

This is not only a problem for setting strategy type, but also for "max_surge" and "max_unavailable".

@Timer thanks for the hint! it is a good workaround for my issue!

Any update on this? Still seeing it in provider.kubernetes v1.5.2

    strategy {
      type = "RollingUpdate"
    }

Even though its setting it, its always trying to update it

StrategyType:           RollingUpdate
  ~ module.eks_deploy.kubernetes_deployment.this
      spec.0.strategy.#:      "0" => "1"
      spec.0.strategy.0.type: "" => "RollingUpdate"

Trying to learn kubernetes and ran into this issue as well

Might be a result of expandDeploymentStrategy trying to cast type as a map[string]interface{} instead of string.

https://github.com/terraform-providers/terraform-provider-kubernetes/blob/3c56c5554be98497160f93d098d64b1fd976edb8/kubernetes/structures_deployment.go#L98

This is my initial thought on reviewing the code.

Can confirm that this change fixes the issue for me.

Fixed in 1.6.x thanks !

Seems like we have positive confirmation of a fix. Closing.

Was this page helpful?
0 / 5 - 0 ratings