From 507da6667a06f4c0fa28a92ac4c59cf84e2dc87f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kozlovsk=C3=BD?= Date: Fri, 20 Sep 2024 20:33:58 +0200 Subject: [PATCH] Add VolumeDevices to PodSpec (#2572) (#2573) * Add VolumeDevices to PodSpec (#2572) * Update changelog to include schema_container --------- Co-authored-by: Mauricio Alvarez Leon <65101411+BBBmau@users.noreply.github.com> --- .changelog/2573.txt | 3 + docs/resources/cron_job.md | 18 + docs/resources/cron_job_v1.md | 18 + docs/resources/daemon_set_v1.md | 16 + docs/resources/daemonset.md | 16 + docs/resources/deployment.md | 16 + docs/resources/deployment_v1.md | 16 + docs/resources/job.md | 16 + docs/resources/job_v1.md | 16 + docs/resources/pod.md | 18 + docs/resources/pod_v1.md | 18 + docs/resources/replication_controller.md | 16 + docs/resources/replication_controller_v1.md | 16 + docs/resources/stateful_set.md | 47 +- docs/resources/stateful_set_v1.md | 46 +- ...esource_kubernetes_stateful_set_v1_test.go | 5 +- ...stateful_set_v1_with_volume_device_test.go | 1421 +++++++++++++++++ kubernetes/schema_container.go | 24 + kubernetes/structures_container.go | 45 + 19 files changed, 1788 insertions(+), 3 deletions(-) create mode 100644 .changelog/2573.txt create mode 100644 kubernetes/resource_kubernetes_stateful_set_v1_with_volume_device_test.go diff --git a/.changelog/2573.txt b/.changelog/2573.txt new file mode 100644 index 0000000000..b0c4b34dcb --- /dev/null +++ b/.changelog/2573.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +`schema_container.go`: Add VolumeDevices +``` diff --git a/docs/resources/cron_job.md b/docs/resources/cron_job.md index 16679f7dd6..a88ad2ec6c 100644 --- a/docs/resources/cron_job.md +++ b/docs/resources/cron_job.md @@ -466,6 +466,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -949,6 +950,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.job_template.spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + @@ -1018,6 +1027,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1501,6 +1511,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.job_template.spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + diff --git a/docs/resources/cron_job_v1.md b/docs/resources/cron_job_v1.md index 0f6f6662e6..d57de2b6b5 100644 --- a/docs/resources/cron_job_v1.md +++ b/docs/resources/cron_job_v1.md @@ -461,6 +461,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -944,6 +945,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.job_template.spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + @@ -1013,6 +1022,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--job_template--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1496,6 +1506,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.job_template.spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + diff --git a/docs/resources/daemon_set_v1.md b/docs/resources/daemon_set_v1.md index 360ade82fb..59ba45b42d 100644 --- a/docs/resources/daemon_set_v1.md +++ b/docs/resources/daemon_set_v1.md @@ -415,6 +415,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -898,6 +899,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -967,6 +975,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1450,6 +1459,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/daemonset.md b/docs/resources/daemonset.md index 8de79f5301..582da60be2 100644 --- a/docs/resources/daemonset.md +++ b/docs/resources/daemonset.md @@ -415,6 +415,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -898,6 +899,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -967,6 +975,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1450,6 +1459,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md index f6ff5e1905..1282ac3e7f 100644 --- a/docs/resources/deployment.md +++ b/docs/resources/deployment.md @@ -415,6 +415,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -898,6 +899,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -967,6 +975,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1450,6 +1459,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/deployment_v1.md b/docs/resources/deployment_v1.md index 5b8011dfbb..99854140b6 100644 --- a/docs/resources/deployment_v1.md +++ b/docs/resources/deployment_v1.md @@ -423,6 +423,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -906,6 +907,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -975,6 +983,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1458,6 +1467,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/job.md b/docs/resources/job.md index 79ae3158d0..73dacd7813 100644 --- a/docs/resources/job.md +++ b/docs/resources/job.md @@ -423,6 +423,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -906,6 +907,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -975,6 +983,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1458,6 +1467,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/job_v1.md b/docs/resources/job_v1.md index 70f52d1336..d0c6d1c94c 100644 --- a/docs/resources/job_v1.md +++ b/docs/resources/job_v1.md @@ -419,6 +419,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -902,6 +903,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -971,6 +979,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1454,6 +1463,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/pod.md b/docs/resources/pod.md index 636964a54b..548a508040 100644 --- a/docs/resources/pod.md +++ b/docs/resources/pod.md @@ -374,6 +374,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -857,6 +858,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + @@ -926,6 +935,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1409,6 +1419,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + diff --git a/docs/resources/pod_v1.md b/docs/resources/pod_v1.md index d9e6b72c67..957dd320da 100644 --- a/docs/resources/pod_v1.md +++ b/docs/resources/pod_v1.md @@ -372,6 +372,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -855,6 +856,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + @@ -924,6 +933,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1407,6 +1417,14 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. + diff --git a/docs/resources/replication_controller.md b/docs/resources/replication_controller.md index f4d766cbd1..e08a5ce4bb 100644 --- a/docs/resources/replication_controller.md +++ b/docs/resources/replication_controller.md @@ -412,6 +412,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -895,6 +896,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -964,6 +972,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1447,6 +1456,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/replication_controller_v1.md b/docs/resources/replication_controller_v1.md index 10dafd5fe8..e83f7c6969 100644 --- a/docs/resources/replication_controller_v1.md +++ b/docs/resources/replication_controller_v1.md @@ -410,6 +410,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -893,6 +894,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -962,6 +970,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1445,6 +1454,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. diff --git a/docs/resources/stateful_set.md b/docs/resources/stateful_set.md index 47c337c3b2..dde06232ef 100644 --- a/docs/resources/stateful_set.md +++ b/docs/resources/stateful_set.md @@ -442,6 +442,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -925,6 +926,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -994,6 +1002,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1477,6 +1486,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -2348,7 +2364,7 @@ Optional: ## Example Usage ```terraform -resource "kubernetes_stateful_set" "prometheus" { +resource "kubernetes_stateful_set_v1" "prometheus" { metadata { annotations = { SomeAnnotation = "foobar" @@ -2365,6 +2381,7 @@ resource "kubernetes_stateful_set" "prometheus" { } spec { + min_ready_seconds = 10 pod_management_policy = "Parallel" replicas = 1 revision_history_limit = 5 @@ -2400,6 +2417,11 @@ resource "kubernetes_stateful_set" "prometheus" { mount_path = "/data" sub_path = "" } + + volume_device { + name = "prometheus-device" + device_path = "/dev/xvda" + } } container { @@ -2471,6 +2493,11 @@ resource "kubernetes_stateful_set" "prometheus" { sub_path = "" } + volume_device { + name = "prometheus-device" + device_path = "/dev/xvda" + } + readiness_probe { http_get { path = "/-/ready" @@ -2530,6 +2557,24 @@ resource "kubernetes_stateful_set" "prometheus" { } } + volume_claim_template { + metadata { + name = "prometheus-device" + } + + spec { + access_modes = ["ReadWriteOnce"] + storage_class_name = "local-storage" + volume_mode = "Block" + + resources { + requests = { + storage = "16Gi" + } + } + } + } + persistent_volume_claim_retention_policy { when_deleted = "Delete" when_scaled = "Delete" diff --git a/docs/resources/stateful_set_v1.md b/docs/resources/stateful_set_v1.md index ae02088943..911677fe8a 100644 --- a/docs/resources/stateful_set_v1.md +++ b/docs/resources/stateful_set_v1.md @@ -447,6 +447,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -930,6 +931,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -999,6 +1007,7 @@ Optional: - `termination_message_policy` (String) Optional: Indicate how the termination message should be populated. File will use the contents of terminationMessagePath to populate the container status message on both success and failure. FallbackToLogsOnError will use the last chunk of container log output if the termination message file is empty and the container exited with an error. The log output is limited to 2048 bytes or 80 lines, whichever is smaller. Defaults to File. Cannot be updated. - `tty` (Boolean) Whether this container should allocate a TTY for itself - `volume_mount` (Block List) Pod volumes to mount into the container's filesystem. Cannot be updated. (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_mount)) +- `volume_device` (Block List) Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated. More info: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#volumes-1 (see [below for nested schema](#nestedblock--spec--template--spec--init_container--volume_device)) - `working_dir` (String) Container's working directory. If not specified, the container runtime's default will be used, which might be configured in the container image. Cannot be updated. @@ -1482,6 +1491,13 @@ Optional: - `read_only` (Boolean) Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false. - `sub_path` (String) Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root). + +### Nested Schema for `spec.template.spec.init_container.volume_device` + +Required: + +- `device_path` (String) Path within the container at which the volume device should be attached. For example '/dev/xvda'. +- `name` (String) This must match the Name of a PersistentVolumeClaim. @@ -2370,7 +2386,7 @@ resource "kubernetes_stateful_set_v1" "prometheus" { } spec { - min_ready_seconds = 10 + min_ready_seconds = 10 pod_management_policy = "Parallel" replicas = 1 revision_history_limit = 5 @@ -2406,6 +2422,11 @@ resource "kubernetes_stateful_set_v1" "prometheus" { mount_path = "/data" sub_path = "" } + + volume_device { + name = "prometheus-device" + device_path = "/dev/xvda" + } } container { @@ -2477,6 +2498,11 @@ resource "kubernetes_stateful_set_v1" "prometheus" { sub_path = "" } + volume_device { + name = "prometheus-device" + device_path = "/dev/xvda" + } + readiness_probe { http_get { path = "/-/ready" @@ -2536,6 +2562,24 @@ resource "kubernetes_stateful_set_v1" "prometheus" { } } + volume_claim_template { + metadata { + name = "prometheus-device" + } + + spec { + access_modes = ["ReadWriteOnce"] + storage_class_name = "local-storage" + volume_mode = "Block" + + resources { + requests = { + storage = "16Gi" + } + } + } + } + persistent_volume_claim_retention_policy { when_deleted = "Delete" when_scaled = "Delete" diff --git a/kubernetes/resource_kubernetes_stateful_set_v1_test.go b/kubernetes/resource_kubernetes_stateful_set_v1_test.go index 9ba50685fd..f2d99095bf 100644 --- a/kubernetes/resource_kubernetes_stateful_set_v1_test.go +++ b/kubernetes/resource_kubernetes_stateful_set_v1_test.go @@ -52,6 +52,7 @@ func TestAccKubernetesStatefulSetV1_basic(t *testing.T) { PreCheck: func() { testAccPreCheck(t) skipIfClusterVersionLessThan(t, "1.27.0") + skipIfRunningInEks(t) }, IDRefreshName: resourceName, IDRefreshIgnore: []string{ @@ -134,6 +135,7 @@ func TestAccKubernetesStatefulSetV1_basic_idempotency(t *testing.T) { PreCheck: func() { testAccPreCheck(t) skipIfClusterVersionLessThan(t, "1.27.0") + skipIfRunningInEks(t) }, IDRefreshName: resourceName, IDRefreshIgnore: []string{ @@ -172,6 +174,7 @@ func TestAccKubernetesStatefulSetV1_Update(t *testing.T) { PreCheck: func() { testAccPreCheck(t) skipIfClusterVersionLessThan(t, "1.27.0") + skipIfRunningInEks(t) }, IDRefreshName: resourceName, IDRefreshIgnore: []string{ @@ -322,7 +325,7 @@ func TestAccKubernetesStatefulSetV1_waitForRollout(t *testing.T) { resourceName := "kubernetes_stateful_set_v1.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); skipIfRunningInEks(t) }, IDRefreshName: resourceName, IDRefreshIgnore: []string{ "spec.0.template.0.spec.0.container.0.resources.0.limits", diff --git a/kubernetes/resource_kubernetes_stateful_set_v1_with_volume_device_test.go b/kubernetes/resource_kubernetes_stateful_set_v1_with_volume_device_test.go new file mode 100644 index 0000000000..7c3cdeb92b --- /dev/null +++ b/kubernetes/resource_kubernetes_stateful_set_v1_with_volume_device_test.go @@ -0,0 +1,1421 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package kubernetes + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + appsv1 "k8s.io/api/apps/v1" +) + +func TestAccKubernetesStatefulSetV1WIthVolumeDevice_basic(t *testing.T) { + var conf appsv1.StatefulSet + name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + resourceName := "kubernetes_stateful_set_v1.test" + imageName := agnhostImage + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + skipIfClusterVersionLessThan(t, "1.27.0") + skipIfNotRunningInEks(t) + }, + IDRefreshName: resourceName, + IDRefreshIgnore: []string{ + "metadata.0.resource_version", + "spec.0.template.0.spec.0.container.0.resources.0.limits", + "spec.0.template.0.spec.0.container.0.resources.0.requests", + }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckKubernetesStatefulSetV1Destroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesStatefulSetV1ConfigBasicWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "wait_for_rollout", "true"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.resource_version"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.uid"), + resource.TestCheckResourceAttrSet(resourceName, "metadata.0.namespace"), + resource.TestCheckResourceAttr(resourceName, "metadata.0.annotations.%", "2"), + resource.TestCheckResourceAttr(resourceName, "metadata.0.labels.%", "3"), + resource.TestCheckResourceAttr(resourceName, "metadata.0.labels.TestLabelOne", "one"), + resource.TestCheckResourceAttr(resourceName, "metadata.0.labels.TestLabelTwo", "two"), + resource.TestCheckResourceAttr(resourceName, "metadata.0.labels.TestLabelThree", "three"), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.replicas", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.min_ready_seconds", "10"), + resource.TestCheckResourceAttr(resourceName, "spec.0.revision_history_limit", "11"), + resource.TestCheckResourceAttr(resourceName, "spec.0.service_name", "ss-test-service"), + resource.TestCheckResourceAttr(resourceName, "spec.0.persistent_volume_claim_retention_policy.0.when_deleted", "Delete"), + resource.TestCheckResourceAttr(resourceName, "spec.0.persistent_volume_claim_retention_policy.0.when_scaled", "Delete"), + resource.TestCheckResourceAttr(resourceName, "spec.0.selector.0.match_labels.%", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.selector.0.match_labels.app", "ss-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.labels.%", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.labels.app", "ss-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.name", "ss-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.image", imageName), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.0.container_port", "80"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.0.name", "web"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.0.name", "ss-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.0.mount_path", "/work-dir"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_device.0.name", "ss-device-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_device.0.device_path", "/dev/xvda"), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.type", "RollingUpdate"), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.rolling_update.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.rolling_update.0.partition", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.#", "2"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.0.metadata.0.name", "ss-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.0.spec.0.access_modes.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.0.spec.0.access_modes.0", "ReadWriteOnce"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.0.spec.0.resources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.0.spec.0.resources.0.requests.%", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.0.spec.0.resources.0.requests.storage", "1Gi"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.1.metadata.0.name", "ss-device-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.1.spec.0.access_modes.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.1.spec.0.access_modes.0", "ReadWriteOnce"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.1.spec.0.volume_mode", "Block"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.1.spec.0.resources.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.1.spec.0.resources.0.requests.%", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.volume_claim_template.1.spec.0.resources.0.requests.storage", "1Gi"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "wait_for_rollout", + "spec.0.update_strategy.#", + "spec.0.update_strategy.0.%", + "spec.0.update_strategy.0.rolling_update.#", + "spec.0.update_strategy.0.rolling_update.0.%", + "spec.0.update_strategy.0.rolling_update.0.partition", + "spec.0.update_strategy.0.type", + }, + }, + }, + }) +} + +func TestAccKubernetesStatefulSetV1WIthVolumeDevice_basic_idempotency(t *testing.T) { + var conf appsv1.StatefulSet + name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + resourceName := "kubernetes_stateful_set_v1.test" + imageName := agnhostImage + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + skipIfClusterVersionLessThan(t, "1.27.0") + skipIfNotRunningInEks(t) + }, + IDRefreshName: resourceName, + IDRefreshIgnore: []string{ + "metadata.0.resource_version", + "spec.0.template.0.spec.0.container.0.resources.0.limits", + "spec.0.template.0.spec.0.container.0.resources.0.requests", + }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckKubernetesStatefulSetV1Destroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesStatefulSetV1ConfigBasicWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigBasicWithVolumeDevice(name, imageName), + PlanOnly: true, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + ), + }, + }, + }) +} + +func TestAccKubernetesStatefulSetV1WIthVolumeDevice_Update(t *testing.T) { + var conf appsv1.StatefulSet + name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + resourceName := "kubernetes_stateful_set_v1.test" + imageName := agnhostImage + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + skipIfClusterVersionLessThan(t, "1.27.0") + skipIfNotRunningInEks(t) + }, + IDRefreshName: resourceName, + IDRefreshIgnore: []string{ + "metadata.0.resource_version", + "spec.0.template.0.spec.0.container.0.resources.0.limits", + "spec.0.template.0.spec.0.container.0.resources.0.requests", + }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckKubernetesStatefulSetV1Destroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesStatefulSetV1ConfigMinimalWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateImageWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.image", imageName), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdatedSelectorLabelsWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "spec.0.selector.0.match_labels.%", "2"), + resource.TestCheckResourceAttr(resourceName, "spec.0.selector.0.match_labels.app", "ss-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.selector.0.match_labels.layer", "ss-test-layer"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.labels.%", "2"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.labels.app", "ss-test"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.metadata.0.labels.layer", "ss-test-layer"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateReplicasWithVolumeDevice(name, imageName, "3"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.replicas", "3"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateReplicasWithVolumeDevice(name, imageName, ""), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + // NOTE setting to empty should preserve the current replica count + resource.TestCheckResourceAttr(resourceName, "spec.0.replicas", "3"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateReplicasWithVolumeDevice(name, imageName, "0"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.replicas", "0"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateMinReadySecondsWithVolumeDevice(name, imageName, 10), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.min_ready_seconds", "10"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateMinReadySecondsWithVolumeDevice(name, imageName, 0), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.min_ready_seconds", "0"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigRollingUpdatePartitionWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.rolling_update.0.partition", "2"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateStrategyOnDeleteWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.type", "OnDelete"), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.rolling_update.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "spec.0.update_strategy.0.rolling_update.0.partition"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateStrategyOnDeleteWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.type", "OnDelete"), + resource.TestCheckResourceAttr(resourceName, "spec.0.update_strategy.0.rolling_update.#", "0"), + resource.TestCheckNoResourceAttr(resourceName, "spec.0.update_strategy.0.rolling_update.0.partition"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateTemplateWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.#", "2"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.0.container_port", "80"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.0.name", "web"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.1.container_port", "443"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.port.1.name", "secure"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.nameservers.#", "3"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.nameservers.0", "1.1.1.1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.nameservers.1", "8.8.8.8"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.nameservers.2", "9.9.9.9"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.searches.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.searches.0", "kubernetes.io"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.option.#", "2"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.option.0.name", "ndots"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.option.0.value", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.option.1.name", "use-vc"), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_config.0.option.1.value", ""), + resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.dns_policy", "Default"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdatePersistentVolumeClaimRetentionPolicyWithVolumeDevice(name, imageName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name), + resource.TestCheckResourceAttr(resourceName, "spec.0.persistent_volume_claim_retention_policy.0.when_deleted", "Retain"), + resource.TestCheckResourceAttr(resourceName, "spec.0.persistent_volume_claim_retention_policy.0.when_scaled", "Retain"), + ), + }, + }, + }) +} + +func TestAccKubernetesStatefulSetV1WIthVolumeDevice_waitForRollout(t *testing.T) { + var conf1, conf2 appsv1.StatefulSet + imageName := busyboxImage + imageName1 := agnhostImage + name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)) + resourceName := "kubernetes_stateful_set_v1.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + skipIfNotRunningInEks(t) + }, + IDRefreshName: resourceName, + IDRefreshIgnore: []string{ + "spec.0.template.0.spec.0.container.0.resources.0.limits", + "spec.0.template.0.spec.0.container.0.resources.0.requests", + "metadata.0.resource_version", + }, + ProviderFactories: testAccProviderFactories, + CheckDestroy: testAccCheckKubernetesStatefulSetV1Destroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesStatefulSetV1ConfigWaitForRolloutWithVolumeDevice(name, imageName, "true"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf1), + resource.TestCheckResourceAttr(resourceName, "wait_for_rollout", "true"), + ), + }, + { + Config: testAccKubernetesStatefulSetV1ConfigWaitForRolloutWithVolumeDevice(name, imageName1, "false"), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesStatefulSetV1Exists(resourceName, &conf2), + resource.TestCheckResourceAttr(resourceName, "wait_for_rollout", "false"), + testAccCheckKubernetesStatefulSetForceNew(&conf1, &conf2, false), + ), + }, + }, + }) +} + +func testAccKubernetesStatefulSetV1ConfigMinimalWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + name = "%s" + } + spec { + selector { + match_labels = { + app = "ss-test" + } + } + service_name = "ss-test-service" + template { + metadata { + labels = { + app = "ss-test" + } + } + spec { + container { + name = "ss-test" + image = "%s" + command = ["sleep", "300"] + } + termination_grace_period_seconds = 1 + } + } + } +} +`, name, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigBasicWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + min_ready_seconds = 10 + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + persistent_volume_claim_retention_policy { + when_deleted = "Delete" + when_scaled = "Delete" + } + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["test-webserver"] + + port { + name = "web" + container_port = 80 + } + + readiness_probe { + initial_delay_seconds = 3 + period_seconds = 1 + http_get { + path = "/" + port = 80 + } + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 1 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigUpdateImageWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["pause"] + + port { + container_port = "80" + name = "web" + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 1 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigUpdatedSelectorLabelsWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + layer = "ss-test-layer" + } + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + layer = "ss-test-layer" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["pause"] + + port { + container_port = "80" + name = "web" + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 0 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigUpdateReplicasWithVolumeDevice(name, imageName, replicas string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + pod_management_policy = "OrderedReady" + replicas = %q + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["pause"] + + port { + container_port = "80" + name = "web" + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + termination_grace_period_seconds = 1 + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 1 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, replicas, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigUpdateMinReadySecondsWithVolumeDevice(name string, imageName string, minReadySeconds int) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + min_ready_seconds = %d + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["pause"] + + port { + container_port = "80" + name = "web" + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + termination_grace_period_seconds = 1 + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 1 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, minReadySeconds, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigUpdateTemplateWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["pause"] + + port { + container_port = "80" + name = "web" + } + + port { + container_port = "443" + name = "secure" + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + + dns_config { + nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"] + searches = ["kubernetes.io"] + + option { + name = "ndots" + value = 1 + } + + option { + name = "use-vc" + } + } + + dns_policy = "Default" + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 1 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigRollingUpdatePartitionWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["pause"] + + port { + container_port = "80" + name = "web" + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 2 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigUpdateStrategyOnDeleteWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["pause"] + + port { + container_port = "80" + name = "web" + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + } + } + + update_strategy { + type = "OnDelete" + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } + + wait_for_rollout = false +} +`, name, imageName) +} + +func testAccKubernetesStatefulSetV1ConfigWaitForRolloutWithVolumeDevice(name, imageName, waitForRollout string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + name = "%s" + } + + timeouts { + create = "10m" + read = "10m" + update = "10m" + delete = "10m" + } + + spec { + replicas = 2 + + selector { + match_labels = { + app = "ss-test" + } + } + + update_strategy { + type = "RollingUpdate" + } + + service_name = "ss-test-service" + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = "%s" + command = ["/bin/httpd", "-f", "-p", "80"] + args = ["test-webserver"] + + port { + container_port = 80 + } + + readiness_probe { + initial_delay_seconds = 3 + period_seconds = 1 + tcp_socket { + port = 80 + } + } + } + } + } + } + + wait_for_rollout = %s +} +`, name, imageName, waitForRollout) +} + +func testAccKubernetesStatefulSetV1ConfigUpdatePersistentVolumeClaimRetentionPolicyWithVolumeDevice(name, imageName string) string { + return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { + metadata { + annotations = { + TestAnnotationOne = "one" + TestAnnotationTwo = "two" + } + + labels = { + TestLabelOne = "one" + TestLabelTwo = "two" + TestLabelThree = "three" + } + + name = "%s" + } + + spec { + pod_management_policy = "OrderedReady" + replicas = 1 + revision_history_limit = 11 + + selector { + match_labels = { + app = "ss-test" + } + } + + service_name = "ss-test-service" + + persistent_volume_claim_retention_policy { + when_deleted = "Retain" + when_scaled = "Retain" + } + + template { + metadata { + labels = { + app = "ss-test" + } + } + + spec { + container { + name = "ss-test" + image = %q + args = ["test-webserver"] + + port { + name = "web" + container_port = 80 + } + + readiness_probe { + initial_delay_seconds = 5 + http_get { + path = "/" + port = 80 + } + } + + volume_mount { + name = "ss-test" + mount_path = "/work-dir" + } + + volume_device { + name = "ss-device-test" + device_path = "/dev/xvda" + } + } + } + } + + update_strategy { + type = "RollingUpdate" + + rolling_update { + partition = 1 + } + } + + volume_claim_template { + metadata { + name = "ss-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + resources { + requests = { + storage = "1Gi" + } + } + } + } + + volume_claim_template { + metadata { + name = "ss-device-test" + } + + spec { + access_modes = ["ReadWriteOnce"] + volume_mode = "Block" + resources { + requests = { + storage = "1Gi" + } + } + } + } + } +} +`, name, imageName) +} diff --git a/kubernetes/schema_container.go b/kubernetes/schema_container.go index 9d1cdedeb1..499ea0236a 100644 --- a/kubernetes/schema_container.go +++ b/kubernetes/schema_container.go @@ -253,6 +253,21 @@ func volumeMountFields() map[string]*schema.Schema { } } +func volumeDeviceFields() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "device_path": { + Type: schema.TypeString, + Required: true, + Description: "Path within the container at which the volume device should be attached. For example '/dev/xvda'.", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "This must match the Name of a PersistentVolumeClaim.", + }, + } +} + func containerFields(isUpdatable bool) map[string]*schema.Schema { s := map[string]*schema.Schema{ "args": { @@ -651,6 +666,15 @@ func containerFields(isUpdatable bool) map[string]*schema.Schema { Schema: volumeMountFields(), }, }, + "volume_device": { + Type: schema.TypeList, + Optional: true, + ForceNew: !isUpdatable, + Description: "Raw volume devices to attach into the container's filesystem as raw block devices. Cannot be updated.", + Elem: &schema.Resource{ + Schema: volumeDeviceFields(), + }, + }, "working_dir": { Type: schema.TypeString, Optional: true, diff --git a/kubernetes/structures_container.go b/kubernetes/structures_container.go index 15a2533245..e116825050 100644 --- a/kubernetes/structures_container.go +++ b/kubernetes/structures_container.go @@ -308,6 +308,25 @@ func flattenContainerVolumeMounts(in []v1.VolumeMount) []interface{} { return att } +func flattenContainerVolumeDevices(in []v1.VolumeDevice) []interface{} { + att := make([]interface{}, len(in)) + + for i, v := range in { + m := map[string]interface{}{} + + if v.DevicePath != "" { + m["device_path"] = v.DevicePath + } + + if v.Name != "" { + m["name"] = v.Name + } + + att[i] = m + } + return att +} + func flattenContainerEnvs(in []v1.EnvVar) []interface{} { att := make([]interface{}, len(in)) for i, v := range in { @@ -434,6 +453,11 @@ func flattenContainers(in []v1.Container, serviceAccountRegex string) ([]interfa } c["volume_mount"] = flattenContainerVolumeMounts(v.VolumeMounts) } + + if len(v.VolumeDevices) > 0 { + c["volume_device"] = flattenContainerVolumeDevices(v.VolumeDevices) + } + att[i] = c } return att, nil @@ -547,6 +571,10 @@ func expandContainers(ctrs []interface{}) ([]v1.Container, error) { cs[i].VolumeMounts = expandContainerVolumeMounts(v) } + if v, ok := ctr["volume_device"].([]interface{}); ok && len(v) > 0 { + cs[i].VolumeDevices = expandContainerVolumeDevices(v) + } + if v, ok := ctr["working_dir"].(string); ok && v != "" { cs[i].WorkingDir = v } @@ -800,6 +828,23 @@ func expandContainerVolumeMounts(in []interface{}) []v1.VolumeMount { return vmp } +func expandContainerVolumeDevices(in []interface{}) []v1.VolumeDevice { + if len(in) == 0 { + return []v1.VolumeDevice{} + } + volumeDevices := make([]v1.VolumeDevice, len(in)) + for i, c := range in { + p := c.(map[string]interface{}) + if devicePath, ok := p["device_path"]; ok { + volumeDevices[i].DevicePath = devicePath.(string) + } + if name, ok := p["name"]; ok { + volumeDevices[i].Name = name.(string) + } + } + return volumeDevices +} + func expandContainerEnv(in []interface{}) ([]v1.EnvVar, error) { if len(in) == 0 { return []v1.EnvVar{}, nil