Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global config-backend snippet config #856

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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