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

Init container doesn't support restart_policy option (to transform it in a sidecar container) #2446

Open
arthurgur opened this issue Mar 18, 2024 · 3 comments · May be fixed by #2449
Open

Comments

@arthurgur
Copy link

Terraform Version, Provider Version and Kubernetes Version

Terraform version: 1.6.2
Kubernetes provider version: 2.27.0
Kubernetes version: 1.19

Affected Resource(s)

Terraform Configuration Files

resource "kubernetes_deployment_v1" "example" {
  metadata {
    name = "terraform-example"
    labels = {
      test = "MyExampleApp"
    }
  }

  spec {
    replicas = 3

    selector {
      match_labels = {
        test = "MyExampleApp"
      }
    }

    template {
      metadata {
        labels = {
          test = "MyExampleApp"
        }
      }

      spec {
        container {
          name  = "example"
          image = "nginx:1.21.6"

        # Init container
        init_container {
          name  = "init-setup"
          image = "busybox:latest"
          restart_policy = "Always"
        }
      }
    }
  }
}

Debug Output

Terraform v1.6.2
on linux_amd64
Initializing plugins and modules...
╷
│ Error: Unsupported argument
│ 
│   on app.tf line XX, in resource "kubernetes_deployment_v1" "this":
│   XX:             restart_policy = "Always"
│ 
│ An argument named "restart_policy" is not expected here.
╵
Operation failed: failed running terraform plan (exit 1)

Panic Output

Steps to Reproduce

  1. Create a ressource kubernetes_deployment_v1 with init container and set the option restart_policy of the init container to "Always" to transform it in a sidecar.
  2. Apply your code

Expected Behavior

Pod with sidecar init container created

Actual Behavior

Option non supported

Important Factoids

References

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
@BBBmau
Copy link
Contributor

BBBmau commented Mar 19, 2024

Enabled by default with Kubernetes 1.29, a [feature gate](https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/) named SidecarContainers allows you to specify a restartPolicy for containers listed in a Pod's initContainers field. 
These restartable sidecar containers are independent with other [init containers](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/) and main application container within the same pod.
These can be started, stopped, or restarted without effecting the main application container and other init containers.

Hello @arthurgur, thanks for opening this issue! With this being marked as beta in v1.29, we can proceed with adding this into the provider. You are open to creating a PR that adds this since this is just adding a new field within

func containerFields(isUpdatable bool) map[string]*schema.Schema {

we can guide you in adding the field and also adding tests that check for this.

@arthurgur
Copy link
Author

Hello @BBBmau, thanks for your reply. Unfortunately I don't have rights to create a branch (or I dont know how, it's my first contribution).

@BBBmau
Copy link
Contributor

BBBmau commented Mar 19, 2024

@arthurgur no worries, be sure to look at our contributing guidelines., I would look into also the section on Pull Request Lifecycle since this is your first contribution.

@arthurgur arthurgur linked a pull request Mar 19, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants