From 5b747c88e92b77244f916f3b36a5d2a60c8c6cbf Mon Sep 17 00:00:00 2001 From: Wagner Sartori Junior Date: Thu, 28 Sep 2023 16:50:49 +0200 Subject: [PATCH] Fix #2302 Add hugepages support to emptyDir --- kubernetes/schema_pod_spec.go | 4 ++-- kubernetes/validators.go | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/kubernetes/schema_pod_spec.go b/kubernetes/schema_pod_spec.go index d5d2ab71bf..8c2f7f1156 100644 --- a/kubernetes/schema_pod_spec.go +++ b/kubernetes/schema_pod_spec.go @@ -669,11 +669,11 @@ func volumeSchema(isUpdatable bool) *schema.Resource { Schema: map[string]*schema.Schema{ "medium": { Type: schema.TypeString, - Description: `What type of storage medium should back this directory. The default is "" which means to use the node's default medium. Must be an empty string (default) or Memory. More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir`, + Description: `What type of storage medium should back this directory. The default is "" which means to use the node's default medium. Must be an empty string (default), Memory, HugePages-. More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir`, Optional: true, Default: "", ForceNew: !isUpdatable, - ValidateFunc: validateAttributeValueIsIn([]string{"", "Memory"}), + ValidateFunc: validateAttributeValueIsInAndContain([]string{"", "Memory", "HugePages-"}), }, "size_limit": { Type: schema.TypeString, diff --git a/kubernetes/validators.go b/kubernetes/validators.go index 5a8b073069..ebd9d5a284 100644 --- a/kubernetes/validators.go +++ b/kubernetes/validators.go @@ -268,6 +268,26 @@ func validateAttributeValueIsIn(validValues []string) schema.SchemaValidateFunc } } +func validateAttributeValueIsInAndContain(validValues []string) schema.SchemaValidateFunc { + return func(v interface{}, k string) (ws []string, errors []error) { + input := v.(string) + isValid := false + for _, s := range validValues { + if strings.Contains(input, s) { + isValid = true + break + } + } + if !isValid { + errors = append(errors, fmt.Errorf( + "%q must contain a value containing %#v, got %q", + k, validValues, input)) + } + return + + } +} + func validateTypeStringNullableIntOrPercent(v interface{}, key string) (ws []string, es []error) { value, ok := v.(string) if !ok {