Add proxy and forward options (#149)

This commit is contained in:
Sandeep Rajan 2019-04-16 11:55:24 -04:00 committed by Chris O'Haver
parent d8ad9b2d44
commit 631694b4e3
2 changed files with 357 additions and 35 deletions

View file

@ -5,7 +5,61 @@ import (
) )
func TestMigrate(t *testing.T) { func TestMigrate(t *testing.T) {
startCorefile := `.:53 { testCases := []struct {
name string
fromVersion string
toVersion string
deprecations bool
startCorefile string
expectedCorefile string
}{
{
name: "Remove invalid proxy option",
startCorefile: `.:53 {
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
endpoint thing1 thing2
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
proxy example.org 1.2.3.4:53 {
protocol https_google
}
cache 30
loop
reload
loadbalance
}
`,
fromVersion: "1.1.3",
toVersion: "1.2.6",
deprecations: true,
expectedCorefile: `.:53 {
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
endpoint thing1 thing2
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
proxy example.org 1.2.3.4:53
cache 30
loop
reload
loadbalance
}
`,
},
{
name: "Migrate from proxy to forward and handle Kubernetes deprecations",
startCorefile: `.:53 {
errors errors
health health
kubernetes cluster.local in-addr.arpa ip6.arpa { kubernetes cluster.local in-addr.arpa ip6.arpa {
@ -21,9 +75,13 @@ func TestMigrate(t *testing.T) {
reload reload
loadbalance loadbalance
} }
` `,
expected := `.:53 { fromVersion: "1.3.1",
toVersion: "1.5.0",
deprecations: true,
expectedCorefile: `.:53 {
errors errors
health health
kubernetes cluster.local in-addr.arpa ip6.arpa { kubernetes cluster.local in-addr.arpa ip6.arpa {
@ -38,15 +96,23 @@ func TestMigrate(t *testing.T) {
reload reload
loadbalance loadbalance
} }
` `,
result, err := Migrate("1.3.1", "1.5.0", startCorefile, true) },
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
result, err := Migrate(testCase.fromVersion, testCase.toVersion, testCase.startCorefile, testCase.deprecations)
if err != nil { if err != nil {
t.Errorf("%v", err) t.Errorf("%v", err)
} }
if result != expected { if result != testCase.expectedCorefile {
t.Errorf("expected %v; got %v", expected, result) t.Errorf("expected %v; got %v", testCase.expectedCorefile, result)
}
})
} }
} }

View file

@ -101,7 +101,19 @@ var Versions = map[string]release{
action: proxyToForwardPluginAction, action: proxyToForwardPluginAction,
options: proxyToForwardOptionsMigrations, options: proxyToForwardOptionsMigrations,
}, },
"forward": {}, "forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -167,7 +179,19 @@ var Versions = map[string]release{
action: proxyToForwardPluginAction, action: proxyToForwardPluginAction,
options: proxyToForwardOptionsMigrations, options: proxyToForwardOptionsMigrations,
}, },
"forward": {}, "forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -240,8 +264,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -295,8 +341,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -360,8 +428,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -405,8 +495,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -450,8 +562,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -495,8 +629,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -555,8 +711,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -599,8 +777,30 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -643,8 +843,33 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {
status: removed,
action: proxyRemoveHttpsGoogleProtocol,
},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"prefer_udp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -686,8 +911,32 @@ var Versions = map[string]release{
}, },
}, },
"prometheus": {}, "prometheus": {},
"proxy": {}, "proxy": {
"forward": {}, options: map[string]option{
"policy": {},
"fail_timeout": {},
"max_fails": {},
"health_check": {},
"except": {},
"spray": {},
"protocol": {
status: ignored,
action: proxyRemoveHttpsGoogleProtocol,
},
},
},
"forward": {
options: map[string]option{
"except": {},
"force_tcp": {},
"expire": {},
"max_fails": {},
"tls": {},
"tls_servername": {},
"policy": {},
"health_check": {},
},
},
"cache": { "cache": {
options: map[string]option{ options: map[string]option{
"success": {}, "success": {},
@ -756,3 +1005,10 @@ var useFirstArgumentOnly = func(o *corefile.Option) (*corefile.Option, error) {
o.Args = o.Args[:1] o.Args = o.Args[:1]
return o, nil return o, nil
} }
var proxyRemoveHttpsGoogleProtocol = func(o *corefile.Option) (*corefile.Option, error) {
if len(o.Args) > 0 && o.Args[0] == "https_google" {
return nil, nil
}
return o, nil
}