From 7c006753de2ec576efec79f499bdd989e22eebbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Sun, 2 Apr 2023 12:03:22 +0200 Subject: [PATCH] Fix invalid codegen for compose/envoy/store_encode Lapsus in component ident field caused too much logic to be removed from the generated code. This caused some _happy accidents_ when matching up to existing resources. --- .../gocode/envoy/store_encode.go.tpl | 2 +- server/compose/envoy/store_encode.gen.go | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/server/codegen/assets/templates/gocode/envoy/store_encode.go.tpl b/server/codegen/assets/templates/gocode/envoy/store_encode.go.tpl index 3abc0b5d9..625e554e4 100644 --- a/server/codegen/assets/templates/gocode/envoy/store_encode.go.tpl +++ b/server/codegen/assets/templates/gocode/envoy/store_encode.go.tpl @@ -352,7 +352,7 @@ func (e StoreEncoder) matchup{{.expIdent}}s(ctx context.Context, s store.Storer, var aux *types.{{.expIdent}} var ok bool for i, n := range nn { - {{ if eq .componentIdent "compose" }} + {{ if eq .component "compose" }} scope := scopes[i] if scope == nil { continue diff --git a/server/compose/envoy/store_encode.gen.go b/server/compose/envoy/store_encode.gen.go index e236c2201..bc4c902a4 100644 --- a/server/compose/envoy/store_encode.gen.go +++ b/server/compose/envoy/store_encode.gen.go @@ -295,6 +295,11 @@ func (e StoreEncoder) matchupCharts(ctx context.Context, s store.Storer, uu map[ var ok bool for i, n := range nn { + scope := scopes[i] + if scope == nil { + continue + } + for _, idf := range n.Identifiers.Slice { if id, err := strconv.ParseUint(idf, 10, 64); err == nil { aux, ok = idMap[id] @@ -525,6 +530,11 @@ func (e StoreEncoder) matchupModules(ctx context.Context, s store.Storer, uu map var ok bool for i, n := range nn { + scope := scopes[i] + if scope == nil { + continue + } + for _, idf := range n.Identifiers.Slice { if id, err := strconv.ParseUint(idf, 10, 64); err == nil { aux, ok = idMap[id] @@ -742,6 +752,11 @@ func (e StoreEncoder) matchupModuleFields(ctx context.Context, s store.Storer, u var ok bool for i, n := range nn { + scope := scopes[i] + if scope == nil { + continue + } + for _, idf := range n.Identifiers.Slice { if id, err := strconv.ParseUint(idf, 10, 64); err == nil { aux, ok = idMap[id] @@ -973,6 +988,11 @@ func (e StoreEncoder) matchupNamespaces(ctx context.Context, s store.Storer, uu var ok bool for i, n := range nn { + scope := scopes[i] + if scope == nil { + continue + } + for _, idf := range n.Identifiers.Slice { if id, err := strconv.ParseUint(idf, 10, 64); err == nil { aux, ok = idMap[id] @@ -1186,6 +1206,11 @@ func (e StoreEncoder) matchupPages(ctx context.Context, s store.Storer, uu map[i var ok bool for i, n := range nn { + scope := scopes[i] + if scope == nil { + continue + } + for _, idf := range n.Identifiers.Slice { if id, err := strconv.ParseUint(idf, 10, 64); err == nil { aux, ok = idMap[id]