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 statefulset cross-namespace #1139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions pkg/qdr/qdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,17 @@ func GetRouterConfigForHeadlessProxy(definition types.ServiceInterface, siteId s
})
svcPorts := definition.Ports
ports := map[int]int{}
targetNs := namespace

if len(definition.Targets) > 0 {
ports = definition.Targets[0].TargetPorts
} else {
target := definition.Targets[0]
targetNs = target.Namespace
if len(target.TargetPorts) > 0 {
ports = target.TargetPorts
}
}

if len(ports) == 0 {
for _, sp := range svcPorts {
ports[sp] = sp
}
Expand All @@ -1067,7 +1075,7 @@ func GetRouterConfigForHeadlessProxy(definition types.ServiceInterface, siteId s
address := fmt.Sprintf("%s-%s:%d", definition.Address, "${POD_ID}", iPort)
if definition.IsOfLocalOrigin() {
name := fmt.Sprintf("egress:%d", ePort)
host := definition.Headless.Name + "-${POD_ID}." + definition.Address + "." + namespace
host := definition.Headless.Name + "-${POD_ID}." + definition.Address + "." + targetNs
// in the originating site, just have egress bindings
switch definition.Protocol {
case "tcp":
Expand Down
177 changes: 177 additions & 0 deletions pkg/qdr/qdr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,180 @@ func TestGetSslProfilesDifference(t *testing.T) {
assert.Assert(t, utils.StringSlicesEqual(deletedSslProfiles, expectedDeletedSslProfiles), "Expected %v but got %v", expectedDeletedSslProfiles, deletedSslProfiles)

}

func TestGetRouterConfigForHeadlessProxy(t *testing.T) {
type test struct {
name string
definition types.ServiceInterface
site string
version string
namespace string
expectedResult BridgeConfig
}

testTable := []test{
{
name: "definition-with-targets",
definition: types.ServiceInterface{
Origin: "",
Address: "address",
Protocol: "tcp",
Ports: []int{9000},
Headless: &types.Headless{
Name: "dummy",
},
Targets: []types.ServiceInterfaceTarget{{
Name: "target-1",
Selector: "app=dummy",
Namespace: "default",
TargetPorts: map[int]int{
3000: 3000,
},
}},
},
site: "site-1",
version: "version-1",
namespace: "namespace-1",
expectedResult: BridgeConfig{
TcpConnectors: TcpEndpointMap{
"egress:3000": TcpEndpoint{
Name: "egress:3000",
Host: "dummy-${POD_ID}.address.default",
Port: "3000",
Address: "address-${POD_ID}:3000",
SiteId: "site-1",
},
},
TcpListeners: TcpEndpointMap{},
HttpConnectors: HttpEndpointMap{},
HttpListeners: HttpEndpointMap{},
},
},
{
name: "definition-without-targets",
definition: types.ServiceInterface{
Origin: "",
Address: "address",
Protocol: "tcp",
Ports: []int{9000},
Headless: &types.Headless{
Name: "dummy",
},
},
site: "site-1",
version: "version-1",
namespace: "namespace-1",
expectedResult: BridgeConfig{
TcpConnectors: TcpEndpointMap{
"egress:9000": TcpEndpoint{
Name: "egress:9000",
Host: "dummy-${POD_ID}.address.namespace-1",
Port: "9000",
Address: "address-${POD_ID}:9000",
SiteId: "site-1",
},
},
TcpListeners: TcpEndpointMap{},
HttpConnectors: HttpEndpointMap{},
HttpListeners: HttpEndpointMap{},
},
},
{
name: "definition-without-targets-http",
definition: types.ServiceInterface{
Origin: "",
Address: "address",
Protocol: "http",
Ports: []int{9000},
Headless: &types.Headless{
Name: "dummy",
},
},
site: "site-1",
version: "version-1",
namespace: "namespace-1",
expectedResult: BridgeConfig{
TcpConnectors: TcpEndpointMap{},
TcpListeners: TcpEndpointMap{},
HttpConnectors: HttpEndpointMap{
"egress:9000": HttpEndpoint{
Name: "egress:9000",
Host: "dummy-${POD_ID}.address.namespace-1",
Port: "9000",
Address: "address-${POD_ID}:9000",
SiteId: "site-1",
},
},
HttpListeners: HttpEndpointMap{},
},
},
{
name: "definition-external-origin",
definition: types.ServiceInterface{
Origin: "external",
Address: "address",
Protocol: "tcp",
Ports: []int{9000},
Headless: &types.Headless{
Name: "dummy",
},
},
site: "site-1",
version: "version-1",
namespace: "namespace-1",
expectedResult: BridgeConfig{
TcpConnectors: TcpEndpointMap{},
TcpListeners: TcpEndpointMap{
"ingress:9000": TcpEndpoint{
Name: "ingress:9000",
Host: "",
Port: "9000",
Address: "address-${POD_ID}:9000",
SiteId: "site-1",
},
},
HttpConnectors: HttpEndpointMap{},
HttpListeners: HttpEndpointMap{},
},
},
{
name: "definition-external-http",
definition: types.ServiceInterface{
Origin: "external",
Address: "address",
Protocol: "http",
Ports: []int{9000},
Headless: &types.Headless{
Name: "dummy",
},
},
site: "site-1",
version: "version-1",
namespace: "namespace-1",
expectedResult: BridgeConfig{
TcpConnectors: TcpEndpointMap{},
TcpListeners: TcpEndpointMap{},
HttpConnectors: HttpEndpointMap{},
HttpListeners: HttpEndpointMap{
"ingress:9000": HttpEndpoint{
Name: "ingress:9000",
Host: "",
Port: "9000",
Address: "address-${POD_ID}:9000",
SiteId: "site-1",
},
},
},
},
}

for _, test := range testTable {
t.Run(test.name, func(t *testing.T) {
expectedResult := test.expectedResult
actualResult, _ := GetRouterConfigForHeadlessProxy(test.definition, test.site, test.version, test.namespace)
routerConfig, _ := UnmarshalRouterConfig(actualResult)

assert.Assert(t, reflect.DeepEqual(expectedResult, routerConfig.Bridges))
})
}
}
12 changes: 12 additions & 0 deletions pkg/service/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ func (bindings *ServiceBindings) AsServiceInterface() types.ServiceInterface {
if bindings.ingressBinding != nil {
mode = bindings.ingressBinding.Mode()
}

targets := []types.ServiceInterfaceTarget{}
for key, egress := range bindings.targets {
targets = append(targets, types.ServiceInterfaceTarget{
Name: egress.name,
Selector: egress.Selector,
Service: egress.service,
Namespace: key.namespace,
})
}

return types.ServiceInterface{
Address: bindings.Address,
Protocol: bindings.protocol,
Expand All @@ -132,6 +143,7 @@ func (bindings *ServiceBindings) AsServiceInterface() types.ServiceInterface {
TlsCredentials: bindings.TlsCredentials,
TlsCertAuthority: bindings.TlsCertAuthority,
PublishNotReadyAddresses: bindings.PublishNotReadyAddresses,
Targets: targets,
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/service/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ func TestNewServiceBindings(t *testing.T) {
}
}
si := b.AsServiceInterface()
si.Targets = nil
copy := s.service
copy.Targets = nil
assert.DeepEqual(t, si, copy)
Expand Down