Skip to content

Commit

Permalink
Merge pull request #856 from jcmoraisjr/jm-fix-config-backend
Browse files Browse the repository at this point in the history
Fix global config-backend snippet config
  • Loading branch information
jcmoraisjr authored Sep 16, 2021
2 parents 001f276 + 5772ffc commit 420969f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
11 changes: 6 additions & 5 deletions pkg/converters/ingress/annotations/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,21 +523,22 @@ func (c *updater) buildBackendCors(d *backData) {

func (c *updater) buildBackendCustomConfig(d *backData) {
config := d.mapper.Get(ingtypes.BackConfigBackend)
if config.Source == nil {
return
}
lines := utils.LineToSlice(config.Value)
if len(lines) == 0 {
return
}
source := "global config"
if config.Source != nil {
source = config.Source.String()
}
for _, keyword := range c.options.DisableKeywords {
if keyword == "*" {
c.logger.Warn("skipping configuration snippet on %s: custom configuration is disabled", config.Source)
c.logger.Warn("skipping configuration snippet on %s: custom configuration is disabled", source)
return
}
for _, line := range lines {
if firstToken(line) == keyword {
c.logger.Warn("skipping configuration snippet on %s: keyword '%s' not allowed", config.Source, keyword)
c.logger.Warn("skipping configuration snippet on %s: keyword '%s' not allowed", source, keyword)
return
}
}
Expand Down
17 changes: 10 additions & 7 deletions pkg/converters/ingress/annotations/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,15 @@ func TestCors(t *testing.T) {
}

func TestCustomConfig(t *testing.T) {
defaultSource := &Source{
Type: "Ingress",
Namespace: "default",
Name: "app",
}
testCases := []struct {
disabled []string
config string
source *Source
expected []string
logging string
}{
Expand All @@ -1331,13 +1337,14 @@ func TestCustomConfig(t *testing.T) {
{
disabled: []string{"server"},
config: " server srv001 127.0.0.1:8080",
source: defaultSource,
logging: `WARN skipping configuration snippet on Ingress 'default/app': keyword 'server' not allowed`,
},
// 2
{
disabled: []string{"*"},
config: " server srv001 127.0.0.1:8080",
logging: `WARN skipping configuration snippet on Ingress 'default/app': custom configuration is disabled`,
logging: `WARN skipping configuration snippet on global config: custom configuration is disabled`,
},
// 3
{
Expand All @@ -1363,6 +1370,7 @@ func TestCustomConfig(t *testing.T) {
acl rootpath path /
http-request set-header x-id 1 if rootpath
`,
source: defaultSource,
logging: `WARN skipping configuration snippet on Ingress 'default/app': keyword 'acl' not allowed`,
},
// 6
Expand All @@ -1374,15 +1382,10 @@ func TestCustomConfig(t *testing.T) {
}
for i, test := range testCases {
c := setup(t)
source := &Source{
Type: "Ingress",
Namespace: "default",
Name: "app",
}
ann := map[string]map[string]string{
"/": {ingtypes.BackConfigBackend: test.config},
}
d := c.createBackendMappingData("default/app", source, map[string]string{}, ann, []string{"/"})
d := c.createBackendMappingData("default/app", test.source, map[string]string{}, ann, []string{"/"})
updater := c.createUpdater()
updater.options.DisableKeywords = test.disabled
updater.buildBackendCustomConfig(d)
Expand Down

0 comments on commit 420969f

Please sign in to comment.