Tweak envoy config structs
Have each node define it's own configs where the decoder may define the wanted values and the global config populates missing values in the Bake step.
This commit is contained in:
@@ -64,13 +64,12 @@ type (
|
||||
DecoderConfig struct{}
|
||||
|
||||
EncodeParams struct {
|
||||
Type encodeType
|
||||
Params map[string]any
|
||||
Config EncoderConfig
|
||||
Type encodeType
|
||||
Params map[string]any
|
||||
Envoy EnvoyConfig
|
||||
Encoder EncoderConfig
|
||||
}
|
||||
EncoderConfig struct {
|
||||
OnExisting mergeAlg
|
||||
|
||||
PreferredTimeLayout string
|
||||
PreferredTimezone string
|
||||
}
|
||||
@@ -93,7 +92,8 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
OnConflictReplace mergeAlg = iota
|
||||
OnConflictDefault mergeAlg = iota
|
||||
OnConflictReplace
|
||||
OnConflictSkip
|
||||
OnConflictPanic
|
||||
// OnConflictMergeLeft mergeAlg = "mergeLeft"
|
||||
@@ -145,6 +145,11 @@ func (svc *service) Decode(ctx context.Context, p DecodeParams) (nn NodeSet, err
|
||||
return
|
||||
}
|
||||
|
||||
func (svc *service) Bake(ctx context.Context, p EncodeParams, nodes ...*Node) (err error) {
|
||||
err = svc.bakeEnvoyConfig(p.Envoy, nodes...)
|
||||
return
|
||||
}
|
||||
|
||||
// Encode encodes Corteza resources bases on the provided encode params
|
||||
//
|
||||
// use the BuildDepGraph function to build the default dependency graph.
|
||||
@@ -227,3 +232,28 @@ func CastMergeAlg(v string) (mergeAlg mergeAlg) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (svc *service) bakeEnvoyConfig(dft EnvoyConfig, nodes ...*Node) (err error) {
|
||||
for _, n := range nodes {
|
||||
n.Config = svc.mergeEnvoyConfigs(n.Config, dft)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (svc *service) mergeEnvoyConfigs(a, b EnvoyConfig) (c EnvoyConfig) {
|
||||
c = a
|
||||
if c.MergeAlg == OnConflictDefault {
|
||||
c.MergeAlg = b.MergeAlg
|
||||
}
|
||||
if c.MergeAlg == OnConflictDefault {
|
||||
c.MergeAlg = OnConflictReplace
|
||||
}
|
||||
|
||||
// @todo pre eval this?
|
||||
if c.SkipIf == "" {
|
||||
c.SkipIf = b.SkipIf
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
45
server/pkg/envoyx/envoy_test.go
Normal file
45
server/pkg/envoyx/envoy_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package envoyx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBake(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
req := require.New(t)
|
||||
|
||||
t.Run("set default envoy config", func(t *testing.T) {
|
||||
a := &Node{
|
||||
Config: EnvoyConfig{
|
||||
MergeAlg: OnConflictDefault,
|
||||
SkipIf: "",
|
||||
},
|
||||
}
|
||||
b := &Node{
|
||||
Config: EnvoyConfig{
|
||||
MergeAlg: OnConflictReplace,
|
||||
SkipIf: "",
|
||||
},
|
||||
}
|
||||
c := &Node{
|
||||
Config: EnvoyConfig{
|
||||
MergeAlg: OnConflictReplace,
|
||||
SkipIf: "true",
|
||||
},
|
||||
}
|
||||
err := (&service{}).Bake(ctx, EncodeParams{Envoy: EnvoyConfig{MergeAlg: OnConflictPanic, SkipIf: "false"}}, a, b, c)
|
||||
req.NoError(err)
|
||||
|
||||
req.Equal(OnConflictPanic, a.Config.MergeAlg)
|
||||
req.Equal("false", a.Config.SkipIf)
|
||||
|
||||
req.Equal(OnConflictReplace, b.Config.MergeAlg)
|
||||
req.Equal("false", b.Config.SkipIf)
|
||||
|
||||
req.Equal(OnConflictReplace, c.Config.MergeAlg)
|
||||
req.Equal("true", c.Config.SkipIf)
|
||||
})
|
||||
}
|
||||
@@ -19,9 +19,9 @@ type (
|
||||
|
||||
// Placeholders are resources which were added to help resolve missing deps
|
||||
Placeholder bool
|
||||
Config NodeConfig
|
||||
Config EnvoyConfig
|
||||
}
|
||||
NodeConfig struct {
|
||||
EnvoyConfig struct {
|
||||
MergeAlg mergeAlg
|
||||
SkipIf string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user