3
0

Base envoy codegen

This commit is contained in:
Tomaž Jerman
2023-02-19 14:02:30 +01:00
parent 735cb155f5
commit 804d59722a
84 changed files with 13840 additions and 67 deletions
@@ -57,6 +57,7 @@ func (d StoreDecoder) decode(ctx context.Context, s store.Storer, dl dal.FullSer
// Get all requested scopes
scopedNodes := make(envoyx.NodeSet, len(p.Filter))
{{ if eq .componentIdent "compose" }}
for i, a := range wrappedFilters {
if a.f.Scope.ResourceType == "" {
continue
@@ -64,7 +65,7 @@ func (d StoreDecoder) decode(ctx context.Context, s store.Storer, dl dal.FullSer
// For now the scope can only point to namespace so this will do
var nn envoyx.NodeSet
nn, err = d.decodeNamespace(ctx, s, dl, d.identToNamespaceFilter(a.f.Scope.Identifiers))
nn, err = d.decodeNamespace(ctx, s, dl, d.makeNamespaceFilter(nil, nil, envoyx.ResourceFilter{Identifiers: a.f.Scope.Identifiers}))
if err != nil {
return
}
@@ -79,6 +80,10 @@ func (d StoreDecoder) decode(ctx context.Context, s store.Storer, dl dal.FullSer
scopedNodes[i] = nn[0]
}
{{ else }}
// @note skipping scope logic since it's currently only supported within
// Compose resources.
{{ end }}
// Get all requested references
//
@@ -121,7 +126,7 @@ func (d StoreDecoder) decode(ctx context.Context, s store.Storer, dl dal.FullSer
for i, wf := range wrappedFilters {
switch wf.rt {
{{- range .resources -}}
{{- if or .envoy.omit (not .envoy.use)}}{{continue}}{{ end -}}
{{- if .envoy.omit}}{{continue}}{{ end -}}
case types.{{.expIdent}}ResourceType:
aux, err = d.decode{{.expIdent}}(ctx, s, dl, d.make{{.expIdent}}Filter(scopedNodes[i], refNodes[i], wf.f))
@@ -142,7 +147,7 @@ func (d StoreDecoder) decode(ctx context.Context, s store.Storer, dl dal.FullSer
}
{{- range .resources }}
{{- if or .envoy.omit (not .envoy.use)}}
{{- if .envoy.omit}}
{{continue}}
{{ end -}}
@@ -248,6 +253,7 @@ func (d StoreDecoder) make{{.expIdent}}Filter(scope *envoyx.Node, refs map[strin
_ = ar
_ = ok
{{ range .model.attributes }}
{{- if .envoy.store.omitRefFilter }}{{continue}}{{ end }}
{{ if eq .dal.type "Ref" }}
ar, ok = refs["{{ .expIdent }}"]
if ok {
@@ -46,7 +46,7 @@ func (e StoreEncoder) Prepare(ctx context.Context, p envoyx.EncodeParams, rt str
switch rt {
{{- range .resources }}
{{- if or .envoy.omit (not .envoy.use)}}
{{- if .envoy.omit}}
{{continue}}
{{end -}}
@@ -81,7 +81,7 @@ func (e StoreEncoder) Encode(ctx context.Context, p envoyx.EncodeParams, rt stri
switch rt {
{{- range .resources }}
{{- if or .envoy.omit (not .envoy.use) -}}
{{- if .envoy.omit -}}
{{continue}}
{{end}}
case types.{{.expIdent}}ResourceType:
@@ -93,7 +93,7 @@ func (e StoreEncoder) Encode(ctx context.Context, p envoyx.EncodeParams, rt stri
}
{{- range .resources }}
{{- if or .envoy.omit (not .envoy.use)}}
{{- if .envoy.omit}}
{{continue}}
{{end}}
@@ -68,7 +68,7 @@ func (d *auxYamlDoc) UnmarshalYAML(n *yaml.Node) (err error) {
switch kv {
{{- range .resources -}}
{{- if or .envoy.omit (not .envoy.use) -}}
{{- if .envoy.omit -}}
{{continue}}
{{- end -}}
@@ -127,7 +127,7 @@ func (d *auxYamlDoc) UnmarshalYAML(n *yaml.Node) (err error) {
{{ $rootRes := .resources }}
{{- range .resources }}
{{- if or .envoy.omit (not .envoy.use)}}
{{- if .envoy.omit}}
{{continue}}
{{ end -}}
@@ -175,6 +175,43 @@ func (d *auxYamlDoc) unmarshal{{ .expIdent }}Map(dctx documentContext, n *yaml.N
}
{{ end }}
{{ range .envoy.yaml.extendedResourceDecoders -}}
// unmarshal{{.expIdent}}ExtendedSeq unmarshals {{.expIdent}} when provided as a sequence node
func (d *auxYamlDoc) unmarshalExtended{{.expIdent}}Seq(dctx documentContext, n *yaml.Node) (out envoyx.NodeSet, err error) {
var aux envoyx.NodeSet
err = y7s.EachSeq(n, func(n *yaml.Node) error {
aux, err = d.unmarshal{{ .expIdent }}ExtendedNode(dctx, n)
if err != nil {
return err
}
out = append(out, aux...)
return nil
})
return
}
// unmarshal{{.expIdent}}ExtendedMap unmarshals {{.expIdent}} when provided as a mapping node
//
// When map encoded, the map key is used as a preset identifier.
// The identifier is passed to the node function as a meta node
func (d *auxYamlDoc) unmarshalExtended{{ .expIdent }}Map(dctx documentContext, n *yaml.Node) (out envoyx.NodeSet, err error) {
var aux envoyx.NodeSet
err = y7s.EachMap(n, func(k, n *yaml.Node) error {
aux, err = d.unmarshal{{ .expIdent }}ExtendedNode(dctx, n, k)
if err != nil {
return err
}
out = append(out, aux...)
return nil
})
return
}
{{ end }}
// unmarshal{{ .expIdent }}Node is a cookie-cutter function to unmarshal
// the yaml node into the corresponding Corteza type & Node
func (d *auxYamlDoc) unmarshal{{ .expIdent }}Node(dctx documentContext, n *yaml.Node, meta ...*yaml.Node) (out envoyx.NodeSet, err error) {
@@ -425,6 +462,26 @@ func (d *auxYamlDoc) unmarshal{{ .expIdent }}Node(dctx documentContext, n *yaml.
{{break}}
{{- end }}
{{- end -}}
{{- range .envoy.yaml.extendedResourceDecoders }}
{{ $identKeys := .identKeys }}
case {{ range $i, $l := $identKeys -}}
"{{ $l }}"{{if not (eq $i (sub (len $identKeys) 1))}},{{end}}
{{- end}}:
default:
if y7s.IsSeq(n) {
nestedNodes, err = d.unmarshalExtended{{.expIdent}}Seq(dctx, n)
if err != nil {
return err
}
} {{- if .supportMappedInput }} else {
nestedNodes, err = d.unmarshalExtended{{.expIdent}}Map(dctx, n)
if err != nil {
return err
}
}{{ end }}
break
{{ end -}}
}
// Iterate nested nodes and update their reference to the current resource
@@ -51,7 +51,7 @@ func (e YamlEncoder) Encode(ctx context.Context, p envoyx.EncodeParams, rt strin
switch rt {
{{- range .resources }}
{{- if or .envoy.omit (not .envoy.use)}}
{{- if .envoy.omit}}
{{continue}}
{{ end -}}
@@ -74,7 +74,7 @@ func (e YamlEncoder) Encode(ctx context.Context, p envoyx.EncodeParams, rt strin
{{ $rootRes := .resources }}
{{- range .resources }}
{{- if or .envoy.omit (not .envoy.use)}}
{{- if .envoy.omit}}
{{continue}}
{{ end -}}
+7
View File
@@ -107,6 +107,8 @@ import (
// defines a custom field identifier when constructing
// resource filters and assigning reference constraints
filterRefField: string | *""
omitRefFilter: bool | *false
}
}
@@ -224,6 +226,11 @@ HandleField: {
AttributeUserRef: {
goType: "uint64"
dal: { type: "Ref", refModelResType: "corteza::system:user", default: 0 }
envoy: {
store: {
omitRefFilter: true
}
}
}
SortableTimestampField: {
+10 -6
View File
@@ -90,10 +90,7 @@ import (
}
envoy?: #resourceEnvoy & {
// @todo temporary; easier development on less resources
use: bool | *false
omit: bool | *false
$resourceIdent: ident
}
@@ -147,8 +144,6 @@ import (
#resourceEnvoy: {
$resourceIdent: string
// @todo remove use, temporary for now
use: bool
omit: bool
// Scoped resources prioritize matching with resources in the same scope.
@@ -174,13 +169,22 @@ import (
supportMappedInput: bool | *true
// mappedField controls what identifier the map key represents
// @todo this can probably be inferred so consider removing it.
mappedField: string
mappedField: string | *""
identKeyLabel: string | *strings.ToLower($resourceIdent)
identKeyAlias: [...string] | *[]
// identKeys defines all of the identifiers that can be used when
// referencing this resource
identKeys: [...string] | *([identKeyLabel]+identKeyAlias)
extendedResourceDecoders: [...{
ident: string
expIdent: string
identKeys: [...string]
supportMappedInput: bool | *true
mappedField: string | *""
}] | *[]
}
// store decode/encode configs