Skip to content
Draft
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
38 changes: 19 additions & 19 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,7 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
var external bool
svc, err := lbc.getServiceForIngressBackend(ing.Spec.DefaultBackend, ing.Namespace)
if err != nil {
nl.Warnf(lbc.Logger, "Error getting service %v: %v", ing.Spec.DefaultBackend.Service.Name, err)
nl.Warnf(lbc.Logger, "Error getting service %v/%v: %v", ing.Namespace, ing.Spec.DefaultBackend.Service.Name, err)
} else {
podEndps, external, err = lbc.getEndpointsForIngressBackend(ing.Spec.DefaultBackend, svc)
if err == nil && external && lbc.isNginxPlus {
Expand All @@ -2251,7 +2251,7 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
}

if err != nil {
nl.Warnf(lbc.Logger, "Error retrieving endpoints for the service %v: %v", ing.Spec.DefaultBackend.Service.Name, err)
nl.Warnf(lbc.Logger, "Error retrieving endpoints for the service %v/%v: %v", ing.Namespace, ing.Spec.DefaultBackend.Service.Name, err)
}

if svc != nil && !external && hasUseClusterIP {
Expand Down Expand Up @@ -2310,7 +2310,7 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
var external bool
svc, err := lbc.getServiceForIngressBackend(&path.Backend, ing.Namespace)
if err != nil {
nl.Debugf(lbc.Logger, "Error getting service %v: %v", &path.Backend.Service.Name, err)
nl.Debugf(lbc.Logger, "Error getting service %v/%v: %v", ing.Namespace, path.Backend.Service.Name, err)
} else {
podEndps, external, err = lbc.getEndpointsForIngressBackend(&path.Backend, svc)
if err == nil && external && lbc.isNginxPlus {
Expand All @@ -2319,7 +2319,7 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
}

if err != nil {
nl.Warnf(lbc.Logger, "Error retrieving endpoints for the service %v: %v", path.Backend.Service.Name, err)
nl.Warnf(lbc.Logger, "Error retrieving endpoints for the service %v/%v: %v", ing.Namespace, path.Backend.Service.Name, err)
}

if svc != nil && !external && hasUseClusterIP {
Expand Down Expand Up @@ -2474,7 +2474,7 @@ func (lbc *LoadBalancerController) createVirtualServerEx(virtualServer *conf_v1.
if u.UseClusterIP {
s, err := lbc.getServiceForUpstream(serviceNamespace, serviceName, u.Port)
if err != nil {
nl.Warnf(lbc.Logger, "Error getting Service for Upstream %v: %v", u.Service, err)
nl.Warnf(lbc.Logger, "Error getting Service for Upstream %v/%v: %v", serviceNamespace, u.Service, err)
} else {
endps = append(endps, ipv6SafeAddrPort(s.Spec.ClusterIP, int32(u.Port)))
}
Expand Down Expand Up @@ -2622,7 +2622,7 @@ func (lbc *LoadBalancerController) createVirtualServerEx(virtualServer *conf_v1.
if u.UseClusterIP {
s, err := lbc.getServiceForUpstream(serviceNamespace, serviceName, u.Port)
if err != nil {
nl.Warnf(lbc.Logger, "Error getting Service for Upstream %v: %v", u.Service, err)
nl.Warnf(lbc.Logger, "Error getting Service for Upstream %v/%v: %v", serviceNamespace, serviceName, err)
} else {
endps = append(endps, fmt.Sprintf("%s:%d", s.Spec.ClusterIP, u.Port))
}
Expand Down Expand Up @@ -2949,7 +2949,7 @@ func (lbc *LoadBalancerController) getTransportServerBackupEndpointsAndKey(trans
func (lbc *LoadBalancerController) getEndpointsForUpstream(namespace string, upstreamService string, upstreamPort uint16) (endps []podEndpoint, isExternal bool, err error) {
svc, err := lbc.getServiceForUpstream(namespace, upstreamService, upstreamPort)
if err != nil {
return nil, false, fmt.Errorf("error getting service %v: %w", upstreamService, err)
return nil, false, fmt.Errorf("error getting service %v/%v: %w", namespace, upstreamService, err)
}

backend := &networking.IngressBackend{
Expand All @@ -2963,7 +2963,7 @@ func (lbc *LoadBalancerController) getEndpointsForUpstream(namespace string, ups

endps, isExternal, err = lbc.getEndpointsForIngressBackend(backend, svc)
if err != nil {
return nil, false, fmt.Errorf("error retrieving endpoints for the service %v: %w", upstreamService, err)
return nil, false, fmt.Errorf("error retrieving endpoints for the service %v/%v: %w", namespace, upstreamService, err)
}

return endps, isExternal, err
Expand All @@ -2972,7 +2972,7 @@ func (lbc *LoadBalancerController) getEndpointsForUpstream(namespace string, ups
func (lbc *LoadBalancerController) getEndpointsForSubselector(namespace string, serviceName string, servicePort uint16, subselector map[string]string) (endps []podEndpoint, err error) {
svc, err := lbc.getServiceForUpstream(namespace, serviceName, servicePort)
if err != nil {
return nil, fmt.Errorf("error getting service %v: %w", serviceName, err)
return nil, fmt.Errorf("error getting service %v/%v: %w", namespace, serviceName, err)
}

var targetPort int32
Expand All @@ -2981,19 +2981,19 @@ func (lbc *LoadBalancerController) getEndpointsForSubselector(namespace string,
if port.Port == int32(servicePort) {
targetPort, err = lbc.getTargetPort(port, svc)
if err != nil {
return nil, fmt.Errorf("error determining target port for port %v in service %v: %w", servicePort, svc.Name, err)
return nil, fmt.Errorf("error determining target port for port %v in service %v/%v: %w", servicePort, svc.Namespace, svc.Name, err)
}
break
}
}

if targetPort == 0 {
return nil, fmt.Errorf("no port %v in service %s", servicePort, svc.Name)
return nil, fmt.Errorf("no port %v in service %s/%s", servicePort, svc.Namespace, svc.Name)
}

endps, err = lbc.getEndpointsForServiceWithSubselector(targetPort, subselector, svc)
if err != nil {
return nil, fmt.Errorf("error retrieving endpoints for the service %v: %w", serviceName, err)
return nil, fmt.Errorf("error retrieving endpoints for the service %v/%v: %w", namespace, serviceName, err)
}

return endps, err
Expand All @@ -3010,7 +3010,7 @@ func (lbc *LoadBalancerController) getEndpointsForServiceWithSubselector(targetP
var svcEndpointSlices []discovery_v1.EndpointSlice
svcEndpointSlices, err = nsi.endpointSliceLister.GetServiceEndpointSlices(svc)
if err != nil {
nl.Debugf(lbc.Logger, "Error getting endpointslices for service %s from the cache: %v", svc.Name, err)
nl.Debugf(lbc.Logger, "Error getting endpointslices for service %s/%s from the cache: %v", svc.Namespace, svc.Name, err)
return nil, err
}

Expand Down Expand Up @@ -3094,7 +3094,7 @@ func getPodName(pod *api_v1.ObjectReference) string {
func (lbc *LoadBalancerController) getHealthChecksForIngressBackend(backend *networking.IngressBackend, namespace string) *api_v1.Probe {
svc, err := lbc.getServiceForIngressBackend(backend, namespace)
if err != nil {
nl.Debugf(lbc.Logger, "Error getting service %v: %v", backend.Service.Name, err)
nl.Debugf(lbc.Logger, "Error getting service %v/%v: %v", namespace, backend.Service.Name, err)
return nil
}
svcPort := lbc.getServicePortForIngressPort(backend.Service.Port, svc)
Expand Down Expand Up @@ -3164,13 +3164,13 @@ func (lbc *LoadBalancerController) getEndpointsForIngressBackend(backend *networ
result = lbc.getExternalEndpointsForIngressBackend(backend, svc)
return result, true, nil
}
nl.Debugf(lbc.Logger, "Error getting endpoints for service %s from the cache: %v", svc.Name, err)
nl.Debugf(lbc.Logger, "Error getting endpoints for service %s/%s from the cache: %v", svc.Namespace, svc.Name, err)
return nil, false, err
}

result, err = lbc.getEndpointsForPortFromEndpointSlices(endpointSlices, backend.Service.Port, svc)
if err != nil {
nl.Debugf(lbc.Logger, "Error getting endpointslices for service %s port %v: %v", svc.Name, configs.GetBackendPortAsString(backend.Service.Port), err)
nl.Debugf(lbc.Logger, "Error getting endpointslices for service %s/%s port %v: %v", svc.Namespace, svc.Name, configs.GetBackendPortAsString(backend.Service.Port), err)
return nil, false, err
}
return result, false, nil
Expand All @@ -3191,7 +3191,7 @@ func (lbc *LoadBalancerController) getEndpointsForPortFromEndpointSlices(endpoin
}

if targetPort == 0 {
return nil, fmt.Errorf("no port %v in service %s", backendPort, svc.Name)
return nil, fmt.Errorf("no port %v in service %s/%s", backendPort, svc.Namespace, svc.Name)
}

makePodEndpoints := func(port int32, epx []discovery_v1.Endpoint) []podEndpoint {
Expand All @@ -3217,7 +3217,7 @@ func (lbc *LoadBalancerController) getEndpointsForPortFromEndpointSlices(endpoin

endpoints := makePodEndpoints(targetPort, filterReadyEndpointsFrom(selectEndpointSlicesForPort(targetPort, endpointSlices)))
if len(endpoints) == 0 {
return nil, fmt.Errorf("no endpointslices for target port %v in service %s", targetPort, svc.Name)
return nil, fmt.Errorf("no endpointslices for target port %v in service %s/%s", targetPort, svc.Namespace, svc.Name)
}
return endpoints, nil
}
Expand Down Expand Up @@ -3281,7 +3281,7 @@ func (lbc *LoadBalancerController) getTargetPort(svcPort api_v1.ServicePort, svc
}

if len(pods) == 0 {
return 0, fmt.Errorf("no pods of service %s", svc.Name)
return 0, fmt.Errorf("no pods of service %s/%s", svc.Namespace, svc.Name)
}

pod := pods[0]
Expand Down
28 changes: 23 additions & 5 deletions tests/suite/test_virtual_server_foreign_upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
create_namespace_with_name_from_yaml,
delete_items_from_yaml,
delete_namespace,
get_first_pod_name,
wait_before_test,
wait_until_all_pods_are_ready,
)
Expand All @@ -15,6 +16,7 @@
create_virtual_server_from_yaml,
delete_v_s_route,
delete_virtual_server,
get_vs_nginx_template_conf,
patch_virtual_server_from_yaml,
)
from suite.utils.yaml_utils import (
Expand Down Expand Up @@ -44,11 +46,7 @@ def virtual_server_foreign_upstream_app_setup(
:param test_namespace:
:return: VirtualServerSetup
"""
print("------------------------- Deploy Virtual Server Example -----------------------------------")
vs_source = f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml"
vs_name = create_virtual_server_from_yaml(kube_apis.custom_objects, vs_source, test_namespace)
vs_host = get_first_host_from_yaml(vs_source)
vs_paths = get_paths_from_vs_yaml(vs_source)
upstream_namespaces = get_upstream_namespace_from_vs_yaml(vs_source, test_namespace)
print(f"Upstream namespaces detected in the VS yaml: {upstream_namespaces}")
ns_1 = (
Expand All @@ -61,12 +59,17 @@ def virtual_server_foreign_upstream_app_setup(
if upstream_namespaces[1] != test_namespace
else test_namespace
)
print("------------------------- Deploy Virtual Server Example -----------------------------------")
create_items_from_yaml(kube_apis, f"{TEST_DATA}/common/app/{request.param['app_type']}/backend1.yaml", ns_1)
create_items_from_yaml(kube_apis, f"{TEST_DATA}/common/app/{request.param['app_type']}/backend2.yaml", ns_2)

wait_until_all_pods_are_ready(kube_apis.v1, ns_1)
wait_until_all_pods_are_ready(kube_apis.v1, ns_2)

vs_name = create_virtual_server_from_yaml(kube_apis.custom_objects, vs_source, test_namespace)
vs_host = get_first_host_from_yaml(vs_source)
vs_paths = get_paths_from_vs_yaml(vs_source)

def fin():
if request.config.getoption("--skip-fixture-teardown") == "no":
print("Clean up Virtual Server Example:")
Expand Down Expand Up @@ -106,8 +109,23 @@ def fin():
indirect=True,
)
class TestVirtualServerForeignUpstream:
def test_responses_after_setup(self, kube_apis, crd_ingress_controller, virtual_server_foreign_upstream_app_setup):
def test_responses_after_setup(
self,
kube_apis,
ingress_controller_prerequisites,
crd_ingress_controller,
virtual_server_foreign_upstream_app_setup,
):
print(f"\nStep 1: initial check")
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
# log VS conf
get_vs_nginx_template_conf(
kube_apis.v1,
virtual_server_foreign_upstream_app_setup.namespace,
virtual_server_foreign_upstream_app_setup.vs_name,
ic_pod_name,
ingress_controller_prerequisites.namespace,
)
wait_before_test()
wait_and_assert_status_code(
200,
Expand Down