terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

Add equivalent of `kubectl rollout restart`

Open foosinn opened this issue 2 years ago • 2 comments

Description

This would allow terraform to restart deployments. Especially useful after deploying other things

Potential Terraform Configuration

resource "kubernetes_rollout_restart" "restart_applciation" {
  apiVersion = "apps/v1"
  kind = "Deployment"

  metadata = {
    "name": "nginx"
    "namespace": "myapp"
  }

  restart_on_create = true  # default value
  restart_on_destroy = true  # default value
}

References

This would provide a much cleaner alternative to https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/blob/master/modules/acm/creds.tf#L85-L99, that also respects current context and network settings.

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

foosinn avatar Sep 28 '23 16:09 foosinn

The way kubectl rollout restart works is by patching the deployment template with the kubectl.kubernetes.io/restartedAt annotation. Rather than adding a new resource for this, you could use the kubernetes_annotations resource to do the same thing:

resource "time_static" "restarted_at" {}

resource "kubernetes_annotations" "example" {
  api_version = "apps/v1"
  kind        = "Deployment"
  metadata {
    name = "nginx-deployment"
  }
  template_annotations = {
    "kubectl.kubernetes.io/restartedAt" = time_static.restarted_at.rfc3339
  }
}

jrhouston avatar Oct 05 '23 14:10 jrhouston

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Oct 05 '24 00:10 github-actions[bot]