diff --git a/server/pkg/envoyx/store.go b/server/pkg/envoyx/store.go index bcdc5ef8e..bdb1c69b7 100644 --- a/server/pkg/envoyx/store.go +++ b/server/pkg/envoyx/store.go @@ -2,6 +2,7 @@ package envoyx import ( "context" + "sort" ) func (svc *Service) decodeStore(ctx context.Context, p DecodeParams) (nn NodeSet, err error) { @@ -33,7 +34,9 @@ func (svc *Service) encodeStore(ctx context.Context, dg *DepGraph, p EncodeParam } // Encoding - for rt, nn := range NodesByResourceType(dg.Roots()...) { + nodes := NodesByResourceType(dg.Roots()...) + for _, rt := range svc.sortResourceTypes(nodes) { + nn := nodes[rt] for _, se := range svc.encoders[EncodeTypeStore] { err = se.Encode(ctx, p, rt, OmitPlaceholderNodes(nn...), dg) if err != nil { @@ -44,3 +47,16 @@ func (svc *Service) encodeStore(ctx context.Context, dg *DepGraph, p EncodeParam return } + +func (svc *Service) sortResourceTypes(nn map[string]NodeSet) (out []string) { + for rt := range nn { + out = append(out, rt) + } + sort.Strings(out) + + for i, j := 0, len(out)-1; i < j; i, j = i+1, j-1 { + out[i], out[j] = out[j], out[i] + } + + return +}