Skip to content

Commit

Permalink
*: remove all usages of deepCopy
Browse files Browse the repository at this point in the history
Recent exploration into the performance of `helm template` has shown that that
VAST majority of execution time is due to calls to `deepCopy`. 50% is executing
deepCopy itself and the other 50% is go's GC attempting to keep up with the
massive allocations and cleanups.

Upon auditing our charts, it became apparent that most usages of `deepCopy` are
not required with many instances not being used at all.

This commit removes all usages of `deepCopy` across all charts in this
repository.
  • Loading branch information
chrisseto committed May 20, 2024
1 parent 2f034c2 commit 5d44bb5
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 85 deletions.
3 changes: 1 addition & 2 deletions charts/connectors/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}
{{- if .Values.deployment.create -}}
{{- $root := deepCopy . }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -234,7 +233,7 @@ spec:
topologySpreadConstraints:
{{- range $spread := .Values.deployment.topologySpreadConstraints }}
- labelSelector:
matchLabels: {{ include "connectors-pod-labels" $root | nindent 14 }}
matchLabels: {{ include "connectors-pod-labels" $ | nindent 14 }}
maxSkew: {{ $spread.maxSkew }}
topologyKey: {{ $spread.topologyKey }}
whenUnsatisfiable: {{ $spread.whenUnsatisfiable }}
Expand Down
15 changes: 6 additions & 9 deletions charts/redpanda/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ Any rpk command that's given to the user in in this file must be defined in _exa
-}}

{{- $anySASL := (include "sasl-enabled" . | fromJson).bool }}
{{- $rpk := deepCopy . }}

{{- $_ := set $rpk "rpk" "rpk" }}

Congratulations on installing {{ .Chart.Name }}!

Expand Down Expand Up @@ -82,26 +79,26 @@ Try some sample commands:
{{- if and $anySASL }}
Create a user:

{{ include "rpk-acl-user-create" $rpk }}
{{ include "rpk-acl-user-create" . }}

Give the user permissions:

{{ include "rpk-acl-create" $rpk }}
{{ include "rpk-acl-create" . }}

{{- end }}

Get the api status:

{{ include "rpk-cluster-info" $rpk }}
{{ include "rpk-cluster-info" . }}

Create a topic

{{ include "rpk-topic-create" $rpk }}
{{ include "rpk-topic-create" . }}

Describe the topic:

{{ include "rpk-topic-describe" $rpk }}
{{ include "rpk-topic-describe" . }}

Delete the topic:

{{ include "rpk-topic-delete" $rpk }}
{{ include "rpk-topic-delete" . }}
12 changes: 6 additions & 6 deletions charts/redpanda/templates/_example-commands.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@ and tested in a test.
{{/* tested in tests/test-kafka-sasl-status.yaml */}}
{{- define "rpk-acl-user-create" -}}
{{ .rpk }} acl user create myuser --new-password changeme --mechanism {{ include "sasl-mechanism" . }}
rpk acl user create myuser --new-password changeme --mechanism {{ include "sasl-mechanism" . }}
{{- end -}}
{{/* tested in tests/test-kafka-sasl-status.yaml */}}
{{- define "rpk-acl-create" -}}
{{ .rpk }} acl create --allow-principal 'myuser' --allow-host '*' --operation all --topic 'test-topic'
rpk acl create --allow-principal 'myuser' --allow-host '*' --operation all --topic 'test-topic'
{{- end -}}
{{/* tested in tests/test-kafka-sasl-status.yaml */}}
{{- define "rpk-cluster-info" -}}
{{ .rpk }} cluster info
rpk cluster info
{{- end -}}
{{/* tested in tests/test-kafka-sasl-status.yaml */}}
{{- define "rpk-topic-create" -}}
{{ .rpk }} topic create test-topic -p 3 -r {{ min (int64 .Values.statefulset.replicas) 3 }}
rpk topic create test-topic -p 3 -r {{ min (int64 .Values.statefulset.replicas) 3 }}
{{- end -}}
{{/* tested in tests/test-kafka-sasl-status.yaml */}}
{{- define "rpk-topic-describe" -}}
{{ .rpk }} topic describe test-topic
rpk topic describe test-topic
{{- end -}}
{{/* tested in tests/test-kafka-sasl-status.yaml */}}
{{- define "rpk-topic-delete" -}}
{{ .rpk }} topic delete test-topic
rpk topic delete test-topic
{{- end -}}
7 changes: 3 additions & 4 deletions charts/redpanda/templates/cert-issuers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/}}
{{- if (include "tls-enabled" . | fromJson).bool }}
{{- $root := deepCopy . }}
{{- $release := .Release }}
{{- $values := .Values }}
{{- range $name, $data := $values.tls.certs }}
Expand All @@ -34,7 +33,7 @@ metadata:
name: {{ template "redpanda.fullname" $ }}-{{ $name }}-selfsigned-issuer
namespace: {{ $release.Namespace | quote }}
labels:
{{- with include "full.labels" $root }}
{{- with include "full.labels" $ }}
{{- . | nindent 4 }}
{{- end }}
spec:
Expand All @@ -48,7 +47,7 @@ metadata:
name: {{ template "redpanda.fullname" $ }}-{{ $name }}-root-issuer
namespace: {{ $release.Namespace | quote }}
labels:
{{- with include "full.labels" $root }}
{{- with include "full.labels" $ }}
{{- . | nindent 4 }}
{{- end }}
spec:
Expand All @@ -62,7 +61,7 @@ metadata:
name: {{ template "redpanda.fullname" $ }}-{{ $name }}-root-certificate
namespace: {{ $release.Namespace | quote }}
labels:
{{- with include "full.labels" $root }}
{{- with include "full.labels" $ }}
{{- . | nindent 4 }}
{{- end }}
spec:
Expand Down
3 changes: 1 addition & 2 deletions charts/redpanda/templates/connectors/connectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ limitations under the License.

{{ $connectorsValues := merge $connectorsValues (dict "Values" (dict "deployment" (dict "create" (not .Values.connectors.deployment.create)))) }}
{{ $connectorsValues := merge $connectorsValues (dict "Values" (dict "test" (dict "create" (not .Values.connectors.test.create)))) }}
{{ $helmVars := deepCopy .Subcharts.connectors }}
{{ $helmVars := merge $connectorsValues $helmVars }}
{{ $helmVars := merge $connectorsValues .Subcharts.connectors }}
{{ include (print .Subcharts.connectors.Template.BasePath "/deployment.yaml") $helmVars }}
---
{{ include (print .Subcharts.connectors.Template.BasePath "/tests/01-mm2-values.yaml") $helmVars }}
Expand Down
25 changes: 10 additions & 15 deletions charts/redpanda/templates/console/configmap-and-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}
{{ $values := .Values }}

{{/* Secret */}}
{{ $secretConfig := dict ( dict
Expand All @@ -39,8 +38,7 @@ limitations under the License.
"secret" $secretConfig
)}}

{{ $console := deepCopy .Subcharts.console }}
{{ $console = merge $config $console }}
{{ $console := merge $config .Subcharts.console }}
---
{{ include (print .Subcharts.console.Template.BasePath "/secret.yaml") $console }}
{{ end }}
Expand All @@ -56,7 +54,7 @@ limitations under the License.
{{/* brokers */}}
{{ $kafkaBrokers := list }}
{{ range (include "seed-server-list" . | mustFromJson) }}
{{ $kafkaBrokers = append $kafkaBrokers (printf "%s:%d" . (int $values.listeners.kafka.port)) }}
{{ $kafkaBrokers = append $kafkaBrokers (printf "%s:%d" . (int $.Values.listeners.kafka.port)) }}
{{ end }}

{{/* sasl */}}
Expand All @@ -73,7 +71,7 @@ limitations under the License.
{{ if (include "schemaRegistry-internal-tls-enabled" . | fromJson).bool }}
{{ $proto = "https" }}
{{ end }}
{{ $port := int $values.listeners.schemaRegistry.port }}
{{ $port := int $.Values.listeners.schemaRegistry.port }}
{{ range (include "seed-server-list" . | mustFromJson) }}
{{ $urls = append $urls (printf "%s://%s:%d" $proto . $port) }}
{{ end }}
Expand All @@ -83,16 +81,15 @@ limitations under the License.

{{ $connectConfig := dict }}
{{ if .Values.connectors.enabled }}
{{ $connectorsValues := deepCopy .Subcharts.connectors }}
{{ $connectorsValues = merge $connectorsValues .Values.connectors }}
{{ $connectorsValues = merge (dict) $.Subcharts.connector .Values.connectors }}
{{/* Connector */}}
{{/* Currently Kafka connect helm chart does not support TLS configuraiton. That's why tls enabled is set explicitly to false*/}}
{{/* Currently Kafka connect helm chart does not support basic auth. That's why username and password is set explicitly to empty string*/}}
{{ $connectConfig = dict
"enabled" $values.connectors.enabled
"enabled" $.Values.connectors.enabled
"clusters" (list
(dict
"url" (printf "http://%s.%s.svc.%s:%s" (include "connectors.serviceName" $connectorsValues) .Release.Namespace ($values.clusterDomain | trimSuffix ".") ($values.connectors.connectors.restPort | toString ))
"url" (printf "http://%s.%s.svc.%s:%s" (include "connectors.serviceName" $connectorsValues) .Release.Namespace ($.Values.clusterDomain | trimSuffix ".") ($.Values.connectors.connectors.restPort | toString ))
"name" "connectors"
"tls" (dict
"enabled" "false"
Expand Down Expand Up @@ -125,7 +122,7 @@ limitations under the License.
"connect" $connectConfig
}}

{{ $consoleConfig := deepCopy .Values.console.config | merge $consoleConfig }}
{{ $consoleConfig := merge $consoleConfig .Values.console.config }}

{{ $config := dict
"Values" (dict
Expand All @@ -135,8 +132,7 @@ limitations under the License.
)
}}

{{ $console := deepCopy .Subcharts.console }}
{{ $console = merge $config $console }}
{{ $console := merge $config .Subcharts.console }}
---
{{ include (print .Subcharts.console.Template.BasePath "/configmap.yaml") $console }}
{{ $configmap = include (print .Subcharts.console.Template.BasePath "/configmap.yaml") $console }}
Expand Down Expand Up @@ -285,7 +281,7 @@ limitations under the License.
"extraEnv" $extraEnv
"secret" $secretConfig
"enterprise" $enterprise
"image" $values.console.image
"image" $.Values.console.image
"autoscaling" .Values.console.autoscaling
"replicaCount" .Values.console.replicaCount
"strategy" .Values.console.strategy
Expand Down Expand Up @@ -317,8 +313,7 @@ limitations under the License.
{{ $consoleValues := merge $consoleValues (dict "Values" (dict "podAnnotations" (dict "checksum-redpanda-chart/config" ( $configmap | toYaml | sha256sum )))) }}
{{ end }}

{{ $helmVars := deepCopy .Subcharts.console }}
{{ $helmVars := merge $consoleValues $helmVars }}
{{ $helmVars := merge $consoleValues .Subcharts.console }}

---
{{ include (print .Subcharts.console.Template.BasePath "/deployment.yaml") $helmVars }}
Expand Down
1 change: 0 additions & 1 deletion charts/redpanda/templates/post-install-upgrade-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
*/}}
{{- if .Values.post_install_job.enabled }}
{{- $values := .Values }}
{{- $root := deepCopy . }}
---
apiVersion: batch/v1
kind: Job
Expand Down
1 change: 0 additions & 1 deletion charts/redpanda/templates/post-upgrade.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
{{- if .Values.post_upgrade_job.enabled }}
{{- $service := .Values.listeners.admin -}}
{{- $cert := get .Values.tls.certs $service.tls.cert -}}
{{- $root := deepCopy . }}
apiVersion: batch/v1
kind: Job
metadata:
Expand Down
1 change: 0 additions & 1 deletion charts/redpanda/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ limitations under the License.
{{- $internalAdvertiseAddress := printf "%s.%s" "$(SERVICE_NAME)" (include "redpanda.internal.domain" .) -}}
{{- $uid := dig "podSecurityContext" "runAsUser" .Values.statefulset.securityContext.runAsUser .Values.statefulset -}}
{{- $gid := dig "podSecurityContext" "fsGroup" .Values.statefulset.securityContext.fsGroup .Values.statefulset -}}
{{- $root := deepCopy . }}

{{- if not (include "redpanda-atleast-22-2-0" . | fromJson).bool -}}
{{- if eq (get .Values "force" | default false) false -}}
Expand Down
5 changes: 1 addition & 4 deletions charts/redpanda/templates/tests/test-auditLogging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
as part of setting auditLogging being enabled.
*/}}
{{- if and .Values.tests.enabled .Values.auditLogging.enabled (include "redpanda-atleast-23-3-0" . | fromJson).bool }}
{{- $rpk := deepCopy . }}
{{- $sasl := .Values.auth.sasl }}
{{- $_ := set $rpk "rpk" "rpk" }}
{{- $_ := set $rpk "dummySasl" false }}
apiVersion: v1
kind: Pod
metadata:
Expand Down Expand Up @@ -91,4 +88,4 @@ spec:
{{- toYaml .Values.statefulset.resources | nindent 12 }}
securityContext: {{ include "container-security-context" . | nindent 8 }}
volumes: {{ include "default-volumes" . | nindent 4 }}
{{- end }}
{{- end }}
13 changes: 6 additions & 7 deletions charts/redpanda/templates/tests/test-connector-via-console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ limitations under the License.
*/}}
{{- if and .Values.tests.enabled .Values.connectors.enabled .Values.console.enabled }}
{{- $sasl := .Values.auth.sasl }}
{{- $root := deepCopy . }}
{{- $values := .Values }}
{{ $consoleValues := dict "Values" (deepCopy .Values.console) "Release" .Release "Chart" .Subcharts.console.Chart }}
{{ $connectorsVars := dict "Values" (deepCopy .Values.connectors) "Release" .Release "Chart" .Subcharts.connectors.Chart }}
{{ $consoleValues := dict "Values" .Values.console "Release" .Release "Chart" .Subcharts.console.Chart }}
{{ $connectorsVars := dict "Values" .Values.connectors "Release" .Release "Chart" .Subcharts.connectors.Chart }}
{{/* brokers */}}
{{- $kafkaBrokers := list }}
{{- range (include "seed-server-list" . | mustFromJson) }}
Expand Down Expand Up @@ -62,13 +61,13 @@ spec:
connectorsState () {
echo check connectors expand status
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ (deepCopy .Values.connectors).connectors.restPort }}/connectors?expand=status
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ .Values.connectors.connectors.restPort }}/connectors?expand=status
echo check connectors expand info
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ (deepCopy .Values.connectors).connectors.restPort }}/connectors?expand=info
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ .Values.connectors.connectors.restPort }}/connectors?expand=info
echo check connector configuration
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ (deepCopy .Values.connectors).connectors.restPort }}/connectors/$CONNECTOR_NAME
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ .Values.connectors.connectors.restPort }}/connectors/$CONNECTOR_NAME
echo check connector topics
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ (deepCopy .Values.connectors).connectors.restPort }}/connectors/$CONNECTOR_NAME/topics
curl {{ template "curl-options" . }} http://{{ include "connectors.serviceName" $connectorsVars }}:{{ .Values.connectors.connectors.restPort }}/connectors/$CONNECTOR_NAME/topics
}
{{- if .Values.auth.sasl.enabled }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
*/}}
{{- if and .Values.tests.enabled (include "tls-enabled" . | fromJson).bool ( eq .Values.external.type "NodePort" ) }}
{{- $values := .Values }}
{{- $root := deepCopy . }}
apiVersion: v1
kind: Pod
metadata:
Expand Down Expand Up @@ -73,7 +72,7 @@ spec:
-CAfile {{ printf "/etc/tls/certs/%s" $name }}/ca.crt
{{- end }}
-key {{ printf "/etc/tls/certs/%s" $name }}/tls.key
-connect {{ include "admin-api-urls" $root }}'
-connect {{ include "admin-api-urls" $ }}'
{{- end }}

{{- if eq $cert.secretRef.name "external-tls-secret" }}
Expand All @@ -90,7 +89,7 @@ spec:
-connect {{ $values.external.domain }}:{{ $port }}'
{{- end }}

{{- if and (eq $values.listeners.schemaRegistry.external.default.tls.cert $name) (include "redpanda-22-2-x-without-sasl" $root | fromJson).bool }}
{{- if and (eq $values.listeners.schemaRegistry.external.default.tls.cert $name) (include "redpanda-22-2-x-without-sasl" $ | fromJson).bool }}
echo "-----> testing external tls: schema registry"
{{- $port := ( first $values.listeners.schemaRegistry.external.default.advertisedPorts ) }}
retry 5 'openssl s_client -verify_return_error -prexit
Expand All @@ -101,7 +100,7 @@ spec:
-connect {{ $values.external.domain }}:{{ $port }}'
{{- end }}

{{- if and (eq $values.listeners.http.external.default.tls.cert $name) (include "redpanda-22-2-x-without-sasl" $root | fromJson).bool }}
{{- if and (eq $values.listeners.http.external.default.tls.cert $name) (include "redpanda-22-2-x-without-sasl" $ | fromJson).bool }}
echo "-----> testing external tls: http api"
{{- $port := ( first $values.listeners.http.external.default.advertisedPorts ) }}
retry 5 'openssl s_client -verify_return_error -prexit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
{{- if and .Values.tests.enabled (include "kafka-internal-tls-enabled" . | fromJson).bool (not (include "sasl-enabled" . | fromJson).bool) -}}
{{- $service := .Values.listeners.kafka -}}
{{- $cert := get .Values.tls.certs $service.tls.cert -}}
{{- $root := deepCopy . }}
apiVersion: v1
kind: Pod
metadata:
Expand Down
4 changes: 1 addition & 3 deletions charts/redpanda/templates/tests/test-kafka-nodelete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
{{- if and .Values.tests.enabled (dig "kafka_nodelete_topics" "[]" $.Values.config.cluster) }}
{{- $noDeleteTopics := .Values.config.cluster.kafka_nodelete_topics }}
{{- $sasl := .Values.auth.sasl }}
{{- $root := deepCopy . }}
{{- $rpk := deepCopy . }}
apiVersion: v1
kind: Pod
metadata:
Expand Down Expand Up @@ -103,4 +101,4 @@ spec:
resources: {{ toYaml .Values.statefulset.resources | nindent 12 }}
securityContext: {{ include "container-security-context" . | nindent 8 }}
volumes: {{ include "default-volumes" . | nindent 4 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ limitations under the License.
*/}}
{{- if .Values.tests.enabled }}
{{- $sasl := .Values.auth.sasl }}
{{- $root := deepCopy . }}
{{- $rpk := deepCopy . }}
apiVersion: v1
kind: Pod
metadata:
Expand Down Expand Up @@ -86,4 +84,4 @@ spec:
resources: {{ toYaml .Values.statefulset.resources | nindent 12 }}
securityContext: {{ include "container-security-context" . | nindent 8 }}
volumes: {{ include "default-volumes" . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 5d44bb5

Please sign in to comment.