diff --git a/charts/redpanda/configmap.tpl.go b/charts/redpanda/configmap.tpl.go index 624a17028..51393eb0f 100644 --- a/charts/redpanda/configmap.tpl.go +++ b/charts/redpanda/configmap.tpl.go @@ -362,7 +362,7 @@ func rpkNodeConfig(dot *helmette.Dot) map[string]any { result := map[string]any{ "overprovisioned": values.Resources.GetOverProvisionValue(), "enable_memory_locking": ptr.Deref(values.Resources.Memory.EnableMemoryLocking, false), - "additional_start_flags": RedpandaAdditionalStartFlags(dot, RedpandaSMP(dot)), + "additional_start_flags": RedpandaAdditionalStartFlags(dot), "kafka_api": map[string]any{ "brokers": brokerList, "tls": brokerTLS, @@ -613,22 +613,12 @@ func createInternalListenerCfg(port int32) map[string]any { // RedpandaAdditionalStartFlags returns a string list of flags suitable for use // as `additional_start_flags`. User provided flags will override any of those // set by default. -func RedpandaAdditionalStartFlags(dot *helmette.Dot, smp int64) []string { +func RedpandaAdditionalStartFlags(dot *helmette.Dot) []string { values := helmette.Unwrap[Values](dot.Values) // All `additional_start_flags` that are set by the chart. - chartFlags := map[string]string{ - "smp": fmt.Sprintf("%d", int(smp)), - // TODO: The transpiled go template will return float64 from both RedpandaMemory and RedpandaReserveMemory - // By wrapping return value from that function the sprintf will work as expected - // https://github.com/redpanda-data/helm-charts/issues/1249 - "memory": fmt.Sprintf("%dM", int(RedpandaMemory(dot))), - // TODO: The transpiled go template will return float64 from both RedpandaMemory and RedpandaReserveMemory - // By wrapping return value from that function the sprintf will work as expected - // https://github.com/redpanda-data/helm-charts/issues/1249 - "reserve-memory": fmt.Sprintf("%dM", int(RedpandaReserveMemory(dot))), - "default-log-level": values.Logging.LogLevel, - } + chartFlags := values.Resources.GetRedpandaStartFlags() + chartFlags["default-log-level"] = values.Logging.LogLevel // If in developer_mode, don't set reserve-memory. if values.Config.Node["developer_mode"] == true { diff --git a/charts/redpanda/helpers.go b/charts/redpanda/helpers.go index c30a79125..3eba68895 100644 --- a/charts/redpanda/helpers.go +++ b/charts/redpanda/helpers.go @@ -416,18 +416,6 @@ func cleanForK8sWithSuffix(s, suffix string) string { return fmt.Sprintf("%s-%s", s, suffix) } -func RedpandaSMP(dot *helmette.Dot) int64 { - values := helmette.Unwrap[Values](dot.Values) - - coresInMillies := values.Resources.CPU.Cores.MilliValue() - - if coresInMillies < 1000 { - return 1 - } - - return values.Resources.CPU.Cores.Value() -} - // coalesce returns the first non-nil pointer. This is distinct from helmette's // Coalesce which returns the first non-EMPTY pointer. // It accepts a slice as variadic methods are not currently supported in diff --git a/charts/redpanda/memory.go b/charts/redpanda/memory.go deleted file mode 100644 index f9ec854d1..000000000 --- a/charts/redpanda/memory.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2025 Redpanda Data, Inc. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.md -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0 - -// +gotohelm:filename=_memory.go.tpl -package redpanda - -import ( - "fmt" - - "github.com/redpanda-data/redpanda-operator/pkg/gotohelm/helmette" -) - -type MebiBytes = int64 - -// RedpandaReserveMemory will return the amount of memory that Redpanda process will not use from the provided value -// in `--memory` or from the internal Redpanda discovery process. It should be passed to the `--reserve-memory` argument -// of the Redpanda process, see RedpandaAdditionalStartFlags and rpk redpanda start documentation. -// https://docs.redpanda.com/current/reference/rpk/rpk-redpanda/rpk-redpanda-start/ -func RedpandaReserveMemory(dot *helmette.Dot) int64 { - values := helmette.Unwrap[Values](dot.Values) - // This optional `redpanda` object allows you to specify the memory size for both the Redpanda - // process and the underlying reserved memory used by Seastar. - // - // The amount of memory to allocate to a container is determined by the sum of three values: - // 1. Redpanda (at least 2Gi per core, ~80% of the container's total memory) - // 2. Seastar subsystem (200Mi * 0.2% of the container's total memory, 200Mi < x < 1Gi) - // 3. Other container processes (whatever small amount remains) - //if rpMem := values.Resources.Memory.Redpanda; rpMem != nil && rpMem.ReserveMemory != nil { - if rpMem := values.Resources.Memory.Redpanda; rpMem != nil && rpMem.ReserveMemory != nil { - return rpMem.ReserveMemory.Value() / (1024 * 1024) - } - - // If Redpanda is omitted (default behavior), memory sizes are calculated automatically - // based on 0.2% of container memory plus 200 Mi. - return int64(float64(ContainerMemory(dot))*0.002) + 200 -} - -// RedpandaMemory will return the amount of memory for Redpanda process. It should be passed to the -// `--memory` argument of the Redpanda process, see RedpandaAdditionalStartFlags and rpk redpanda start documentation. -// https://docs.redpanda.com/current/reference/rpk/rpk-redpanda/rpk-redpanda-start/ -func RedpandaMemory(dot *helmette.Dot) int64 { - values := helmette.Unwrap[Values](dot.Values) - - memory := int64(0) - containerMemory := ContainerMemory(dot) - // This optional `redpanda` object allows you to specify the memory size for both the Redpanda - // process and the underlying reserved memory used by Seastar. - // - // The amount of memory to allocate to a container is determined by the sum of three values: - // 1. Redpanda (at least 2Gi per core, ~80% of the container's total memory) - // 2. Seastar subsystem (200Mi * 0.2% of the container's total memory, 200Mi < x < 1Gi) - // 3. Other container processes (whatever small amount remains) - if rpMem := values.Resources.Memory.Redpanda; rpMem != nil && rpMem.Memory != nil { - memory = rpMem.Memory.Value() / (1024 * 1024) - } else { - // - memory = int64(float64(containerMemory) * 0.8) - } - - if memory == 0 { - panic("unable to get memory value redpanda-memory") - } - - if memory < 256 { - panic(fmt.Sprintf("%d is below the minimum value for Redpanda", memory)) - } - - if memory+RedpandaReserveMemory(dot) > containerMemory { - panic(fmt.Sprintf("Not enough container memory for Redpanda memory values where Redpanda: %d, reserve: %d, container: %d", memory, RedpandaReserveMemory(dot), containerMemory)) - } - - return memory -} - -// Returns either the min or max container memory values as an integer value of MembiBytes -func ContainerMemory(dot *helmette.Dot) MebiBytes { - values := helmette.Unwrap[Values](dot.Values) - - if values.Resources.Memory.Container.Min != nil { - return values.Resources.Memory.Container.Min.Value() / (1024 * 1024) - } - - return values.Resources.Memory.Container.Max.Value() / (1024 * 1024) -} diff --git a/charts/redpanda/statefulset.go b/charts/redpanda/statefulset.go index 2aa95755e..bb61ef3a0 100644 --- a/charts/redpanda/statefulset.go +++ b/charts/redpanda/statefulset.go @@ -647,7 +647,7 @@ func statefulSetInitContainerConfigurator(dot *helmette.Dot) *corev1.Container { func StatefulSetContainers(dot *helmette.Dot) []corev1.Container { var containers []corev1.Container - containers = append(containers, *statefulSetContainerRedpanda(dot)) + containers = append(containers, statefulSetContainerRedpanda(dot)) if c := statefulSetContainerConfigWatcher(dot); c != nil { containers = append(containers, *c) } @@ -668,12 +668,12 @@ func wrapLifecycleHook(hook string, timeoutSeconds int64, cmd []string) []string return []string{"bash", "-c", fmt.Sprintf("timeout -v %d %s 2>&1 | sed \"s/^/lifecycle-hook %s $(date): /\" | tee /proc/1/fd/1; true", timeoutSeconds, wrapped, hook)} } -func statefulSetContainerRedpanda(dot *helmette.Dot) *corev1.Container { +func statefulSetContainerRedpanda(dot *helmette.Dot) corev1.Container { values := helmette.Unwrap[Values](dot.Values) internalAdvertiseAddress := fmt.Sprintf("%s.%s", "$(SERVICE_NAME)", InternalDomain(dot)) - container := &corev1.Container{ + container := corev1.Container{ Name: Name(dot), Image: fmt.Sprintf(`%s:%s`, values.Image.Repository, Tag(dot)), Env: bootstrapEnvVars(dot, statefulSetRedpandaEnv()), @@ -755,7 +755,7 @@ func statefulSetContainerRedpanda(dot *helmette.Dot) *corev1.Container { VolumeMounts: append(StatefulSetVolumeMounts(dot), templateToVolumeMounts(dot, values.Statefulset.ExtraVolumeMounts)...), SecurityContext: ptr.To(ContainerSecurityContext(dot)), - Resources: corev1.ResourceRequirements{}, + Resources: values.Resources.GetResourceRequirements(), } if !helmette.Dig(values.Config.Node, false, `recovery_mode_enabled`).(bool) { @@ -861,18 +861,6 @@ func statefulSetContainerRedpanda(dot *helmette.Dot) *corev1.Container { ) } - container.Resources.Limits = helmette.UnmarshalInto[corev1.ResourceList](map[string]any{ - "cpu": values.Resources.CPU.Cores, - "memory": values.Resources.Memory.Container.Max, - }) - - if values.Resources.Memory.Container.Min != nil { - container.Resources.Requests = helmette.UnmarshalInto[corev1.ResourceList](map[string]any{ - "cpu": values.Resources.CPU.Cores, - "memory": *values.Resources.Memory.Container.Min, - }) - } - return container } diff --git a/charts/redpanda/templates/_configmap.go.tpl b/charts/redpanda/templates/_configmap.go.tpl index fc500a921..227de82a0 100644 --- a/charts/redpanda/templates/_configmap.go.tpl +++ b/charts/redpanda/templates/_configmap.go.tpl @@ -313,7 +313,7 @@ {{- if (gt ((get (fromJson (include "_shims.len" (dict "a" (list $tls_8) ))) "r") | int) (0 | int)) -}} {{- $schemaRegistryTLS = $tls_8 -}} {{- end -}} -{{- $result := (dict "overprovisioned" (get (fromJson (include "redpanda.RedpandaResources.GetOverProvisionValue" (dict "a" (list $values.resources) ))) "r") "enable_memory_locking" (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $values.resources.memory.enable_memory_locking false) ))) "r") "additional_start_flags" (get (fromJson (include "redpanda.RedpandaAdditionalStartFlags" (dict "a" (list $dot ((get (fromJson (include "redpanda.RedpandaSMP" (dict "a" (list $dot) ))) "r") | int64)) ))) "r") "kafka_api" (dict "brokers" $brokerList "tls" $brokerTLS ) "admin_api" (dict "addresses" (get (fromJson (include "redpanda.Listeners.AdminList" (dict "a" (list $values.listeners ($values.statefulset.replicas | int) (get (fromJson (include "redpanda.Fullname" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.InternalDomain" (dict "a" (list $dot) ))) "r")) ))) "r") "tls" $adminTLS ) "schema_registry" (dict "addresses" (get (fromJson (include "redpanda.Listeners.SchemaRegistryList" (dict "a" (list $values.listeners ($values.statefulset.replicas | int) (get (fromJson (include "redpanda.Fullname" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.InternalDomain" (dict "a" (list $dot) ))) "r")) ))) "r") "tls" $schemaRegistryTLS ) ) -}} +{{- $result := (dict "overprovisioned" (get (fromJson (include "redpanda.RedpandaResources.GetOverProvisionValue" (dict "a" (list $values.resources) ))) "r") "enable_memory_locking" (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $values.resources.memory.enable_memory_locking false) ))) "r") "additional_start_flags" (get (fromJson (include "redpanda.RedpandaAdditionalStartFlags" (dict "a" (list $dot) ))) "r") "kafka_api" (dict "brokers" $brokerList "tls" $brokerTLS ) "admin_api" (dict "addresses" (get (fromJson (include "redpanda.Listeners.AdminList" (dict "a" (list $values.listeners ($values.statefulset.replicas | int) (get (fromJson (include "redpanda.Fullname" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.InternalDomain" (dict "a" (list $dot) ))) "r")) ))) "r") "tls" $adminTLS ) "schema_registry" (dict "addresses" (get (fromJson (include "redpanda.Listeners.SchemaRegistryList" (dict "a" (list $values.listeners ($values.statefulset.replicas | int) (get (fromJson (include "redpanda.Fullname" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.InternalDomain" (dict "a" (list $dot) ))) "r")) ))) "r") "tls" $schemaRegistryTLS ) ) -}} {{- $result = (merge (dict ) $result (get (fromJson (include "redpanda.Tuning.Translate" (dict "a" (list $values.tuning) ))) "r")) -}} {{- $result = (merge (dict ) $result (get (fromJson (include "redpanda.Config.CreateRPKConfiguration" (dict "a" (list $values.config) ))) "r")) -}} {{- $_is_returning = true -}} @@ -541,11 +541,11 @@ {{- define "redpanda.RedpandaAdditionalStartFlags" -}} {{- $dot := (index .a 0) -}} -{{- $smp := (index .a 1) -}} {{- range $_ := (list 1) -}} {{- $_is_returning := false -}} {{- $values := $dot.Values.AsMap -}} -{{- $chartFlags := (dict "smp" (printf "%d" ($smp | int)) "memory" (printf "%dM" (((get (fromJson (include "redpanda.RedpandaMemory" (dict "a" (list $dot) ))) "r") | int64) | int)) "reserve-memory" (printf "%dM" (((get (fromJson (include "redpanda.RedpandaReserveMemory" (dict "a" (list $dot) ))) "r") | int64) | int)) "default-log-level" $values.logging.logLevel ) -}} +{{- $chartFlags := (get (fromJson (include "redpanda.RedpandaResources.GetRedpandaStartFlags" (dict "a" (list $values.resources) ))) "r") -}} +{{- $_ := (set $chartFlags "default-log-level" $values.logging.logLevel) -}} {{- if (eq (index $values.config.node "developer_mode") true) -}} {{- $_ := (unset $chartFlags "reserve-memory") -}} {{- end -}} diff --git a/charts/redpanda/templates/_helpers.go.tpl b/charts/redpanda/templates/_helpers.go.tpl index 3d83d1287..86ffe6e52 100644 --- a/charts/redpanda/templates/_helpers.go.tpl +++ b/charts/redpanda/templates/_helpers.go.tpl @@ -464,23 +464,6 @@ {{- end -}} {{- end -}} -{{- define "redpanda.RedpandaSMP" -}} -{{- $dot := (index .a 0) -}} -{{- range $_ := (list 1) -}} -{{- $_is_returning := false -}} -{{- $values := $dot.Values.AsMap -}} -{{- $coresInMillies := ((get (fromJson (include "_shims.resource_MilliValue" (dict "a" (list $values.resources.cpu.cores) ))) "r") | int64) -}} -{{- if (lt $coresInMillies (1000 | int64)) -}} -{{- $_is_returning = true -}} -{{- (dict "r" (1 | int64)) | toJson -}} -{{- break -}} -{{- end -}} -{{- $_is_returning = true -}} -{{- (dict "r" ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $values.resources.cpu.cores) ))) "r") | int64)) | toJson -}} -{{- break -}} -{{- end -}} -{{- end -}} - {{- define "redpanda.coalesce" -}} {{- $values := (index .a 0) -}} {{- range $_ := (list 1) -}} @@ -542,9 +525,9 @@ {{- $originalKeys := (dict ) -}} {{- $overrideByKey := (dict ) -}} {{- range $_, $el := $override -}} -{{- $_526_key_ok := (get (fromJson (include "_shims.get" (dict "a" (list $el $mergeKey) ))) "r") -}} -{{- $key := (index $_526_key_ok 0) -}} -{{- $ok := (index $_526_key_ok 1) -}} +{{- $_514_key_ok := (get (fromJson (include "_shims.get" (dict "a" (list $el $mergeKey) ))) "r") -}} +{{- $key := (index $_514_key_ok 0) -}} +{{- $ok := (index $_514_key_ok 1) -}} {{- if (not $ok) -}} {{- continue -}} {{- end -}} @@ -555,13 +538,13 @@ {{- end -}} {{- $merged := (coalesce nil) -}} {{- range $_, $el := $original -}} -{{- $_538_key__ := (get (fromJson (include "_shims.get" (dict "a" (list $el $mergeKey) ))) "r") -}} -{{- $key := (index $_538_key__ 0) -}} -{{- $_ := (index $_538_key__ 1) -}} +{{- $_526_key__ := (get (fromJson (include "_shims.get" (dict "a" (list $el $mergeKey) ))) "r") -}} +{{- $key := (index $_526_key__ 0) -}} +{{- $_ := (index $_526_key__ 1) -}} {{- $_ := (set $originalKeys $key true) -}} -{{- $_540_elOverride_7_ok_8 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $overrideByKey $key (coalesce nil)) ))) "r") -}} -{{- $elOverride_7 := (index $_540_elOverride_7_ok_8 0) -}} -{{- $ok_8 := (index $_540_elOverride_7_ok_8 1) -}} +{{- $_528_elOverride_7_ok_8 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $overrideByKey $key (coalesce nil)) ))) "r") -}} +{{- $elOverride_7 := (index $_528_elOverride_7_ok_8 0) -}} +{{- $ok_8 := (index $_528_elOverride_7_ok_8 1) -}} {{- if $ok_8 -}} {{- $merged = (concat (default (list ) $merged) (list (get (fromJson (include $mergeFunc (dict "a" (list $el $elOverride_7) ))) "r"))) -}} {{- else -}} @@ -572,15 +555,15 @@ {{- break -}} {{- end -}} {{- range $_, $el := $override -}} -{{- $_550_key_ok := (get (fromJson (include "_shims.get" (dict "a" (list $el $mergeKey) ))) "r") -}} -{{- $key := (index $_550_key_ok 0) -}} -{{- $ok := (index $_550_key_ok 1) -}} +{{- $_538_key_ok := (get (fromJson (include "_shims.get" (dict "a" (list $el $mergeKey) ))) "r") -}} +{{- $key := (index $_538_key_ok 0) -}} +{{- $ok := (index $_538_key_ok 1) -}} {{- if (not $ok) -}} {{- continue -}} {{- end -}} -{{- $_555___ok_9 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $originalKeys $key false) ))) "r") -}} -{{- $_ := (index $_555___ok_9 0) -}} -{{- $ok_9 := (index $_555___ok_9 1) -}} +{{- $_543___ok_9 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $originalKeys $key false) ))) "r") -}} +{{- $_ := (index $_543___ok_9 0) -}} +{{- $ok_9 := (index $_543___ok_9 1) -}} {{- if $ok_9 -}} {{- continue -}} {{- end -}} diff --git a/charts/redpanda/templates/_memory.go.tpl b/charts/redpanda/templates/_memory.go.tpl deleted file mode 100644 index 015a771b4..000000000 --- a/charts/redpanda/templates/_memory.go.tpl +++ /dev/null @@ -1,63 +0,0 @@ -{{- /* Generated from "memory.go" */ -}} - -{{- define "redpanda.RedpandaReserveMemory" -}} -{{- $dot := (index .a 0) -}} -{{- range $_ := (list 1) -}} -{{- $_is_returning := false -}} -{{- $values := $dot.Values.AsMap -}} -{{- $rpMem_1 := $values.resources.memory.redpanda -}} -{{- if (and (ne (toJson $rpMem_1) "null") (ne (toJson $rpMem_1.reserveMemory) "null")) -}} -{{- $_is_returning = true -}} -{{- (dict "r" ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $rpMem_1.reserveMemory) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64)) | toJson -}} -{{- break -}} -{{- end -}} -{{- $_is_returning = true -}} -{{- (dict "r" ((add (((mulf (((get (fromJson (include "redpanda.ContainerMemory" (dict "a" (list $dot) ))) "r") | int64) | float64) 0.002) | float64) | int64) (200 | int64)) | int64)) | toJson -}} -{{- break -}} -{{- end -}} -{{- end -}} - -{{- define "redpanda.RedpandaMemory" -}} -{{- $dot := (index .a 0) -}} -{{- range $_ := (list 1) -}} -{{- $_is_returning := false -}} -{{- $values := $dot.Values.AsMap -}} -{{- $memory := ((0 | int64) | int64) -}} -{{- $containerMemory := ((get (fromJson (include "redpanda.ContainerMemory" (dict "a" (list $dot) ))) "r") | int64) -}} -{{- $rpMem_2 := $values.resources.memory.redpanda -}} -{{- if (and (ne (toJson $rpMem_2) "null") (ne (toJson $rpMem_2.memory) "null")) -}} -{{- $memory = ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $rpMem_2.memory) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64) -}} -{{- else -}} -{{- $memory = (((mulf ($containerMemory | float64) 0.8) | float64) | int64) -}} -{{- end -}} -{{- if (eq $memory (0 | int64)) -}} -{{- $_ := (fail "unable to get memory value redpanda-memory") -}} -{{- end -}} -{{- if (lt $memory (256 | int64)) -}} -{{- $_ := (fail (printf "%d is below the minimum value for Redpanda" $memory)) -}} -{{- end -}} -{{- if (gt ((add $memory ((get (fromJson (include "redpanda.RedpandaReserveMemory" (dict "a" (list $dot) ))) "r") | int64)) | int64) $containerMemory) -}} -{{- $_ := (fail (printf "Not enough container memory for Redpanda memory values where Redpanda: %d, reserve: %d, container: %d" $memory ((get (fromJson (include "redpanda.RedpandaReserveMemory" (dict "a" (list $dot) ))) "r") | int64) $containerMemory)) -}} -{{- end -}} -{{- $_is_returning = true -}} -{{- (dict "r" $memory) | toJson -}} -{{- break -}} -{{- end -}} -{{- end -}} - -{{- define "redpanda.ContainerMemory" -}} -{{- $dot := (index .a 0) -}} -{{- range $_ := (list 1) -}} -{{- $_is_returning := false -}} -{{- $values := $dot.Values.AsMap -}} -{{- if (ne (toJson $values.resources.memory.container.min) "null") -}} -{{- $_is_returning = true -}} -{{- (dict "r" ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $values.resources.memory.container.min) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64)) | toJson -}} -{{- break -}} -{{- end -}} -{{- $_is_returning = true -}} -{{- (dict "r" ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $values.resources.memory.container.max) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64)) | toJson -}} -{{- break -}} -{{- end -}} -{{- end -}} - diff --git a/charts/redpanda/templates/_statefulset.go.tpl b/charts/redpanda/templates/_statefulset.go.tpl index 1eda80b1e..d7649a101 100644 --- a/charts/redpanda/templates/_statefulset.go.tpl +++ b/charts/redpanda/templates/_statefulset.go.tpl @@ -395,7 +395,7 @@ {{- $_is_returning := false -}} {{- $values := $dot.Values.AsMap -}} {{- $internalAdvertiseAddress := (printf "%s.%s" "$(SERVICE_NAME)" (get (fromJson (include "redpanda.InternalDomain" (dict "a" (list $dot) ))) "r")) -}} -{{- $container := (mustMergeOverwrite (dict "name" "" "resources" (dict ) ) (dict "name" (get (fromJson (include "redpanda.Name" (dict "a" (list $dot) ))) "r") "image" (printf `%s:%s` $values.image.repository (get (fromJson (include "redpanda.Tag" (dict "a" (list $dot) ))) "r")) "env" (get (fromJson (include "redpanda.bootstrapEnvVars" (dict "a" (list $dot (get (fromJson (include "redpanda.statefulSetRedpandaEnv" (dict "a" (list ) ))) "r")) ))) "r") "lifecycle" (mustMergeOverwrite (dict ) (dict "postStart" (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (get (fromJson (include "redpanda.wrapLifecycleHook" (dict "a" (list "post-start" ((div ($values.statefulset.terminationGracePeriodSeconds | int64) (2 | int64)) | int64) (list "bash" "-x" "/var/lifecycle/postStart.sh")) ))) "r") )) )) "preStop" (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (get (fromJson (include "redpanda.wrapLifecycleHook" (dict "a" (list "pre-stop" ((div ($values.statefulset.terminationGracePeriodSeconds | int64) (2 | int64)) | int64) (list "bash" "-x" "/var/lifecycle/preStop.sh")) ))) "r") )) )) )) "startupProbe" (mustMergeOverwrite (dict ) (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (list `/bin/sh` `-c` (join "\n" (list `set -e` (printf `RESULT=$(curl --silent --fail -k -m 5 %s "%s://%s/v1/status/ready")` (get (fromJson (include "redpanda.adminTLSCurlFlags" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminInternalHTTPProtocol" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminApiURLs" (dict "a" (list $dot) ))) "r")) `echo $RESULT` `echo $RESULT | grep ready` ``))) )) )) (dict "initialDelaySeconds" ($values.statefulset.startupProbe.initialDelaySeconds | int) "periodSeconds" ($values.statefulset.startupProbe.periodSeconds | int) "failureThreshold" ($values.statefulset.startupProbe.failureThreshold | int) )) "livenessProbe" (mustMergeOverwrite (dict ) (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (list `/bin/sh` `-c` (printf `curl --silent --fail -k -m 5 %s "%s://%s/v1/status/ready"` (get (fromJson (include "redpanda.adminTLSCurlFlags" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminInternalHTTPProtocol" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminApiURLs" (dict "a" (list $dot) ))) "r"))) )) )) (dict "initialDelaySeconds" ($values.statefulset.livenessProbe.initialDelaySeconds | int) "periodSeconds" ($values.statefulset.livenessProbe.periodSeconds | int) "failureThreshold" ($values.statefulset.livenessProbe.failureThreshold | int) )) "command" (list `rpk` `redpanda` `start` (printf `--advertise-rpc-addr=%s:%d` $internalAdvertiseAddress ($values.listeners.rpc.port | int))) "volumeMounts" (concat (default (list ) (get (fromJson (include "redpanda.StatefulSetVolumeMounts" (dict "a" (list $dot) ))) "r")) (default (list ) (get (fromJson (include "redpanda.templateToVolumeMounts" (dict "a" (list $dot $values.statefulset.extraVolumeMounts) ))) "r"))) "securityContext" (get (fromJson (include "redpanda.ContainerSecurityContext" (dict "a" (list $dot) ))) "r") "resources" (mustMergeOverwrite (dict ) (dict )) )) -}} +{{- $container := (mustMergeOverwrite (dict "name" "" "resources" (dict ) ) (dict "name" (get (fromJson (include "redpanda.Name" (dict "a" (list $dot) ))) "r") "image" (printf `%s:%s` $values.image.repository (get (fromJson (include "redpanda.Tag" (dict "a" (list $dot) ))) "r")) "env" (get (fromJson (include "redpanda.bootstrapEnvVars" (dict "a" (list $dot (get (fromJson (include "redpanda.statefulSetRedpandaEnv" (dict "a" (list ) ))) "r")) ))) "r") "lifecycle" (mustMergeOverwrite (dict ) (dict "postStart" (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (get (fromJson (include "redpanda.wrapLifecycleHook" (dict "a" (list "post-start" ((div ($values.statefulset.terminationGracePeriodSeconds | int64) (2 | int64)) | int64) (list "bash" "-x" "/var/lifecycle/postStart.sh")) ))) "r") )) )) "preStop" (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (get (fromJson (include "redpanda.wrapLifecycleHook" (dict "a" (list "pre-stop" ((div ($values.statefulset.terminationGracePeriodSeconds | int64) (2 | int64)) | int64) (list "bash" "-x" "/var/lifecycle/preStop.sh")) ))) "r") )) )) )) "startupProbe" (mustMergeOverwrite (dict ) (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (list `/bin/sh` `-c` (join "\n" (list `set -e` (printf `RESULT=$(curl --silent --fail -k -m 5 %s "%s://%s/v1/status/ready")` (get (fromJson (include "redpanda.adminTLSCurlFlags" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminInternalHTTPProtocol" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminApiURLs" (dict "a" (list $dot) ))) "r")) `echo $RESULT` `echo $RESULT | grep ready` ``))) )) )) (dict "initialDelaySeconds" ($values.statefulset.startupProbe.initialDelaySeconds | int) "periodSeconds" ($values.statefulset.startupProbe.periodSeconds | int) "failureThreshold" ($values.statefulset.startupProbe.failureThreshold | int) )) "livenessProbe" (mustMergeOverwrite (dict ) (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (list `/bin/sh` `-c` (printf `curl --silent --fail -k -m 5 %s "%s://%s/v1/status/ready"` (get (fromJson (include "redpanda.adminTLSCurlFlags" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminInternalHTTPProtocol" (dict "a" (list $dot) ))) "r") (get (fromJson (include "redpanda.adminApiURLs" (dict "a" (list $dot) ))) "r"))) )) )) (dict "initialDelaySeconds" ($values.statefulset.livenessProbe.initialDelaySeconds | int) "periodSeconds" ($values.statefulset.livenessProbe.periodSeconds | int) "failureThreshold" ($values.statefulset.livenessProbe.failureThreshold | int) )) "command" (list `rpk` `redpanda` `start` (printf `--advertise-rpc-addr=%s:%d` $internalAdvertiseAddress ($values.listeners.rpc.port | int))) "volumeMounts" (concat (default (list ) (get (fromJson (include "redpanda.StatefulSetVolumeMounts" (dict "a" (list $dot) ))) "r")) (default (list ) (get (fromJson (include "redpanda.templateToVolumeMounts" (dict "a" (list $dot $values.statefulset.extraVolumeMounts) ))) "r"))) "securityContext" (get (fromJson (include "redpanda.ContainerSecurityContext" (dict "a" (list $dot) ))) "r") "resources" (get (fromJson (include "redpanda.RedpandaResources.GetResourceRequirements" (dict "a" (list $values.resources) ))) "r") )) -}} {{- if (not (get (fromJson (include "_shims.typeassertion" (dict "a" (list "bool" (dig `recovery_mode_enabled` false $values.config.node)) ))) "r")) -}} {{- $_ := (set $container "readinessProbe" (mustMergeOverwrite (dict ) (mustMergeOverwrite (dict ) (dict "exec" (mustMergeOverwrite (dict ) (dict "command" (list `/bin/sh` `-c` (join "\n" (list `set -x` `RESULT=$(rpk cluster health)` `echo $RESULT` `echo $RESULT | grep 'Healthy:.*true'` ``))) )) )) (dict "initialDelaySeconds" ($values.statefulset.readinessProbe.initialDelaySeconds | int) "timeoutSeconds" ($values.statefulset.readinessProbe.timeoutSeconds | int) "periodSeconds" ($values.statefulset.readinessProbe.periodSeconds | int) "successThreshold" ($values.statefulset.readinessProbe.successThreshold | int) "failureThreshold" ($values.statefulset.readinessProbe.failureThreshold | int) ))) -}} {{- end -}} @@ -443,10 +443,6 @@ {{- end -}} {{- $_ := (set $container "volumeMounts" (concat (default (list ) $container.volumeMounts) (list (mustMergeOverwrite (dict "name" "" "mountPath" "" ) (dict "name" $name "mountPath" (get (fromJson (include "redpanda.Storage.TieredCacheDirectory" (dict "a" (list $values.storage $dot) ))) "r") ))))) -}} {{- end -}} -{{- $_ := (set $container.resources "limits" (dict "cpu" $values.resources.cpu.cores "memory" $values.resources.memory.container.max )) -}} -{{- if (ne (toJson $values.resources.memory.container.min) "null") -}} -{{- $_ := (set $container.resources "requests" (dict "cpu" $values.resources.cpu.cores "memory" $values.resources.memory.container.min )) -}} -{{- end -}} {{- $_is_returning = true -}} {{- (dict "r" $container) | toJson -}} {{- break -}} diff --git a/charts/redpanda/templates/_values.go.tpl b/charts/redpanda/templates/_values.go.tpl index 0a7e0f67e..7833e6c91 100644 --- a/charts/redpanda/templates/_values.go.tpl +++ b/charts/redpanda/templates/_values.go.tpl @@ -102,6 +102,39 @@ {{- end -}} {{- end -}} +{{- define "redpanda.RedpandaResources.GetResourceRequirements" -}} +{{- $rr := (index .a 0) -}} +{{- range $_ := (list 1) -}} +{{- $_is_returning := false -}} +{{- $reqs := (mustMergeOverwrite (dict ) (dict "limits" (dict "cpu" $rr.cpu.cores "memory" $rr.memory.container.max ) )) -}} +{{- if (ne (toJson $rr.memory.container.min) "null") -}} +{{- $_ := (set $reqs "requests" (dict "cpu" $rr.cpu.cores "memory" $rr.memory.container.min )) -}} +{{- end -}} +{{- $_is_returning = true -}} +{{- (dict "r" $reqs) | toJson -}} +{{- break -}} +{{- end -}} +{{- end -}} + +{{- define "redpanda.RedpandaResources.GetRedpandaStartFlags" -}} +{{- $rr := (index .a 0) -}} +{{- range $_ := (list 1) -}} +{{- $_is_returning := false -}} +{{- $flags := (dict ) -}} +{{- $coresInMillies_2 := ((get (fromJson (include "_shims.resource_MilliValue" (dict "a" (list $rr.cpu.cores) ))) "r") | int64) -}} +{{- if (lt $coresInMillies_2 (1000 | int64)) -}} +{{- $_ := (set $flags "smp" (printf "%d" (1 | int))) -}} +{{- else -}} +{{- $_ := (set $flags "smp" (printf "%d" ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $rr.cpu.cores) ))) "r") | int64))) -}} +{{- end -}} +{{- $_ := (set $flags "memory" (printf "%dM" ((get (fromJson (include "redpanda.RedpandaResources.memory" (dict "a" (list $rr) ))) "r") | int64))) -}} +{{- $_ := (set $flags "reserve-memory" (printf "%dM" ((get (fromJson (include "redpanda.RedpandaResources.reserveMemory" (dict "a" (list $rr) ))) "r") | int64))) -}} +{{- $_is_returning = true -}} +{{- (dict "r" $flags) | toJson -}} +{{- break -}} +{{- end -}} +{{- end -}} + {{- define "redpanda.RedpandaResources.GetOverProvisionValue" -}} {{- $rr := (index .a 0) -}} {{- range $_ := (list 1) -}} @@ -117,14 +150,72 @@ {{- end -}} {{- end -}} +{{- define "redpanda.RedpandaResources.memory" -}} +{{- $rr := (index .a 0) -}} +{{- range $_ := (list 1) -}} +{{- $_is_returning := false -}} +{{- $memory := ((0 | int64) | int64) -}} +{{- $containerMemory := ((get (fromJson (include "redpanda.RedpandaResources.containerMemory" (dict "a" (list $rr) ))) "r") | int64) -}} +{{- $rpMem_3 := $rr.memory.redpanda -}} +{{- if (and (ne (toJson $rpMem_3) "null") (ne (toJson $rpMem_3.memory) "null")) -}} +{{- $memory = ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $rpMem_3.memory) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64) -}} +{{- else -}} +{{- $memory = (((mulf ($containerMemory | float64) 0.8) | float64) | int64) -}} +{{- end -}} +{{- if (eq $memory (0 | int64)) -}} +{{- $_ := (fail "unable to get memory value redpanda-memory") -}} +{{- end -}} +{{- if (lt $memory (256 | int64)) -}} +{{- $_ := (fail (printf "%d is below the minimum value for Redpanda" $memory)) -}} +{{- end -}} +{{- if (gt ((add $memory ((get (fromJson (include "redpanda.RedpandaResources.reserveMemory" (dict "a" (list $rr) ))) "r") | int64)) | int64) $containerMemory) -}} +{{- $_ := (fail (printf "Not enough container memory for Redpanda memory values where Redpanda: %d, reserve: %d, container: %d" $memory ((get (fromJson (include "redpanda.RedpandaResources.reserveMemory" (dict "a" (list $rr) ))) "r") | int64) $containerMemory)) -}} +{{- end -}} +{{- $_is_returning = true -}} +{{- (dict "r" $memory) | toJson -}} +{{- break -}} +{{- end -}} +{{- end -}} + +{{- define "redpanda.RedpandaResources.reserveMemory" -}} +{{- $rr := (index .a 0) -}} +{{- range $_ := (list 1) -}} +{{- $_is_returning := false -}} +{{- $rpMem_4 := $rr.memory.redpanda -}} +{{- if (and (ne (toJson $rpMem_4) "null") (ne (toJson $rpMem_4.reserveMemory) "null")) -}} +{{- $_is_returning = true -}} +{{- (dict "r" ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $rpMem_4.reserveMemory) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64)) | toJson -}} +{{- break -}} +{{- end -}} +{{- $_is_returning = true -}} +{{- (dict "r" ((add (((mulf (((get (fromJson (include "redpanda.RedpandaResources.containerMemory" (dict "a" (list $rr) ))) "r") | int64) | float64) 0.002) | float64) | int64) (200 | int64)) | int64)) | toJson -}} +{{- break -}} +{{- end -}} +{{- end -}} + +{{- define "redpanda.RedpandaResources.containerMemory" -}} +{{- $rr := (index .a 0) -}} +{{- range $_ := (list 1) -}} +{{- $_is_returning := false -}} +{{- if (ne (toJson $rr.memory.container.min) "null") -}} +{{- $_is_returning = true -}} +{{- (dict "r" ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $rr.memory.container.min) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64)) | toJson -}} +{{- break -}} +{{- end -}} +{{- $_is_returning = true -}} +{{- (dict "r" ((div ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $rr.memory.container.max) ))) "r") | int64) ((mul (1024 | int) (1024 | int)))) | int64)) | toJson -}} +{{- break -}} +{{- end -}} +{{- end -}} + {{- define "redpanda.Storage.IsTieredStorageEnabled" -}} {{- $s := (index .a 0) -}} {{- range $_ := (list 1) -}} {{- $_is_returning := false -}} {{- $conf := (get (fromJson (include "redpanda.Storage.GetTieredStorageConfig" (dict "a" (list $s) ))) "r") -}} -{{- $_406_b_ok := (get (fromJson (include "_shims.dicttest" (dict "a" (list $conf "cloud_storage_enabled" (coalesce nil)) ))) "r") -}} -{{- $b := (index $_406_b_ok 0) -}} -{{- $ok := (index $_406_b_ok 1) -}} +{{- $_514_b_ok := (get (fromJson (include "_shims.dicttest" (dict "a" (list $conf "cloud_storage_enabled" (coalesce nil)) ))) "r") -}} +{{- $b := (index $_514_b_ok 0) -}} +{{- $ok := (index $_514_b_ok 1) -}} {{- $_is_returning = true -}} {{- (dict "r" (and $ok (get (fromJson (include "_shims.typeassertion" (dict "a" (list "bool" $b) ))) "r"))) | toJson -}} {{- break -}} @@ -169,21 +260,21 @@ {{- range $_ := (list 1) -}} {{- $_is_returning := false -}} {{- $values := $dot.Values.AsMap -}} -{{- $_435_dir_2_ok_3 := (get (fromJson (include "_shims.typetest" (dict "a" (list "string" (index $values.config.node "cloud_storage_cache_directory") "") ))) "r") -}} -{{- $dir_2 := (index $_435_dir_2_ok_3 0) -}} -{{- $ok_3 := (index $_435_dir_2_ok_3 1) -}} -{{- if $ok_3 -}} +{{- $_543_dir_5_ok_6 := (get (fromJson (include "_shims.typetest" (dict "a" (list "string" (index $values.config.node "cloud_storage_cache_directory") "") ))) "r") -}} +{{- $dir_5 := (index $_543_dir_5_ok_6 0) -}} +{{- $ok_6 := (index $_543_dir_5_ok_6 1) -}} +{{- if $ok_6 -}} {{- $_is_returning = true -}} -{{- (dict "r" $dir_2) | toJson -}} +{{- (dict "r" $dir_5) | toJson -}} {{- break -}} {{- end -}} {{- $tieredConfig := (get (fromJson (include "redpanda.Storage.GetTieredStorageConfig" (dict "a" (list $values.storage) ))) "r") -}} -{{- $_444_dir_4_ok_5 := (get (fromJson (include "_shims.typetest" (dict "a" (list "string" (index $tieredConfig "cloud_storage_cache_directory") "") ))) "r") -}} -{{- $dir_4 := (index $_444_dir_4_ok_5 0) -}} -{{- $ok_5 := (index $_444_dir_4_ok_5 1) -}} -{{- if $ok_5 -}} +{{- $_552_dir_7_ok_8 := (get (fromJson (include "_shims.typetest" (dict "a" (list "string" (index $tieredConfig "cloud_storage_cache_directory") "") ))) "r") -}} +{{- $dir_7 := (index $_552_dir_7_ok_8 0) -}} +{{- $ok_8 := (index $_552_dir_7_ok_8 1) -}} +{{- if $ok_8 -}} {{- $_is_returning = true -}} -{{- (dict "r" $dir_4) | toJson -}} +{{- (dict "r" $dir_7) | toJson -}} {{- break -}} {{- end -}} {{- $_is_returning = true -}} @@ -280,9 +371,9 @@ {{- $result := (dict ) -}} {{- $s := (toJson $t) -}} {{- $tune := (fromJson $s) -}} -{{- $_670_m_ok := (get (fromJson (include "_shims.typetest" (dict "a" (list (printf "map[%s]%s" "string" "interface {}") $tune (coalesce nil)) ))) "r") -}} -{{- $m := (index $_670_m_ok 0) -}} -{{- $ok := (index $_670_m_ok 1) -}} +{{- $_778_m_ok := (get (fromJson (include "_shims.typetest" (dict "a" (list (printf "map[%s]%s" "string" "interface {}") $tune (coalesce nil)) ))) "r") -}} +{{- $m := (index $_778_m_ok 0) -}} +{{- $ok := (index $_778_m_ok 1) -}} {{- if (not $ok) -}} {{- $_is_returning = true -}} {{- (dict "r" (dict )) | toJson -}} @@ -418,10 +509,10 @@ {{- $seen := (dict ) -}} {{- $deduped := (coalesce nil) -}} {{- range $_, $item := $items -}} -{{- $_787___ok_6 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $seen $item.key false) ))) "r") -}} -{{- $_ := (index $_787___ok_6 0) -}} -{{- $ok_6 := (index $_787___ok_6 1) -}} -{{- if $ok_6 -}} +{{- $_895___ok_9 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $seen $item.key false) ))) "r") -}} +{{- $_ := (index $_895___ok_9 0) -}} +{{- $ok_9 := (index $_895___ok_9 1) -}} +{{- if $ok_9 -}} {{- continue -}} {{- end -}} {{- $deduped = (concat (default (list ) $deduped) (list $item)) -}} @@ -473,9 +564,9 @@ {{- $name := (index .a 1) -}} {{- range $_ := (list 1) -}} {{- $_is_returning := false -}} -{{- $_878_cert_ok := (get (fromJson (include "_shims.dicttest" (dict "a" (list $m $name (dict "enabled" (coalesce nil) "caEnabled" false "applyInternalDNSNames" (coalesce nil) "duration" "" "issuerRef" (coalesce nil) "secretRef" (coalesce nil) "clientSecretRef" (coalesce nil) )) ))) "r") -}} -{{- $cert := (index $_878_cert_ok 0) -}} -{{- $ok := (index $_878_cert_ok 1) -}} +{{- $_986_cert_ok := (get (fromJson (include "_shims.dicttest" (dict "a" (list $m $name (dict "enabled" (coalesce nil) "caEnabled" false "applyInternalDNSNames" (coalesce nil) "duration" "" "issuerRef" (coalesce nil) "secretRef" (coalesce nil) "clientSecretRef" (coalesce nil) )) ))) "r") -}} +{{- $cert := (index $_986_cert_ok 0) -}} +{{- $ok := (index $_986_cert_ok 1) -}} {{- if (not $ok) -}} {{- $_ := (fail (printf "Certificate %q referenced, but not found in the tls.certs map" $name)) -}} {{- end -}} @@ -823,9 +914,9 @@ {{- if $saslEnabled -}} {{- $_ := (set $internal "authentication_method" "http_basic") -}} {{- end -}} -{{- $am_7 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} -{{- if (ne $am_7 "") -}} -{{- $_ := (set $internal "authentication_method" $am_7) -}} +{{- $am_10 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} +{{- if (ne $am_10 "") -}} +{{- $_ := (set $internal "authentication_method" $am_10) -}} {{- end -}} {{- $result := (list $internal) -}} {{- range $k, $l := $l.external -}} @@ -836,9 +927,9 @@ {{- if $saslEnabled -}} {{- $_ := (set $listener "authentication_method" "http_basic") -}} {{- end -}} -{{- $am_8 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} -{{- if (ne $am_8 "") -}} -{{- $_ := (set $listener "authentication_method" $am_8) -}} +{{- $am_11 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} +{{- if (ne $am_11 "") -}} +{{- $_ := (set $listener "authentication_method" $am_11) -}} {{- end -}} {{- $result = (concat (default (list ) $result) (list $listener)) -}} {{- end -}} @@ -921,9 +1012,9 @@ {{- if (get (fromJson (include "redpanda.Auth.IsSASLEnabled" (dict "a" (list $auth) ))) "r") -}} {{- $_ := (set $internal "authentication_method" "sasl") -}} {{- end -}} -{{- $am_9 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} -{{- if (ne $am_9 "") -}} -{{- $_ := (set $internal "authentication_method" $am_9) -}} +{{- $am_12 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} +{{- if (ne $am_12 "") -}} +{{- $_ := (set $internal "authentication_method" $am_12) -}} {{- end -}} {{- $kafka := (list $internal) -}} {{- range $k, $l := $l.external -}} @@ -934,9 +1025,9 @@ {{- if (get (fromJson (include "redpanda.Auth.IsSASLEnabled" (dict "a" (list $auth) ))) "r") -}} {{- $_ := (set $listener "authentication_method" "sasl") -}} {{- end -}} -{{- $am_10 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} -{{- if (ne $am_10 "") -}} -{{- $_ := (set $listener "authentication_method" $am_10) -}} +{{- $am_13 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} +{{- if (ne $am_13 "") -}} +{{- $_ := (set $listener "authentication_method" $am_13) -}} {{- end -}} {{- $kafka = (concat (default (list ) $kafka) (list $listener)) -}} {{- end -}} @@ -1068,9 +1159,9 @@ {{- if $saslEnabled -}} {{- $_ := (set $internal "authentication_method" "http_basic") -}} {{- end -}} -{{- $am_11 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} -{{- if (ne $am_11 "") -}} -{{- $_ := (set $internal "authentication_method" $am_11) -}} +{{- $am_14 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} +{{- if (ne $am_14 "") -}} +{{- $_ := (set $internal "authentication_method" $am_14) -}} {{- end -}} {{- $result := (list $internal) -}} {{- range $k, $l := $l.external -}} @@ -1081,9 +1172,9 @@ {{- if $saslEnabled -}} {{- $_ := (set $listener "authentication_method" "http_basic") -}} {{- end -}} -{{- $am_12 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} -{{- if (ne $am_12 "") -}} -{{- $_ := (set $listener "authentication_method" $am_12) -}} +{{- $am_15 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $l.authenticationMethod "") ))) "r") -}} +{{- if (ne $am_15 "") -}} +{{- $_ := (set $listener "authentication_method" $am_15) -}} {{- end -}} {{- $result = (concat (default (list ) $result) (list $listener)) -}} {{- end -}} @@ -1218,10 +1309,10 @@ {{- $result := (dict ) -}} {{- range $k, $v := $c -}} {{- if (not (empty $v)) -}} -{{- $_1712___ok_13 := (get (fromJson (include "_shims.asnumeric" (dict "a" (list $v) ))) "r") -}} -{{- $_ := ((index $_1712___ok_13 0) | float64) -}} -{{- $ok_13 := (index $_1712___ok_13 1) -}} -{{- if $ok_13 -}} +{{- $_1820___ok_16 := (get (fromJson (include "_shims.asnumeric" (dict "a" (list $v) ))) "r") -}} +{{- $_ := ((index $_1820___ok_16 0) | float64) -}} +{{- $ok_16 := (index $_1820___ok_16 1) -}} +{{- if $ok_16 -}} {{- $_ := (set $result $k $v) -}} {{- else -}}{{- if (kindIs "bool" $v) -}} {{- $_ := (set $result $k $v) -}} @@ -1246,11 +1337,11 @@ {{- $_is_returning := false -}} {{- $result := (dict ) -}} {{- range $k, $v := $c -}} -{{- $_1732_b_14_ok_15 := (get (fromJson (include "_shims.typetest" (dict "a" (list "bool" $v false) ))) "r") -}} -{{- $b_14 := (index $_1732_b_14_ok_15 0) -}} -{{- $ok_15 := (index $_1732_b_14_ok_15 1) -}} -{{- if $ok_15 -}} -{{- $_ := (set $result $k $b_14) -}} +{{- $_1840_b_17_ok_18 := (get (fromJson (include "_shims.typetest" (dict "a" (list "bool" $v false) ))) "r") -}} +{{- $b_17 := (index $_1840_b_17_ok_18 0) -}} +{{- $ok_18 := (index $_1840_b_17_ok_18 1) -}} +{{- if $ok_18 -}} +{{- $_ := (set $result $k $b_17) -}} {{- continue -}} {{- end -}} {{- if (not (empty $v)) -}} @@ -1291,15 +1382,15 @@ {{- $config := (index .a 1) -}} {{- range $_ := (list 1) -}} {{- $_is_returning := false -}} -{{- $_1777___hasAccessKey := (get (fromJson (include "_shims.dicttest" (dict "a" (list $config "cloud_storage_access_key" (coalesce nil)) ))) "r") -}} -{{- $_ := (index $_1777___hasAccessKey 0) -}} -{{- $hasAccessKey := (index $_1777___hasAccessKey 1) -}} -{{- $_1778___hasSecretKey := (get (fromJson (include "_shims.dicttest" (dict "a" (list $config "cloud_storage_secret_key" (coalesce nil)) ))) "r") -}} -{{- $_ := (index $_1778___hasSecretKey 0) -}} -{{- $hasSecretKey := (index $_1778___hasSecretKey 1) -}} -{{- $_1779___hasSharedKey := (get (fromJson (include "_shims.dicttest" (dict "a" (list $config "cloud_storage_azure_shared_key" (coalesce nil)) ))) "r") -}} -{{- $_ := (index $_1779___hasSharedKey 0) -}} -{{- $hasSharedKey := (index $_1779___hasSharedKey 1) -}} +{{- $_1885___hasAccessKey := (get (fromJson (include "_shims.dicttest" (dict "a" (list $config "cloud_storage_access_key" (coalesce nil)) ))) "r") -}} +{{- $_ := (index $_1885___hasAccessKey 0) -}} +{{- $hasAccessKey := (index $_1885___hasAccessKey 1) -}} +{{- $_1886___hasSecretKey := (get (fromJson (include "_shims.dicttest" (dict "a" (list $config "cloud_storage_secret_key" (coalesce nil)) ))) "r") -}} +{{- $_ := (index $_1886___hasSecretKey 0) -}} +{{- $hasSecretKey := (index $_1886___hasSecretKey 1) -}} +{{- $_1887___hasSharedKey := (get (fromJson (include "_shims.dicttest" (dict "a" (list $config "cloud_storage_azure_shared_key" (coalesce nil)) ))) "r") -}} +{{- $_ := (index $_1887___hasSharedKey 0) -}} +{{- $hasSharedKey := (index $_1887___hasSharedKey 1) -}} {{- $envvars := (coalesce nil) -}} {{- if (and (not $hasAccessKey) (get (fromJson (include "redpanda.SecretRef.IsValid" (dict "a" (list $tsc.accessKey) ))) "r")) -}} {{- $envvars = (concat (default (list ) $envvars) (list (mustMergeOverwrite (dict "name" "" ) (dict "name" "REDPANDA_CLOUD_STORAGE_ACCESS_KEY" "valueFrom" (get (fromJson (include "redpanda.SecretRef.AsSource" (dict "a" (list $tsc.accessKey) ))) "r") )))) -}} @@ -1322,12 +1413,12 @@ {{- $c := (index .a 0) -}} {{- range $_ := (list 1) -}} {{- $_is_returning := false -}} -{{- $_1815___containerExists := (get (fromJson (include "_shims.dicttest" (dict "a" (list $c "cloud_storage_azure_container" (coalesce nil)) ))) "r") -}} -{{- $_ := (index $_1815___containerExists 0) -}} -{{- $containerExists := (index $_1815___containerExists 1) -}} -{{- $_1816___accountExists := (get (fromJson (include "_shims.dicttest" (dict "a" (list $c "cloud_storage_azure_storage_account" (coalesce nil)) ))) "r") -}} -{{- $_ := (index $_1816___accountExists 0) -}} -{{- $accountExists := (index $_1816___accountExists 1) -}} +{{- $_1923___containerExists := (get (fromJson (include "_shims.dicttest" (dict "a" (list $c "cloud_storage_azure_container" (coalesce nil)) ))) "r") -}} +{{- $_ := (index $_1923___containerExists 0) -}} +{{- $containerExists := (index $_1923___containerExists 1) -}} +{{- $_1924___accountExists := (get (fromJson (include "_shims.dicttest" (dict "a" (list $c "cloud_storage_azure_storage_account" (coalesce nil)) ))) "r") -}} +{{- $_ := (index $_1924___accountExists 0) -}} +{{- $accountExists := (index $_1924___accountExists 1) -}} {{- $_is_returning = true -}} {{- (dict "r" (and $containerExists $accountExists)) | toJson -}} {{- break -}} @@ -1338,9 +1429,9 @@ {{- $c := (index .a 0) -}} {{- range $_ := (list 1) -}} {{- $_is_returning := false -}} -{{- $_1821_value_ok := (get (fromJson (include "_shims.dicttest" (dict "a" (list $c `cloud_storage_cache_size` (coalesce nil)) ))) "r") -}} -{{- $value := (index $_1821_value_ok 0) -}} -{{- $ok := (index $_1821_value_ok 1) -}} +{{- $_1929_value_ok := (get (fromJson (include "_shims.dicttest" (dict "a" (list $c `cloud_storage_cache_size` (coalesce nil)) ))) "r") -}} +{{- $value := (index $_1929_value_ok 0) -}} +{{- $ok := (index $_1929_value_ok 1) -}} {{- if (not $ok) -}} {{- $_is_returning = true -}} {{- (dict "r" (coalesce nil)) | toJson -}} @@ -1365,9 +1456,9 @@ {{- if $_is_returning -}} {{- break -}} {{- end -}} -{{- $size_16 := (get (fromJson (include "redpanda.TieredStorageConfig.CloudStorageCacheSize" (dict "a" (list (deepCopy $c)) ))) "r") -}} -{{- if (ne (toJson $size_16) "null") -}} -{{- $_ := (set $config "cloud_storage_cache_size" ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $size_16) ))) "r") | int64)) -}} +{{- $size_19 := (get (fromJson (include "redpanda.TieredStorageConfig.CloudStorageCacheSize" (dict "a" (list (deepCopy $c)) ))) "r") -}} +{{- if (ne (toJson $size_19) "null") -}} +{{- $_ := (set $config "cloud_storage_cache_size" ((get (fromJson (include "_shims.resource_Value" (dict "a" (list $size_19) ))) "r") | int64)) -}} {{- end -}} {{- $_is_returning = true -}} {{- (dict "r" $config) | toJson -}} diff --git a/charts/redpanda/values.go b/charts/redpanda/values.go index c2766f74a..88ef451b3 100644 --- a/charts/redpanda/values.go +++ b/charts/redpanda/values.go @@ -53,6 +53,8 @@ const ( certificateMountPoint = "/etc/tls/certs" ) +type MebiBytes = int64 + // values.go contains a collection of go structs that (loosely) map to // values.yaml and are used for generating values.schema.json. Commented out // struct fields are fields that are valid in the eyes of values.yaml but are @@ -371,6 +373,40 @@ type RedpandaResources struct { } `json:"memory" jsonschema:"required"` } +func (rr *RedpandaResources) GetResourceRequirements() corev1.ResourceRequirements { + // Otherwise fallback to the historical behavior. + reqs := corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + "cpu": rr.CPU.Cores, + "memory": rr.Memory.Container.Max, + }, + } + + if rr.Memory.Container.Min != nil { + reqs.Requests = corev1.ResourceList{ + "cpu": rr.CPU.Cores, + "memory": *rr.Memory.Container.Min, + } + } + + return reqs +} + +func (rr *RedpandaResources) GetRedpandaStartFlags() map[string]string { + flags := map[string]string{} + + if coresInMillies := rr.CPU.Cores.MilliValue(); coresInMillies < 1000 { + flags["smp"] = fmt.Sprintf("%d", 1) + } else { + flags["smp"] = fmt.Sprintf("%d", rr.CPU.Cores.Value()) + } + + flags["memory"] = fmt.Sprintf("%dM", rr.memory()) + flags["reserve-memory"] = fmt.Sprintf("%dM", rr.reserveMemory()) + + return flags +} + func (rr *RedpandaResources) GetOverProvisionValue() bool { if rr.CPU.Cores.MilliValue() < 1000 { return true @@ -379,6 +415,77 @@ func (rr *RedpandaResources) GetOverProvisionValue() bool { return ptr.Deref(rr.CPU.Overprovisioned, false) } +// memory returns the amount of memory for Redpanda process. It should be +// passed to the `--memory` argument of the Redpanda process, see +// RedpandaAdditionalStartFlags and rpk redpanda start documentation. +// +// https://docs.redpanda.com/current/reference/rpk/rpk-redpanda/rpk-redpanda-start/ +func (rr *RedpandaResources) memory() int64 { + memory := int64(0) + containerMemory := rr.containerMemory() + + // This optional `redpanda` object allows you to specify the memory size for both the Redpanda + // process and the underlying reserved memory used by Seastar. + // + // The amount of memory to allocate to a container is determined by the sum of three values: + // 1. Redpanda (at least 2Gi per core, ~80% of the container's total memory) + // 2. Seastar subsystem (200Mi * 0.2% of the container's total memory, 200Mi < x < 1Gi) + // 3. Other container processes (whatever small amount remains) + if rpMem := rr.Memory.Redpanda; rpMem != nil && rpMem.Memory != nil { + memory = rpMem.Memory.Value() / (1024 * 1024) + } else { + memory = int64(float64(containerMemory) * 0.8) + } + + if memory == 0 { + panic("unable to get memory value redpanda-memory") + } + + if memory < 256 { + panic(fmt.Sprintf("%d is below the minimum value for Redpanda", memory)) + } + + if memory+rr.reserveMemory() > containerMemory { + panic(fmt.Sprintf("Not enough container memory for Redpanda memory values where Redpanda: %d, reserve: %d, container: %d", memory, rr.reserveMemory(), containerMemory)) + } + + return memory +} + +// reserveMemory returns the amount of memory that the Redpanda process will +// not use from the provided value in `--memory` or from the internal Redpanda +// discovery process. It should be passed to the `--reserve-memory` argument +// of the Redpanda process, see RedpandaAdditionalStartFlags and rpk redpanda +// start documentation. +// +// https://docs.redpanda.com/current/reference/rpk/rpk-redpanda/rpk-redpanda-start/ +func (rr *RedpandaResources) reserveMemory() int64 { + // This optional `redpanda` object allows you to specify the memory size for both the Redpanda + // process and the underlying reserved memory used by Seastar. + // + // The amount of memory to allocate to a container is determined by the sum of three values: + // 1. Redpanda (at least 2Gi per core, ~80% of the container's total memory) + // 2. Seastar subsystem (200Mi * 0.2% of the container's total memory, 200Mi < x < 1Gi) + // 3. Other container processes (whatever small amount remains) + if rpMem := rr.Memory.Redpanda; rpMem != nil && rpMem.ReserveMemory != nil { + return rpMem.ReserveMemory.Value() / (1024 * 1024) + } + + // If Redpanda is omitted (default behavior), memory sizes are calculated automatically + // based on 0.2% of container memory plus 200 Mi. + return int64(float64(rr.containerMemory())*0.002) + 200 +} + +// containerMemory returns either the min or max container memory values as an +// integer value of MembiBytes. +func (rr *RedpandaResources) containerMemory() MebiBytes { + if rr.Memory.Container.Min != nil { + return rr.Memory.Container.Min.Value() / (1024 * 1024) + } + + return rr.Memory.Container.Max.Value() / (1024 * 1024) +} + type Storage struct { HostPath string `json:"hostPath" jsonschema:"required"` Tiered Tiered `json:"tiered" jsonschema:"required"`