Skip to content

Commit

Permalink
chore: recognize our standard types in ref visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Dec 18, 2024
1 parent 47fa562 commit 85c0f34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions pkg/controller/direct/common/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/direct/common/visitfields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 85c0f34

Please sign in to comment.