This commit is contained in:
Renjie Cai 2025-02-17 09:50:31 -08:00 committed by GitHub
commit 46e158b14f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 115 additions and 115 deletions

View file

@ -61,7 +61,7 @@ import (
)
const (
exampleBackend = "example-http-svc-1-80"
exampleBackend = "example_http-svc-1_80"
TRUE = "true"
)
@ -518,12 +518,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -537,19 +537,19 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -563,7 +563,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -624,24 +624,24 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-foo-http-svc-80": {
Name: "example-foo-http-svc-80",
"example_foo-http-svc_80": {
Name: "example_foo-http-svc_80",
NoServer: false,
},
"example-foo-http-svc-canary-80": {
Name: "example-foo-http-svc-canary-80",
"example_foo-http-svc-canary_80": {
Name: "example_foo-http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
},
},
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -655,7 +655,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-foo-http-svc-80",
Backend: "example_foo-http-svc_80",
},
},
},
@ -665,31 +665,31 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
},
map[string]*ingress.Backend{
"example-foo-http-svc-80": {
Name: "example-foo-http-svc-80",
"example_foo-http-svc_80": {
Name: "example_foo-http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-foo-http-svc-canary-80"},
AlternativeBackends: []string{"example_foo-http-svc-canary_80"},
},
"example-foo-http-svc-canary-80": {
Name: "example-foo-http-svc-canary-80",
"example_foo-http-svc-canary_80": {
Name: "example_foo-http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
},
},
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -703,7 +703,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -743,8 +743,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -774,12 +774,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -793,19 +793,19 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -819,7 +819,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -848,8 +848,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
Name: "upstream-default-backend",
NoServer: false,
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -915,12 +915,12 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -934,19 +934,19 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -960,7 +960,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -1005,8 +1005,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
SessionAffinity: ingress.SessionAffinityConfig{
AffinityType: "cookie",
@ -1016,8 +1016,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -1031,16 +1031,16 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
SessionAffinity: ingress.SessionAffinityConfig{
AffinityType: "cookie",
AffinityMode: "balanced",
@ -1049,8 +1049,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -1071,7 +1071,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -1116,8 +1116,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
SessionAffinity: ingress.SessionAffinityConfig{
AffinityType: "cookie",
@ -1127,8 +1127,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -1142,16 +1142,16 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
SessionAffinity: ingress.SessionAffinityConfig{
AffinityType: "cookie",
AffinityMode: "balanced",
@ -1160,8 +1160,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -1182,7 +1182,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -1227,8 +1227,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
SessionAffinity: ingress.SessionAffinityConfig{
AffinityType: "cookie",
@ -1238,8 +1238,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -1253,16 +1253,16 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
},
map[string]*ingress.Backend{
"example-http-svc-80": {
Name: "example-http-svc-80",
"example_http-svc_80": {
Name: "example_http-svc_80",
NoServer: false,
AlternativeBackends: []string{"example-http-svc-canary-80"},
AlternativeBackends: []string{"example_http-svc-canary_80"},
SessionAffinity: ingress.SessionAffinityConfig{
AffinityType: "cookie",
AffinityMode: "balanced",
@ -1271,8 +1271,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
},
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -1286,7 +1286,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -1326,8 +1326,8 @@ func TestMergeAlternativeBackends(t *testing.T) {
},
},
map[string]*ingress.Backend{
"example-http-svc-canary-80": {
Name: "example-http-svc-canary-80",
"example_http-svc-canary_80": {
Name: "example_http-svc-canary_80",
NoServer: true,
TrafficShapingPolicy: ingress.TrafficShapingPolicy{
Weight: 20,
@ -1341,7 +1341,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -1354,7 +1354,7 @@ func TestMergeAlternativeBackends(t *testing.T) {
{
Path: "/",
PathType: &pathTypePrefix,
Backend: "example-http-svc-80",
Backend: "example_http-svc_80",
},
},
},
@ -1722,8 +1722,8 @@ func TestGetBackendServers(t *testing.T) {
t.Errorf("server location 0 should not be default backend")
}
if s.Locations[0].Backend != "example-http-svc-80" {
t.Errorf("location backend should be 'example-http-svc-80', got '%s'", s.Locations[0].Backend)
if s.Locations[0].Backend != "example_http-svc_80" {
t.Errorf("location backend should be 'example_http-svc_80', got '%s'", s.Locations[0].Backend)
}
},
SetConfigMap: testConfigMap,
@ -1890,7 +1890,7 @@ func TestGetBackendServers(t *testing.T) {
t.Errorf("server hostname should be 'example.com', got '%s'", s.Hostname)
}
if s.Locations[0].Backend != "example-http-svc-80" {
if s.Locations[0].Backend != "example_http-svc_80" {
t.Errorf("location backend should be 'example-http-svc-80', got '%s'", s.Locations[0].Backend)
}
},
@ -2151,7 +2151,7 @@ func TestGetBackendServers(t *testing.T) {
}
if s.Locations[0].Backend != exampleBackend || s.Locations[1].Backend != exampleBackend || s.Locations[2].Backend != exampleBackend {
t.Errorf("all location backend should be 'example-http-svc-1-80'")
t.Errorf("all location backend should be '%s'", exampleBackend)
}
if len(upstreams) != 3 {
@ -2160,14 +2160,14 @@ func TestGetBackendServers(t *testing.T) {
}
if upstreams[0].Name != exampleBackend {
t.Errorf("example-http-svc-1-80 should be first upstream, got %s", upstreams[0].Name)
t.Errorf("%s should be first upstream, got %s", exampleBackend, upstreams[0].Name)
return
}
if upstreams[0].NoServer {
t.Errorf("'example-http-svc-1-80' should be primary upstream, got as alternative upstream")
t.Errorf("'%s' should be primary upstream, got as alternative upstream", exampleBackend)
}
if len(upstreams[0].AlternativeBackends) != 1 || upstreams[0].AlternativeBackends[0] != "example-http-svc-2-80" {
t.Errorf("example-http-svc-2-80 should be alternative upstream for 'example-http-svc-1-80'")
if len(upstreams[0].AlternativeBackends) != 1 || upstreams[0].AlternativeBackends[0] != "example_http-svc-2_80" {
t.Errorf("example_http-svc-2_80 should be alternative upstream for '%s'", exampleBackend)
}
},
SetConfigMap: testConfigMap,

View file

@ -50,13 +50,13 @@ func newUpstream(name string) *ingress.Backend {
func upstreamName(namespace string, service *networking.IngressServiceBackend) string {
if service != nil {
if service.Port.Number > 0 {
return fmt.Sprintf("%s-%s-%d", namespace, service.Name, service.Port.Number)
return fmt.Sprintf("%s_%s_%d", namespace, service.Name, service.Port.Number)
}
if service.Port.Name != "" {
return fmt.Sprintf("%s-%s-%s", namespace, service.Name, service.Port.Name)
return fmt.Sprintf("%s_%s_%s", namespace, service.Name, service.Port.Name)
}
}
return fmt.Sprintf("%s-INVALID", namespace)
return fmt.Sprintf("%s_INVALID", namespace)
}
// upstreamServiceNameAndPort verifies if service is not nil, and then return the

View file

@ -1091,8 +1091,8 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
f.WaitForNginxServer("_",
func(server string) bool {
upstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s-%s-%s";`, f.Namespace, framework.HTTPBunService, "80")
canaryUpstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s-%s-%s";`, f.Namespace, canaryService, "80")
upstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s_%s_%s";`, f.Namespace, framework.HTTPBunService, "80")
canaryUpstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s_%s_%s";`, f.Namespace, canaryService, "80")
return strings.Contains(server, fmt.Sprintf(`set $ingress_name "%v";`, host)) &&
!strings.Contains(server, `set $proxy_upstream_name "upstream-default-backend";`) &&

View file

@ -32,7 +32,7 @@ import (
// GetLbAlgorithm returns algorithm identifier for the given backend
func (f *Framework) GetLbAlgorithm(serviceName string, servicePort int) (string, error) {
backendName := fmt.Sprintf("%s-%s-%v", f.Namespace, serviceName, servicePort)
backendName := fmt.Sprintf("%s_%s_%v", f.Namespace, serviceName, servicePort)
cmd := fmt.Sprintf("/dbg backends get %s", backendName)
output, err := f.ExecIngressPod(cmd)

View file

@ -68,7 +68,7 @@ var _ = framework.IngressNginxDescribe("[SSL] [Flag] default-ssl-certificate", f
f.EnsureIngress(ing)
ginkgo.By("making sure new ingress is deployed")
expectedConfig := fmt.Sprintf(`set $proxy_upstream_name "%v-%v-%v";`, f.Namespace, service, port)
expectedConfig := fmt.Sprintf(`set $proxy_upstream_name "%v_%v_%v";`, f.Namespace, service, port)
f.WaitForNginxServer("_", func(cfg string) bool {
return strings.Contains(cfg, expectedConfig)
})
@ -90,7 +90,7 @@ var _ = framework.IngressNginxDescribe("[SSL] [Flag] default-ssl-certificate", f
assert.Nil(ginkgo.GinkgoT(), err)
ginkgo.By("making sure new ingress is deployed")
expectedConfig := fmt.Sprintf(`set $proxy_upstream_name "%v-%v-%v";`, f.Namespace, service, port)
expectedConfig := fmt.Sprintf(`set $proxy_upstream_name "%v_%v_%v";`, f.Namespace, service, port)
f.WaitForNginxServer(host, func(cfg string) bool {
return strings.Contains(cfg, expectedConfig)
})

View file

@ -37,7 +37,7 @@ var _ = framework.IngressNginxDescribe("Dynamic $proxy_host", func() {
disableSnippet := f.AllowSnippetConfiguration()
defer disableSnippet()
upstreamName := fmt.Sprintf("%v-%v-80", f.Namespace, framework.EchoService)
upstreamName := fmt.Sprintf("%v_%v_80", f.Namespace, framework.EchoService)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/configuration-snippet": `more_set_headers "Custom-Header: $proxy_host"`,
}
@ -61,7 +61,7 @@ var _ = framework.IngressNginxDescribe("Dynamic $proxy_host", func() {
disableSnippet := f.AllowSnippetConfiguration()
defer disableSnippet()
upstreamName := fmt.Sprintf("%v-%v-80", f.Namespace, framework.EchoService)
upstreamName := fmt.Sprintf("%v_%v_80", f.Namespace, framework.EchoService)
upstreamVHost := "different.host"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-vhost": upstreamVHost,