Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: sjcsjc123 <[email protected]>
  • Loading branch information
sjcsjc123 committed Dec 30, 2023
1 parent e22fd3d commit a4a1fdf
Show file tree
Hide file tree
Showing 4 changed files with 595 additions and 23 deletions.
5 changes: 2 additions & 3 deletions pkg/ingress/kube/configmap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,20 @@ type ItemEventHandler = func(name string)

type HigressConfig struct {
Tracing *Tracing `json:"tracing,omitempty"`
Gzip *Gzip `json:"gzip,omitempty"`
Downstream *Downstream `json:"downstream,omitempty"`
DisableXEnvoyHeaders bool `json:"disableXEnvoyHeaders,omitempty"`
AddXRealIpHeader bool `json:"addXRealIpHeader,omitempty"`
Gzip *Gzip `json:"gzip,omitempty"`
}

func NewDefaultHigressConfig() *HigressConfig {
globalOption := NewDefaultGlobalOption()
higressConfig := &HigressConfig{
Tracing: NewDefaultTracing(),
Gzip: NewDefaultGzip(),
Downstream: globalOption.Downstream,
DisableXEnvoyHeaders: globalOption.DisableXEnvoyHeaders,
AddXRealIpHeader: globalOption.AddXRealIpHeader,
Gzip: NewDefaultGzip(),

}
return higressConfig
}
Expand Down
18 changes: 13 additions & 5 deletions pkg/ingress/kube/configmap/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func NewConfigmapMgr(XDSUpdater model.XDSUpdater, namespace string, higressConfi
configmapMgr.SetHigressConfig(NewDefaultHigressConfig())

tracingController := NewTracingController(namespace)

downstreamController := NewGlobalOptionController(namespace)
configmapMgr.AddItemControllers(tracingController)
configmapMgr.AddItemControllers(downstreamController)

gzipController := NewGzipController(namespace)
configmapMgr.AddItemControllers(gzipController)

globalOptionController := NewGlobalOptionController(namespace)
configmapMgr.AddItemControllers(globalOptionController)

configmapMgr.initEventHandlers()

return configmapMgr
Expand Down Expand Up @@ -121,12 +121,20 @@ func (c *ConfigmapMgr) AddOrUpdateHigressConfig(name util.ClusterNamespacedName)
return
}

newHigressConfig := NewDefaultHigressConfig()
if err = yaml.Unmarshal([]byte(higressConfigmap.Data[HigressConfigMapKey]), newHigressConfig); err != nil {
var higressConfig *HigressConfig
err = yaml.Unmarshal([]byte(higressConfigmap.Data[HigressConfigMapKey]), &higressConfig)
if err != nil {
IngressLog.Errorf("data:%s, convert to higress config error, error: %+v", higressConfigmap.Data[HigressConfigMapKey], err)
return
}

newHigressConfig := NewDefaultHigressConfig()
newHigressConfig.Tracing = higressConfig.Tracing
newHigressConfig.Gzip = higressConfig.Gzip
newHigressConfig.Downstream = higressConfig.Downstream
newHigressConfig.DisableXEnvoyHeaders = higressConfig.DisableXEnvoyHeaders
newHigressConfig.AddXRealIpHeader = higressConfig.AddXRealIpHeader

for _, itemController := range c.ItemControllers {
if itemErr := itemController.ValidHigressConfig(newHigressConfig); itemErr != nil {
IngressLog.Errorf("configmap %s controller valid higress config error, error: %+v", itemController.GetName(), itemErr)
Expand Down
24 changes: 9 additions & 15 deletions pkg/ingress/kube/configmap/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package configmap

import (
"encoding/json"
"fmt"
"reflect"
"sync/atomic"
Expand Down Expand Up @@ -57,6 +56,8 @@ type Global struct {

// Downstream configures the behavior of the downstream connection.
type Downstream struct {
// Enable enables the downstream config.
Enable bool `json:"enable,omitempty"`
// IdleTimeout limits the time that a connection may be idle and stream idle.
IdleTimeout uint32 `json:"idleTimeout,omitempty"`
// MaxRequestHeadersKb limits the size of request headers allowed.
Expand Down Expand Up @@ -138,19 +139,11 @@ func compareGlobal(old *Global, new *Global) (Result, error) {

// deepCopyGlobal deep copies the global option.
func deepCopyGlobal(global *Global) (*Global, error) {
defaultGlobal := &Global{}

bytes, err := json.Marshal(global)
if err != nil {
return nil, err
}

err = json.Unmarshal(bytes, defaultGlobal)
if err != nil {
return nil, err
}

return defaultGlobal, nil
newGlobal := NewDefaultGlobalOption()
newGlobal.Downstream = global.Downstream
newGlobal.AddXRealIpHeader = global.AddXRealIpHeader
newGlobal.DisableXEnvoyHeaders = global.DisableXEnvoyHeaders
return newGlobal, nil
}

// NewDefaultGlobalOption returns a default global config.
Expand All @@ -165,6 +158,7 @@ func NewDefaultGlobalOption() *Global {
// NewDefaultDownstream returns a default downstream config.
func NewDefaultDownstream() *Downstream {
return &Downstream{
Enable: false,
IdleTimeout: defaultIdleTimeout,
MaxRequestHeadersKb: defaultMaxRequestHeadersKb,
ConnectionBufferLimits: defaultConnectionBufferLimits,
Expand Down Expand Up @@ -299,7 +293,7 @@ func (g *GlobalOptionController) ConstructEnvoyFilters() ([]*config.Config, erro
configPatch = append(configPatch, disableXEnvoyHeadersConfig...)
}

if global.Downstream == nil {
if global.Downstream == nil || !global.Downstream.Enable {
return generateEnvoyFilter(namespace, configPatch), nil
}

Expand Down
Loading

0 comments on commit a4a1fdf

Please sign in to comment.