From c9a68148bba8bcbd8d97e08fb82ca25da106b9f9 Mon Sep 17 00:00:00 2001 From: Aayush Subramaniam Date: Fri, 17 May 2024 01:02:14 +0530 Subject: [PATCH 1/5] min_ready_seconds parameter added to statefulset Signed-off-by: Aayush Subramaniam --- ...esource_kubernetes_stateful_set_v1_test.go | 104 ++++++++++++++++++ kubernetes/schema_stateful_set_spec.go | 7 ++ kubernetes/structures_stateful_set.go | 16 +++ 3 files changed, 127 insertions(+) diff --git a/kubernetes/resource_kubernetes_stateful_set_v1_test.go b/kubernetes/resource_kubernetes_stateful_set_v1_test.go index aa0d535686..acba27986e 100644 --- a/kubernetes/resource_kubernetes_stateful_set_v1_test.go +++ b/kubernetes/resource_kubernetes_stateful_set_v1_test.go @@ -76,6 +76,7 @@ func TestAccKubernetesStatefulSetV1_basic(t *testing.T) { 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"), @@ -222,6 +223,22 @@ func TestAccKubernetesStatefulSetV1_Update(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "spec.0.replicas", "0"), ), }, + { + Config: testAccKubernetesStatefulSetV1ConfigUpdateMinReadySeconds(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: testAccKubernetesStatefulSetV1ConfigUpdateMinReadySeconds(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: testAccKubernetesStatefulSetV1ConfigRollingUpdatePartition(name, imageName), Check: resource.ComposeAggregateTestCheckFunc( @@ -522,6 +539,7 @@ func testAccKubernetesStatefulSetV1ConfigBasic(name, imageName string) string { } spec { + min_ready_seconds = 10 pod_management_policy = "OrderedReady" replicas = 1 revision_history_limit = 11 @@ -856,6 +874,92 @@ func testAccKubernetesStatefulSetV1ConfigUpdateReplicas(name, imageName, replica `, name, replicas, imageName) } +func testAccKubernetesStatefulSetV1ConfigUpdateMinReadySeconds(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" + } + } + 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" + } + } + } + } + } +} +`, name, minReadySeconds, imageName) +} + func testAccKubernetesStatefulSetV1ConfigUpdateTemplate(name, imageName string) string { return fmt.Sprintf(`resource "kubernetes_stateful_set_v1" "test" { metadata { diff --git a/kubernetes/schema_stateful_set_spec.go b/kubernetes/schema_stateful_set_spec.go index 81b6ce8a5b..c2efec4148 100644 --- a/kubernetes/schema_stateful_set_spec.go +++ b/kubernetes/schema_stateful_set_spec.go @@ -134,6 +134,13 @@ func statefulSetSpecFields() map[string]*schema.Schema { }, }, }, + "min_ready_seconds": { + Type: schema.TypeInt, + Description: "This is an optional field that specifies the minimum number of seconds for which a newly created Pod should be running and ready without any of its containers crashing, for it to be considered available. This field defaults to 0 (the Pod will be considered available as soon as it is ready).", + Optional: true, + Default: 0, + ValidateFunc: validateNonNegativeInteger, + }, } return s } diff --git a/kubernetes/structures_stateful_set.go b/kubernetes/structures_stateful_set.go index b1cbfd8b19..a2361ef279 100644 --- a/kubernetes/structures_stateful_set.go +++ b/kubernetes/structures_stateful_set.go @@ -83,6 +83,10 @@ func expandStatefulSetSpec(s []interface{}) (*v1.StatefulSetSpec, error) { obj.VolumeClaimTemplates = append(obj.VolumeClaimTemplates, *p) } } + + if v, ok := in["min_ready_seconds"].(int); ok { + obj.MinReadySeconds = int32(v) + } return obj, nil } func expandStatefulSetSpecUpdateStrategy(s []interface{}) (*v1.StatefulSetUpdateStrategy, error) { @@ -181,6 +185,7 @@ func flattenStatefulSetSpec(spec v1.StatefulSetSpec, d *schema.ResourceData, met att["persistent_volume_claim_retention_policy"] = flattenStatefulSetSpecPersistentVolumeClaimRetentionPolicy(*spec.PersistentVolumeClaimRetentionPolicy) } + att["min_ready_seconds"] = spec.MinReadySeconds return []interface{}{att}, nil } @@ -290,6 +295,17 @@ func patchStatefulSetSpec(d *schema.ResourceData) (PatchOperations, error) { }) } } + + if d.HasChange("spec.0.min_ready_seconds") { + log.Printf("[TRACE] StatefulSet.Spec.MinReadySeconds has changes") + if v, ok := d.Get("spec.0.min_ready_seconds").(int); ok { + vv := int32(v) + ops = append(ops, &ReplaceOperation{ + Path: "/spec/minReadySeconds", + Value: vv, + }) + } + } return ops, nil } From 85be29e0bc606e81c068d936a5d8500bbbda7850 Mon Sep 17 00:00:00 2001 From: Aayush Subramaniam Date: Fri, 17 May 2024 01:12:16 +0530 Subject: [PATCH 2/5] Documentation Updated Signed-off-by: Aayush Subramaniam --- docs/resources/stateful_set_v1.md | 134 ++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/docs/resources/stateful_set_v1.md b/docs/resources/stateful_set_v1.md index 0b77a7fb5d..95b57a6d6a 100644 --- a/docs/resources/stateful_set_v1.md +++ b/docs/resources/stateful_set_v1.md @@ -2361,6 +2361,7 @@ resource "kubernetes_stateful_set_v1" "prometheus" { } spec { + min_ready_seconds = 10 pod_management_policy = "Parallel" replicas = 1 revision_history_limit = 5 @@ -2534,6 +2535,139 @@ resource "kubernetes_stateful_set_v1" "prometheus" { } ``` +## Argument Reference + +The following arguments are supported: + +* `metadata` - (Required) Standard Kubernetes object metadata. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata) +* `spec` - (Required) Spec defines the specification of the desired behavior of the stateful set. For more info see [Kubernetes reference](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status) +* `wait_for_rollout` - (Optional) Wait for the StatefulSet to finish rolling out. Defaults to `true`. + +## Nested Blocks + +### `metadata` + +#### Arguments + +* `annotations` - (Optional) An unstructured key value map stored with the stateful set that may be used to store arbitrary metadata. + +~> By default, the provider ignores any annotations whose key names end with *kubernetes.io*. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) + +* `generate_name` - (Optional) Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency) +* `labels` - (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the stateful set. **Must match `selector`**. + +~> By default, the provider ignores any labels whose key names end with *kubernetes.io*. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) + +* `name` - (Optional) Name of the stateful set, must be unique. Cannot be updated. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names) +* `namespace` - (Optional) Namespace defines the space within which name of the stateful set must be unique. + +#### Attributes + +* `generation` - A sequence number representing a specific generation of the desired state. +* `resource_version` - An opaque value that represents the internal version of this stateful set that can be used by clients to determine when stateful set has changed. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency) +* `uid` - The unique in time and space value for this stateful set. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids) + +### `spec` + +#### Arguments + +* `pod_management_policy` - (Optional) podManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down. The default policy is `OrderedReady`, where pods are created in increasing order (pod-0, then pod-1, etc) and the controller will wait until each pod is ready before continuing. When scaling down, the pods are removed in the opposite order. The alternative policy is `Parallel` which will create pods in parallel to match the desired scale without waiting, and on scale down will delete all pods at once. *Changing this forces a new resource to be created.* + +* `replicas` - (Optional) The desired number of replicas of the given Template. These are replicas in the sense that they are instantiations of the same Template, but individual replicas also have a consistent identity. If unspecified, defaults to 1. This attribute is a string to be able to distinguish between explicit zero and not specified. + +* `revision_history_limit` - (Optional) The maximum number of revisions that will be maintained in the StatefulSet's revision history. The revision history consists of all revisions not represented by a currently applied StatefulSetSpec version. The default value is 10. *Changing this forces a new resource to be created.* + +* `selector` - (Required) A label query over pods that should match the replica count. **It must match the pod template's labels.** *Changing this forces a new resource to be created.* More info: [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) + +* `service_name` - (Required) The name of the service that governs this StatefulSet. This service must exist before the StatefulSet, and is responsible for the network identity of the set. Pods get DNS/hostnames that follow the pattern: pod-specific-string.serviceName.default.svc.cluster.local where "pod-specific-string" is managed by the StatefulSet controller. *Changing this forces a new resource to be created.* + +* `template` - (Required) The object that describes the pod that will be created if insufficient replicas are detected. Each pod stamped out by the StatefulSet will fulfill this Template, but have a unique identity from the rest of the StatefulSet. + +* `update_strategy` - (Optional) Indicates the StatefulSet update strategy that will be employed to update Pods in the StatefulSet when a revision is made to Template. + +* `volume_claim_template` - (Optional) A list of volume claims that pods are allowed to reference. A claim in this list takes precedence over any volumes in the template, with the same name. *Changing this forces a new resource to be created.* + +* `persistent_volume_claim_retention_policy` - (Optional) The object controls if and how PVCs are deleted during the lifecycle of a StatefulSet. + +* `min_ready_seconds` - (Optional) - This is an optional field that specifies the minimum number of seconds for which a newly created Pod should be running and ready without any of its containers crashing, for it to be considered available. This field defaults to 0 (the Pod will be considered available as soon as it is ready). + +## Nested Blocks + +### `spec.template` + +#### Arguments + +* `metadata` - (Required) Standard object's metadata. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata). + +* `spec` - (Optional) Specification of the desired behavior of the pod. For more info see [Kubernetes reference](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status). + +## Nested Blocks + +### `spec.template.metadata` + +#### Arguments + +These arguments are the same as the for the `metadata` block of a Pod with a few exceptions: + +* When `spec.template.metadata.namespace` does not have a default value, it is empty if not set. + +* The `spec.template.metadata.namespace` is a stub field that does not affect the namespace in which the Pod will be created. The Pod will be created in the same namespace as the main resource. However, modifying this field will force the resource recreation. + +Please see the [Pod resource](pod_v1.html#metadata) for reference. + +### `spec.template.spec` + +#### Arguments + +These arguments are the same as the for the `spec` block of a Pod. + +Please see the [Pod resource](pod_v1.html#spec) for reference. + +## Nested Blocks + +### `spec.update_strategy` + +#### Arguments + +* `type` - (Optional) Indicates the type of the StatefulSetUpdateStrategy. There are two valid update strategies, RollingUpdate and OnDelete. Default is `RollingUpdate`. + +* `rolling_update` - (Optional) The RollingUpdate update strategy will update all Pods in a StatefulSet, in reverse ordinal order, while respecting the StatefulSet guarantees. + +### `spec.update_strategy.rolling_update` + +#### Arguments + +* `partition` - (Optional) Indicates the ordinal at which the StatefulSet should be partitioned. You can perform a phased roll out (e.g. a linear, geometric, or exponential roll out) using a partitioned rolling update in a similar manner to how you rolled out a canary. To perform a phased roll out, set the partition to the ordinal at which you want the controller to pause the update. By setting the partition to 0, you allow the StatefulSet controller to continue the update process. Default value is `0`. + +## Nested Blocks + +### `spec.volume_claim_template` + +One or more `volume_claim_template` blocks can be specified. + +#### Arguments + +Each takes the same attibutes as a `kubernetes_persistent_volume_claim_v1` resource. + +Please see its [documentation](persistent_volume_claim_v1.html#argument-reference) for reference. + +### `spec.persistent_volume_claim_retention_policy` + +#### Arguments + +* `when_deleted` - (Optional) This field controls what happens when a Statefulset is deleted. Default is Retain. + +* `when_scaled` - (Optional) This field controls what happens when a Statefulset is scaled. Default is Retain. + +## Timeouts + +The following [Timeout](/docs/configuration/resources.html#operation-timeouts) configuration options are available for the `kubernetes_stateful_set_v1` resource: + +* `create` - (Default `10 minutes`) Used for creating new StatefulSet +* `read` - (Default `10 minutes`) Used for reading a StatefulSet +* `update` - (Default `10 minutes`) Used for updating a StatefulSet +* `delete` - (Default `10 minutes`) Used for destroying a StatefulSet + ## Import kubernetes_stateful_set_v1 can be imported using its namespace and name, e.g. From 209e68ba8ac85e69a8105068897e839490f2eb51 Mon Sep 17 00:00:00 2001 From: Aayush Subramaniam Date: Sun, 26 May 2024 11:00:54 +0530 Subject: [PATCH 3/5] Added changelog and fixed lint in test --- .changelog/2493.txt | 3 +++ kubernetes/resource_kubernetes_stateful_set_v1_test.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .changelog/2493.txt diff --git a/.changelog/2493.txt b/.changelog/2493.txt new file mode 100644 index 0000000000..c0cc1771f5 --- /dev/null +++ b/.changelog/2493.txt @@ -0,0 +1,3 @@ +```release-note:improvement +resource/resource_kubernetes_stateful_set_v1: Add support for `min_ready_seconds` +``` \ No newline at end of file diff --git a/kubernetes/resource_kubernetes_stateful_set_v1_test.go b/kubernetes/resource_kubernetes_stateful_set_v1_test.go index acba27986e..97cd2b5d69 100644 --- a/kubernetes/resource_kubernetes_stateful_set_v1_test.go +++ b/kubernetes/resource_kubernetes_stateful_set_v1_test.go @@ -539,7 +539,7 @@ func testAccKubernetesStatefulSetV1ConfigBasic(name, imageName string) string { } spec { - min_ready_seconds = 10 + min_ready_seconds = 10 pod_management_policy = "OrderedReady" replicas = 1 revision_history_limit = 11 @@ -892,7 +892,7 @@ func testAccKubernetesStatefulSetV1ConfigUpdateMinReadySeconds(name string, imag } spec { - min_ready_seconds = %d + min_ready_seconds = %d pod_management_policy = "OrderedReady" replicas = 1 revision_history_limit = 11 From dacf23b584d269d2b292157ed8f2667694f5def5 Mon Sep 17 00:00:00 2001 From: Aayush Subramaniam Date: Sun, 26 May 2024 11:28:27 +0530 Subject: [PATCH 4/5] documentation updated --- docs/resources/stateful_set_v1.md | 134 +----------------------------- 1 file changed, 1 insertion(+), 133 deletions(-) diff --git a/docs/resources/stateful_set_v1.md b/docs/resources/stateful_set_v1.md index 95b57a6d6a..f46d62c28d 100644 --- a/docs/resources/stateful_set_v1.md +++ b/docs/resources/stateful_set_v1.md @@ -61,6 +61,7 @@ Optional: - `revision_history_limit` (Number) The maximum number of revisions that will be maintained in the StatefulSet's revision history. The default value is 10. - `update_strategy` (Block List) The strategy that the StatefulSet controller will use to perform updates. (see [below for nested schema](#nestedblock--spec--update_strategy)) - `volume_claim_template` (Block List) A list of claims that pods are allowed to reference. Every claim in this list must have at least one matching (by name) volumeMount in one container in the template. (see [below for nested schema](#nestedblock--spec--volume_claim_template)) +- `min_ready_seconds` - (Optional) - This is an optional field that specifies the minimum number of seconds for which a newly created Pod should be running and ready without any of its containers crashing, for it to be considered available. This field defaults to 0 (the Pod will be considered available as soon as it is ready). ### Nested Schema for `spec.selector` @@ -2535,139 +2536,6 @@ resource "kubernetes_stateful_set_v1" "prometheus" { } ``` -## Argument Reference - -The following arguments are supported: - -* `metadata` - (Required) Standard Kubernetes object metadata. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata) -* `spec` - (Required) Spec defines the specification of the desired behavior of the stateful set. For more info see [Kubernetes reference](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status) -* `wait_for_rollout` - (Optional) Wait for the StatefulSet to finish rolling out. Defaults to `true`. - -## Nested Blocks - -### `metadata` - -#### Arguments - -* `annotations` - (Optional) An unstructured key value map stored with the stateful set that may be used to store arbitrary metadata. - -~> By default, the provider ignores any annotations whose key names end with *kubernetes.io*. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/) - -* `generate_name` - (Optional) Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#idempotency) -* `labels` - (Optional) Map of string keys and values that can be used to organize and categorize (scope and select) the stateful set. **Must match `selector`**. - -~> By default, the provider ignores any labels whose key names end with *kubernetes.io*. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) - -* `name` - (Optional) Name of the stateful set, must be unique. Cannot be updated. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names) -* `namespace` - (Optional) Namespace defines the space within which name of the stateful set must be unique. - -#### Attributes - -* `generation` - A sequence number representing a specific generation of the desired state. -* `resource_version` - An opaque value that represents the internal version of this stateful set that can be used by clients to determine when stateful set has changed. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency) -* `uid` - The unique in time and space value for this stateful set. For more info see [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids) - -### `spec` - -#### Arguments - -* `pod_management_policy` - (Optional) podManagementPolicy controls how pods are created during initial scale up, when replacing pods on nodes, or when scaling down. The default policy is `OrderedReady`, where pods are created in increasing order (pod-0, then pod-1, etc) and the controller will wait until each pod is ready before continuing. When scaling down, the pods are removed in the opposite order. The alternative policy is `Parallel` which will create pods in parallel to match the desired scale without waiting, and on scale down will delete all pods at once. *Changing this forces a new resource to be created.* - -* `replicas` - (Optional) The desired number of replicas of the given Template. These are replicas in the sense that they are instantiations of the same Template, but individual replicas also have a consistent identity. If unspecified, defaults to 1. This attribute is a string to be able to distinguish between explicit zero and not specified. - -* `revision_history_limit` - (Optional) The maximum number of revisions that will be maintained in the StatefulSet's revision history. The revision history consists of all revisions not represented by a currently applied StatefulSetSpec version. The default value is 10. *Changing this forces a new resource to be created.* - -* `selector` - (Required) A label query over pods that should match the replica count. **It must match the pod template's labels.** *Changing this forces a new resource to be created.* More info: [Kubernetes reference](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) - -* `service_name` - (Required) The name of the service that governs this StatefulSet. This service must exist before the StatefulSet, and is responsible for the network identity of the set. Pods get DNS/hostnames that follow the pattern: pod-specific-string.serviceName.default.svc.cluster.local where "pod-specific-string" is managed by the StatefulSet controller. *Changing this forces a new resource to be created.* - -* `template` - (Required) The object that describes the pod that will be created if insufficient replicas are detected. Each pod stamped out by the StatefulSet will fulfill this Template, but have a unique identity from the rest of the StatefulSet. - -* `update_strategy` - (Optional) Indicates the StatefulSet update strategy that will be employed to update Pods in the StatefulSet when a revision is made to Template. - -* `volume_claim_template` - (Optional) A list of volume claims that pods are allowed to reference. A claim in this list takes precedence over any volumes in the template, with the same name. *Changing this forces a new resource to be created.* - -* `persistent_volume_claim_retention_policy` - (Optional) The object controls if and how PVCs are deleted during the lifecycle of a StatefulSet. - -* `min_ready_seconds` - (Optional) - This is an optional field that specifies the minimum number of seconds for which a newly created Pod should be running and ready without any of its containers crashing, for it to be considered available. This field defaults to 0 (the Pod will be considered available as soon as it is ready). - -## Nested Blocks - -### `spec.template` - -#### Arguments - -* `metadata` - (Required) Standard object's metadata. For more info see [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata). - -* `spec` - (Optional) Specification of the desired behavior of the pod. For more info see [Kubernetes reference](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status). - -## Nested Blocks - -### `spec.template.metadata` - -#### Arguments - -These arguments are the same as the for the `metadata` block of a Pod with a few exceptions: - -* When `spec.template.metadata.namespace` does not have a default value, it is empty if not set. - -* The `spec.template.metadata.namespace` is a stub field that does not affect the namespace in which the Pod will be created. The Pod will be created in the same namespace as the main resource. However, modifying this field will force the resource recreation. - -Please see the [Pod resource](pod_v1.html#metadata) for reference. - -### `spec.template.spec` - -#### Arguments - -These arguments are the same as the for the `spec` block of a Pod. - -Please see the [Pod resource](pod_v1.html#spec) for reference. - -## Nested Blocks - -### `spec.update_strategy` - -#### Arguments - -* `type` - (Optional) Indicates the type of the StatefulSetUpdateStrategy. There are two valid update strategies, RollingUpdate and OnDelete. Default is `RollingUpdate`. - -* `rolling_update` - (Optional) The RollingUpdate update strategy will update all Pods in a StatefulSet, in reverse ordinal order, while respecting the StatefulSet guarantees. - -### `spec.update_strategy.rolling_update` - -#### Arguments - -* `partition` - (Optional) Indicates the ordinal at which the StatefulSet should be partitioned. You can perform a phased roll out (e.g. a linear, geometric, or exponential roll out) using a partitioned rolling update in a similar manner to how you rolled out a canary. To perform a phased roll out, set the partition to the ordinal at which you want the controller to pause the update. By setting the partition to 0, you allow the StatefulSet controller to continue the update process. Default value is `0`. - -## Nested Blocks - -### `spec.volume_claim_template` - -One or more `volume_claim_template` blocks can be specified. - -#### Arguments - -Each takes the same attibutes as a `kubernetes_persistent_volume_claim_v1` resource. - -Please see its [documentation](persistent_volume_claim_v1.html#argument-reference) for reference. - -### `spec.persistent_volume_claim_retention_policy` - -#### Arguments - -* `when_deleted` - (Optional) This field controls what happens when a Statefulset is deleted. Default is Retain. - -* `when_scaled` - (Optional) This field controls what happens when a Statefulset is scaled. Default is Retain. - -## Timeouts - -The following [Timeout](/docs/configuration/resources.html#operation-timeouts) configuration options are available for the `kubernetes_stateful_set_v1` resource: - -* `create` - (Default `10 minutes`) Used for creating new StatefulSet -* `read` - (Default `10 minutes`) Used for reading a StatefulSet -* `update` - (Default `10 minutes`) Used for updating a StatefulSet -* `delete` - (Default `10 minutes`) Used for destroying a StatefulSet - ## Import kubernetes_stateful_set_v1 can be imported using its namespace and name, e.g. From 7d6c87dad4d837d612a81401934a09ac64e5c9fe Mon Sep 17 00:00:00 2001 From: BBBmau Date: Mon, 12 Aug 2024 13:02:25 -0700 Subject: [PATCH 5/5] update docs and description to match k8s docs --- docs/resources/stateful_set_v1.md | 2 +- kubernetes/schema_stateful_set_spec.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/stateful_set_v1.md b/docs/resources/stateful_set_v1.md index f46d62c28d..c8b68bc5c6 100644 --- a/docs/resources/stateful_set_v1.md +++ b/docs/resources/stateful_set_v1.md @@ -61,7 +61,7 @@ Optional: - `revision_history_limit` (Number) The maximum number of revisions that will be maintained in the StatefulSet's revision history. The default value is 10. - `update_strategy` (Block List) The strategy that the StatefulSet controller will use to perform updates. (see [below for nested schema](#nestedblock--spec--update_strategy)) - `volume_claim_template` (Block List) A list of claims that pods are allowed to reference. Every claim in this list must have at least one matching (by name) volumeMount in one container in the template. (see [below for nested schema](#nestedblock--spec--volume_claim_template)) -- `min_ready_seconds` - (Optional) - This is an optional field that specifies the minimum number of seconds for which a newly created Pod should be running and ready without any of its containers crashing, for it to be considered available. This field defaults to 0 (the Pod will be considered available as soon as it is ready). +- `min_ready_seconds` - (Optional) - Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0. (pod will be considered available as soon as it is ready) ### Nested Schema for `spec.selector` diff --git a/kubernetes/schema_stateful_set_spec.go b/kubernetes/schema_stateful_set_spec.go index c2efec4148..b7e9a8ca7b 100644 --- a/kubernetes/schema_stateful_set_spec.go +++ b/kubernetes/schema_stateful_set_spec.go @@ -136,7 +136,7 @@ func statefulSetSpecFields() map[string]*schema.Schema { }, "min_ready_seconds": { Type: schema.TypeInt, - Description: "This is an optional field that specifies the minimum number of seconds for which a newly created Pod should be running and ready without any of its containers crashing, for it to be considered available. This field defaults to 0 (the Pod will be considered available as soon as it is ready).", + Description: "Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0. (pod will be considered available as soon as it is ready)", Optional: true, Default: 0, ValidateFunc: validateNonNegativeInteger,