Skip to content

Commit

Permalink
Fix namespace export error when resources reference deleted resources
Browse files Browse the repository at this point in the history
  • Loading branch information
tjerman committed Nov 3, 2023
1 parent 0c3a525 commit dc54b55
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 275 deletions.
31 changes: 13 additions & 18 deletions server/automation/envoy/store_encode.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions server/automation/envoy/yaml_encode.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions server/codegen/assets/templates/gocode/envoy/store_encode.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,9 @@ func (e StoreEncoder) encode{{.expIdent}}(ctx context.Context, p envoyx.EncodePa
var auxID uint64
err = func() (err error) {
for fieldLabel, ref := range n.References {
rn := tree.ParentForRef(n, ref)
if rn == nil {
err = fmt.Errorf("parent reference %v not found", ref)
return
}

auxID = rn.Resource.GetID()
auxID = safeParentID(tree, n, ref)
if auxID == 0 {
err = fmt.Errorf("parent reference does not provide an identifier")
return
continue
}

err = n.Resource.SetValue(fieldLabel, 0, auxID)
Expand Down Expand Up @@ -508,4 +501,13 @@ func (e StoreEncoder) makeNamespaceFilter(scope *envoyx.Node, refs map[string]*e

return
}
{{ end }}
{{ end }}

func safeParentID(tt envoyx.Traverser, n *envoyx.Node, ref envoyx.Ref) (out uint64) {
rn := tt.ParentForRef(n, ref)
if rn == nil {
return
}

return rn.Resource.GetID()
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,12 @@ func (e YamlEncoder) getWriter(p envoyx.EncodeParams) (out io.Writer, err error)
err = errors.Errorf("YAML encoder expects a writer conforming to io.Writer interface")
return
}

func safeParentIdentifier(tt envoyx.Traverser, n *envoyx.Node, ref envoyx.Ref) (out string) {
aux := tt.ParentForRef(n, ref)
if aux == nil {
return ref.Identifiers.FriendlyIdentifier()
}

return aux.Identifiers.FriendlyIdentifier()
}
75 changes: 21 additions & 54 deletions server/compose/envoy/store_encode.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions server/compose/envoy/yaml_encode.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dc54b55

Please sign in to comment.