Skip to content

Commit 2379697

Browse files
committed
charts/console: remove all helmette.Dot references
1 parent 2c26dd5 commit 2379697

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+814
-615
lines changed

acceptance/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ github.com/redpanda-data/common-go/secrets v0.1.3 h1:VRo+OFS4Zgb2UMvwcIuUujdMhAP
720720
github.com/redpanda-data/common-go/secrets v0.1.3/go.mod h1:WjUU/5saSXwItZx6veFOGbQZUgPQz4MQ65z22y0Ky84=
721721
github.com/redpanda-data/console/backend v0.0.0-20240303221210-05d5d9e85f20 h1:+zsE3W1V86k2sjAGWOySIlF0xn5R1aXXQBaIdr80F48=
722722
github.com/redpanda-data/console/backend v0.0.0-20240303221210-05d5d9e85f20/go.mod h1:DC42/3+k5PefSo4IalYbDN3yRZrVFP0b69+gC/NwGd4=
723+
github.com/redpanda-data/redpanda-operator/charts/console v0.0.0-20250718150737-e01f8476d560 h1:fhMikrIYgjTukRTS7zZHJ5sFQP4hotkfExEyFRWw6rI=
724+
github.com/redpanda-data/redpanda-operator/charts/console v0.0.0-20250718150737-e01f8476d560/go.mod h1:aSiQU9wI3DcOv4tyvoJz5Gx2bUq71LHlLnPkQcGWpK4=
723725
github.com/redpanda-data/redpanda-operator/gotohelm v1.1.0 h1:IV2Ic66JDKPtCnNU4Kn1naJlzZmhl0izRj17qgTCo20=
724726
github.com/redpanda-data/redpanda-operator/gotohelm v1.1.0/go.mod h1:usCpPzzzhgtPrRTiUQOzFqGmukce8U0SrzEeX2ONDFE=
725727
github.com/redpanda-data/redpanda/src/go/rpk v0.0.0-20250716004441-6e1647296ad6 h1:SbcvWTYFEbH5+NQOl1To5jppEa8RCK1HAkRNfhdUGLg=

charts/console/chart.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

charts/console/chart/chart.go

Lines changed: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ package chart
1111

1212
import (
1313
"embed"
14+
"fmt"
15+
"strings"
1416

1517
"github.com/redpanda-data/redpanda-operator/charts/console/v3"
1618
"github.com/redpanda-data/redpanda-operator/gotohelm"
@@ -31,30 +33,118 @@ var (
3133
//go:embed values.schema.json
3234
ValuesSchemaJSON []byte
3335

34-
// ChartLabel is the go version of the console helm chart.
35-
Chart = gotohelm.MustLoad(chartFiles, render)
36+
// Chart is the go version of the console helm chart.
37+
Chart = gotohelm.MustLoad(chartFiles, Render)
3638
)
3739

38-
type Values struct {
39-
console.Values `json:",inline"`
40-
41-
Enabled *bool `json:"enabled,omitempty"`
42-
Tests Enableable `json:"tests"`
43-
}
44-
45-
type Enableable struct {
46-
Enabled bool `json:"enabled"`
47-
}
48-
49-
// render is the entrypoint to both the go and helm versions of the console
40+
// Render is the entrypoint to both the go and helm versions of the console
5041
// helm chart.
5142
// In helm, _shims.render-manifest is used to call and filter the output of
5243
// this function.
5344
// In go, this function should be call by executing [ChartLabel.Render], which will
5445
// handle construction of [helmette.Dot], subcharting, and output filtering.
55-
func render(dot *helmette.Dot) []kube.Object {
46+
func Render(dot *helmette.Dot) []kube.Object {
47+
state := DotToState(dot)
48+
5649
// NB: This slice may contain nil interfaces!
5750
// Filtering happens elsewhere, don't call this function directly if you
5851
// can avoid it.
59-
return console.Render(dot)
52+
return console.Render(state)
53+
}
54+
55+
func DotToState(dot *helmette.Dot) *console.RenderState {
56+
values := helmette.Unwrap[Values](dot.Values)
57+
templater := &templater{Dot: dot, FauxDot: newFauxDot(dot)}
58+
59+
return &console.RenderState{
60+
ReleaseName: dot.Release.Name,
61+
Namespace: dot.Release.Namespace,
62+
Values: values.RenderValues,
63+
Template: templater.Template,
64+
CommonLabels: map[string]string{
65+
"helm.sh/chart": ChartLabel(dot),
66+
"app.kubernetes.io/managed-by": dot.Release.Service,
67+
"app.kubernetes.io/version": dot.Chart.AppVersion,
68+
},
69+
}
70+
}
71+
72+
// templater is a fairly hacky yet effective way to abstract out the global
73+
// `tpl` function that's plagued our rendering packages.
74+
//
75+
// It works around a very niche issue in gotohelm/helm:
76+
// 1. The inability to return a [helmette.Chart]. Helm's internal version
77+
// of `Chart` has JSON tags. Returning it in gotohelm results in all
78+
// fields being downcased and therefore inaccessible. To work around this, we
79+
// construct a [FauxChart] which explicitly keeps the Chart fields upper cased.
80+
// 2. The inability to return a `helmette.Values`. Values is a wrapper type
81+
// around a map[string]any. It comes with an AsMap function that's used by
82+
// gotohelm. We hack in interoperability by assigning a shallow clone of the
83+
// values to itself in the AsMap key.
84+
type templater struct {
85+
// Dot is present purely to satisfy the go requirements of helmette.Tpl. DO
86+
// NOT REFERENCE IT IN HELM IT WILL NOT WORK.
87+
Dot *helmette.Dot
88+
FauxDot *FauxDot
89+
}
90+
91+
func (t *templater) Template(tpl string) string {
92+
return helmette.Tpl(t.Dot, tpl, t.FauxDot)
93+
}
94+
95+
type FauxChart struct {
96+
Name string
97+
Version string
98+
AppVersion string
99+
}
100+
101+
type FauxDot struct {
102+
Values map[string]any
103+
Chart FauxChart
104+
Release helmette.Release
105+
Template helmette.Template
106+
}
107+
108+
func newFauxDot(dot *helmette.Dot) *FauxDot {
109+
clone := map[string]any{}
110+
for key, value := range dot.Values.AsMap() {
111+
clone[key] = value
112+
}
113+
// NB: A shallow clone MUST be used here. If there's any recursion, the
114+
// JSON serialization in sprig "gives up" and returns an empty string.
115+
clone["AsMap"] = dot.Values.AsMap()
116+
return &FauxDot{
117+
Values: clone,
118+
Release: dot.Release,
119+
Template: dot.Template,
120+
Chart: FauxChart{
121+
Name: dot.Chart.Name,
122+
AppVersion: dot.Chart.AppVersion,
123+
Version: dot.Chart.Version,
124+
},
125+
}
126+
}
127+
128+
// Functions below this line are included for backwards compatibility purposes.
129+
// They're re-namespaced in compat.tpl
130+
131+
func Name(dot *helmette.Dot) string {
132+
return DotToState(dot).ChartName()
133+
}
134+
135+
// Create a default fully qualified app name.
136+
// We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
137+
// If release name contains chart name it will be used as a full name.
138+
func Fullname(dot *helmette.Dot) string {
139+
return DotToState(dot).FullName()
140+
}
141+
142+
// Create chart name and version as used by the chart label.
143+
func ChartLabel(dot *helmette.Dot) string {
144+
chart := fmt.Sprintf("%s-%s", dot.Chart.Name, dot.Chart.Version)
145+
return cleanForK8s(strings.ReplaceAll(chart, "+", "_"))
146+
}
147+
148+
func cleanForK8s(s string) string {
149+
return helmette.TrimSuffix("-", helmette.Trunc(63, s))
60150
}

charts/console/chart/chart_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,19 @@ import (
3939
"github.com/redpanda-data/redpanda-operator/pkg/testutil"
4040
)
4141

42-
func TestArtifactHubImages(t *testing.T) {
42+
func TestChartYAML(t *testing.T) {
4343
var images []map[string]any
4444
require.NoError(t, yaml.Unmarshal([]byte(Chart.Metadata().Annotations["artifacthub.io/images"]), &images))
4545

46-
require.Equal(t, []map[string]any{
46+
assert.Equal(t, []map[string]any{
4747
{
4848
"name": "console",
4949
"image": "docker.redpanda.com/redpandadata/console:" + Chart.Metadata().AppVersion,
5050
},
5151
}, images)
52+
53+
assert.Equal(t, console.ChartName, Chart.Metadata().Name)
54+
assert.Equal(t, console.AppVersion, Chart.Metadata().AppVersion)
5255
}
5356

5457
// TestValues asserts that the chart's values.yaml file can be losslessly
@@ -206,7 +209,7 @@ func TestGoHelmEquivalence(t *testing.T) {
206209
Tests: &PartialEnableable{
207210
Enabled: ptr.To(false),
208211
},
209-
PartialValues: console.PartialValues{
212+
PartialRenderValues: console.PartialRenderValues{
210213
Secret: &console.PartialSecretConfig{
211214
Authentication: &console.PartialAuthenticationSecrets{
212215
JWTSigningKey: ptr.To("SECRET"),
@@ -259,7 +262,7 @@ func TestGoHelmEquivalence(t *testing.T) {
259262

260263
func TestSecrets(t *testing.T) {
261264
values := PartialValues{
262-
PartialValues: console.PartialValues{
265+
PartialRenderValues: console.PartialRenderValues{
263266
Secret: &console.PartialSecretConfig{
264267
Create: ptr.To(true),
265268
Kafka: &console.PartialKafkaSecrets{
@@ -357,7 +360,7 @@ func TestIntegrationChart(t *testing.T) {
357360
env := h.Namespaced(t)
358361

359362
partial := PartialValues{
360-
PartialValues: console.PartialValues{
363+
PartialRenderValues: console.PartialRenderValues{
361364
Image: &console.PartialImage{
362365
Repository: ptr.To("redpandadata/console-unstable"),
363366
Tag: ptr.To("master-a4cf9be"),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0
99

10-
package console
10+
package chart
1111

1212
import (
1313
"fmt"

charts/console/chart/templates/NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/}}
17-
{{- $notes := (get ((include "console.Notes" (dict "a" (list .))) | fromJson) "r") -}}
17+
{{- $notes := (get ((include "chart.Notes" (dict "a" (list .))) | fromJson) "r") -}}
1818
{{- range $_, $note := $notes }}
1919
{{ $note }}
2020
{{- end }}

charts/console/chart/templates/_chart.chart.tpl

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,95 @@
11
{{- /* GENERATED FILE DO NOT EDIT */ -}}
22
{{- /* Transpiled by gotohelm from "github.com/redpanda-data/redpanda-operator/charts/console/v3/chart/chart.go" */ -}}
33

4-
{{- define "chart.render" -}}
4+
{{- define "chart.Render" -}}
55
{{- $dot := (index .a 0) -}}
66
{{- range $_ := (list 1) -}}
77
{{- $_is_returning := false -}}
8+
{{- $state := (get (fromJson (include "chart.DotToState" (dict "a" (list $dot)))) "r") -}}
89
{{- $_is_returning = true -}}
9-
{{- (dict "r" (get (fromJson (include "console.Render" (dict "a" (list $dot)))) "r")) | toJson -}}
10+
{{- (dict "r" (get (fromJson (include "console.Render" (dict "a" (list $state)))) "r")) | toJson -}}
11+
{{- break -}}
12+
{{- end -}}
13+
{{- end -}}
14+
15+
{{- define "chart.DotToState" -}}
16+
{{- $dot := (index .a 0) -}}
17+
{{- range $_ := (list 1) -}}
18+
{{- $_is_returning := false -}}
19+
{{- $values := $dot.Values.AsMap -}}
20+
{{- $templater := (mustMergeOverwrite (dict "Dot" (coalesce nil) "FauxDot" (coalesce nil)) (dict "Dot" $dot "FauxDot" (get (fromJson (include "chart.newFauxDot" (dict "a" (list $dot)))) "r"))) -}}
21+
{{- $_is_returning = true -}}
22+
{{- (dict "r" (mustMergeOverwrite (dict "ReleaseName" "" "Namespace" "" "Template" (coalesce nil) "CommonLabels" (coalesce nil) "Values" (dict "replicaCount" 0 "nameOverride" "" "commonLabels" (coalesce nil) "fullnameOverride" "" "image" (dict "registry" "" "repository" "" "pullPolicy" "" "tag" "") "imagePullSecrets" (coalesce nil) "automountServiceAccountToken" false "serviceAccount" (dict "create" false "automountServiceAccountToken" false "annotations" (coalesce nil) "name" "") "annotations" (coalesce nil) "podAnnotations" (coalesce nil) "podLabels" (coalesce nil) "podSecurityContext" (dict) "securityContext" (dict) "service" (dict "type" "" "port" 0 "annotations" (coalesce nil)) "ingress" (dict "enabled" false "annotations" (coalesce nil) "hosts" (coalesce nil) "tls" (coalesce nil)) "resources" (dict) "autoscaling" (dict "enabled" false "minReplicas" 0 "maxReplicas" 0 "targetCPUUtilizationPercentage" (coalesce nil)) "nodeSelector" (coalesce nil) "tolerations" (coalesce nil) "affinity" (dict) "topologySpreadConstraints" (coalesce nil) "priorityClassName" "" "config" (coalesce nil) "extraEnv" (coalesce nil) "extraEnvFrom" (coalesce nil) "extraVolumes" (coalesce nil) "extraVolumeMounts" (coalesce nil) "extraContainers" (coalesce nil) "initContainers" (dict "extraInitContainers" (coalesce nil)) "secretMounts" (coalesce nil) "secret" (dict "create" false "kafka" (dict) "authentication" (dict "jwtSigningKey" "" "oidc" (dict)) "license" "" "redpanda" (dict "adminApi" (dict)) "serde" (dict) "schemaRegistry" (dict)) "livenessProbe" (dict) "readinessProbe" (dict) "configmap" (dict "create" false) "deployment" (dict "create" false) "strategy" (dict))) (dict "ReleaseName" $dot.Release.Name "Namespace" $dot.Release.Namespace "Values" $values "Template" (list "chart.templater.Template" $templater) "CommonLabels" (dict "helm.sh/chart" (get (fromJson (include "chart.ChartLabel" (dict "a" (list $dot)))) "r") "app.kubernetes.io/managed-by" $dot.Release.Service "app.kubernetes.io/version" $dot.Chart.AppVersion)))) | toJson -}}
23+
{{- break -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{- define "chart.templater.Template" -}}
28+
{{- $t := (index .a 0) -}}
29+
{{- $tpl := (index .a 1) -}}
30+
{{- range $_ := (list 1) -}}
31+
{{- $_is_returning := false -}}
32+
{{- $_is_returning = true -}}
33+
{{- (dict "r" (tpl $tpl $t.FauxDot)) | toJson -}}
34+
{{- break -}}
35+
{{- end -}}
36+
{{- end -}}
37+
38+
{{- define "chart.newFauxDot" -}}
39+
{{- $dot := (index .a 0) -}}
40+
{{- range $_ := (list 1) -}}
41+
{{- $_is_returning := false -}}
42+
{{- $clone := (dict) -}}
43+
{{- range $key, $value := $dot.Values.AsMap -}}
44+
{{- $_ := (set $clone $key $value) -}}
45+
{{- end -}}
46+
{{- if $_is_returning -}}
47+
{{- break -}}
48+
{{- end -}}
49+
{{- $_ := (set $clone "AsMap" $dot.Values.AsMap) -}}
50+
{{- $_is_returning = true -}}
51+
{{- (dict "r" (mustMergeOverwrite (dict "Values" (coalesce nil) "Chart" (dict "Name" "" "Version" "" "AppVersion" "") "Release" (dict "Name" "" "Namespace" "" "Service" "" "IsUpgrade" false "IsInstall" false) "Template" (dict "Name" "" "BasePath" "")) (dict "Values" $clone "Release" $dot.Release "Template" $dot.Template "Chart" (mustMergeOverwrite (dict "Name" "" "Version" "" "AppVersion" "") (dict "Name" $dot.Chart.Name "AppVersion" $dot.Chart.AppVersion "Version" $dot.Chart.Version))))) | toJson -}}
52+
{{- break -}}
53+
{{- end -}}
54+
{{- end -}}
55+
56+
{{- define "chart.Name" -}}
57+
{{- $dot := (index .a 0) -}}
58+
{{- range $_ := (list 1) -}}
59+
{{- $_is_returning := false -}}
60+
{{- $_is_returning = true -}}
61+
{{- (dict "r" (get (fromJson (include "console.RenderState.ChartName" (dict "a" (list (get (fromJson (include "chart.DotToState" (dict "a" (list $dot)))) "r"))))) "r")) | toJson -}}
62+
{{- break -}}
63+
{{- end -}}
64+
{{- end -}}
65+
66+
{{- define "chart.Fullname" -}}
67+
{{- $dot := (index .a 0) -}}
68+
{{- range $_ := (list 1) -}}
69+
{{- $_is_returning := false -}}
70+
{{- $_is_returning = true -}}
71+
{{- (dict "r" (get (fromJson (include "console.RenderState.FullName" (dict "a" (list (get (fromJson (include "chart.DotToState" (dict "a" (list $dot)))) "r"))))) "r")) | toJson -}}
72+
{{- break -}}
73+
{{- end -}}
74+
{{- end -}}
75+
76+
{{- define "chart.ChartLabel" -}}
77+
{{- $dot := (index .a 0) -}}
78+
{{- range $_ := (list 1) -}}
79+
{{- $_is_returning := false -}}
80+
{{- $chart := (printf "%s-%s" $dot.Chart.Name $dot.Chart.Version) -}}
81+
{{- $_is_returning = true -}}
82+
{{- (dict "r" (get (fromJson (include "chart.cleanForK8s" (dict "a" (list (replace "+" "_" $chart))))) "r")) | toJson -}}
83+
{{- break -}}
84+
{{- end -}}
85+
{{- end -}}
86+
87+
{{- define "chart.cleanForK8s" -}}
88+
{{- $s := (index .a 0) -}}
89+
{{- range $_ := (list 1) -}}
90+
{{- $_is_returning := false -}}
91+
{{- $_is_returning = true -}}
92+
{{- (dict "r" (trimSuffix "-" (trunc (63 | int) $s))) | toJson -}}
1093
{{- break -}}
1194
{{- end -}}
1295
{{- end -}}

0 commit comments

Comments
 (0)