Skip to content

Commit

Permalink
fix: Coerce case for restart policy (#77)
Browse files Browse the repository at this point in the history
Co-authored-by: Stenal P Jolly <[email protected]>
Co-authored-by: Bharath KKB <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2021
1 parent b6c4b7c commit 5612b31
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
*/

locals {
cos_image_name = var.cos_image_name
cos_image_family = var.cos_image_name == null ? "cos-${var.cos_image_family}" : null
cos_project = "cos-cloud"
invalid_restart_policy = var.restart_policy != "OnFailure" && var.restart_policy != "UnlessStopped" && var.restart_policy != "Always" && var.restart_policy != "No" ? 1 : 0
restart_policy_enum = tomap({
"onfailure" : "OnFailure"
"unlessstopped" : "UnlessStopped"
"always" : "Always"
"no" : "No"
})

cos_image_name = var.cos_image_name
cos_image_family = var.cos_image_name == null ? "cos-${var.cos_image_family}" : null
cos_project = "cos-cloud"

spec = {
spec = {
containers = [var.container]
volumes = var.volumes
restartPolicy = var.restart_policy
restartPolicy = lookup(local.restart_policy_enum, lower(var.restart_policy), null)
}
}

Expand Down

4 comments on commit 5612b31

@jakevc
Copy link

@jakevc jakevc commented on 5612b31 Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those values do not appear to be acceptable for container restart policy. According to the documentation the only valid values are: "never", "on-failure", "always". Why are these values used instead?

@morgante
Copy link
Contributor

@morgante morgante commented on 5612b31 Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakevc Have you tested these values? If you have tested and can show a reproduction case, open an issue. The gcloud command is not what we're using. In fact, gcloud internally converts to the values.

Please do not consider the gcloud command as documentation for this module.

@jakevc
Copy link

@jakevc jakevc commented on 5612b31 Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. Yes the konlet startup container is killed when I use "No" or "no" here is the error log:

ov 17 18:49:15 gcs-inventory konlet-startup[3383]: 2021/11/17 18:49:15 Creating directory /mnt/disks/gce-containers-mounts/tmpfss/tempfs-0 as a mount point for volume tempfs-0.
Nov 17 18:49:15 gcs-inventory konlet-startup[3383]: 2021/11/17 18:49:15 Attempting to mount device tmpfs at /mnt/disks/gce-containers-mounts/tmpfss/tempfs-0.
Nov 17 18:49:15 gcs-inventory konlet-startup[3383]: 2021/11/17 18:49:15 Error: Failed to start container: Invalid container declaration: Unsupported container restart policy 'No'
Nov 17 18:49:15 gcs-inventory konlet-startup[3383]: 2021/11/17 18:49:15 Saving welcome script to profile.d
Nov 17 18:49:16 gcs-inventory docker[406]: 2021-11-17T18:49:16.339335399Z container die 0362179d3c0247be7703496b7705cbd3b3c0d1ad07d5752206ea6185a975ebd0 (exitCode=1, image=gcr.io/gce-containers/konlet:v.0.11-latest, name=interesting_borg)

However, this does not occur when I use any of "never", "on-failure", or "always".

@morgante
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakevc We don't do support via comments. Open an issue on the module (with your full config) if you're truly having an issue using Terraform.

Please sign in to comment.