From 85c0f3477a04e06712c1c8623d1b0b100afaf4e7 Mon Sep 17 00:00:00 2001 From: justinsb Date: Tue, 17 Dec 2024 20:19:21 -0500 Subject: [PATCH] chore: recognize our standard types in ref visitor --- pkg/controller/direct/common/refs.go | 17 +++++++++++++++++ pkg/controller/direct/common/visitfields.go | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/controller/direct/common/refs.go b/pkg/controller/direct/common/refs.go index 95163a7737..cd3cbdb43d 100644 --- a/pkg/controller/direct/common/refs.go +++ b/pkg/controller/direct/common/refs.go @@ -184,7 +184,24 @@ type refNormalizer struct { project *refs.Project } +type Normalizable interface { + NormalizedExternal(context.Context, client.Reader, string) (string, error) +} + func (r *refNormalizer) VisitField(path string, v any) error { + ctx := r.ctx + + if v == nil { + return nil + } + + if normalizable, ok := v.(Normalizable); ok { + _, err := normalizable.NormalizedExternal(ctx, r.kube, r.src.GetNamespace()) + if err != nil { + return err + } + return nil + } if logsPanel, ok := v.(*krm.LogsPanel); ok { for i := range logsPanel.ResourceNames { if ref, err := normalizeResourceName(r.ctx, r.kube, r.src, &logsPanel.ResourceNames[i]); err != nil { diff --git a/pkg/controller/direct/common/visitfields.go b/pkg/controller/direct/common/visitfields.go index f85cd231ba..7a547b7fa5 100644 --- a/pkg/controller/direct/common/visitfields.go +++ b/pkg/controller/direct/common/visitfields.go @@ -76,7 +76,8 @@ func (w *visitorWalker) visitAny(path string, v reflect.Value) { switch elemType.Kind() { case reflect.Struct, reflect.String: for i := 0; i < v.Len(); i++ { - w.visitAny(path+"[]", v.Index(i)) + // We pass the address, so that the visitor can mutate the value in place + w.visitAny(path+"[]", v.Index(i).Addr()) } case reflect.Uint8: // Do not visit []byte as individual values, treat as a leaf