Skip to content
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
42 changes: 21 additions & 21 deletions internal/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2609,19 +2609,19 @@ func (lbc *LoadBalancerController) createIngressEx(ing *networking.Ingress, vali
func (lbc *LoadBalancerController) getAppProtectLogConfAndDst(ing *networking.Ingress) ([]configs.AppProtectLog, error) {
var apLogs []configs.AppProtectLog
if _, exists := ing.Annotations[configs.AppProtectLogConfDstAnnotation]; !exists {
return apLogs, fmt.Errorf("Error: %v requires %v in %v", configs.AppProtectLogConfAnnotation, configs.AppProtectLogConfDstAnnotation, ing.Name)
return apLogs, fmt.Errorf("error: %v requires %v in %v", configs.AppProtectLogConfAnnotation, configs.AppProtectLogConfDstAnnotation, ing.Name)
}

logDsts := strings.Split(ing.Annotations[configs.AppProtectLogConfDstAnnotation], ",")
logConfNsNs := appprotectcommon.ParseResourceReferenceAnnotationList(ing.Namespace, ing.Annotations[configs.AppProtectLogConfAnnotation])
if len(logDsts) != len(logConfNsNs) {
return apLogs, fmt.Errorf("Error Validating App Protect Destination and Config for Ingress %v: LogConf and LogDestination must have equal number of items", ing.Name)
return apLogs, fmt.Errorf("error Validating App Protect Destination and Config for Ingress %v: LogConf and LogDestination must have equal number of items", ing.Name)
}

for i, logConfNsN := range logConfNsNs {
logConf, err := lbc.appProtectConfiguration.GetAppResource(appprotect.LogConfGVK.Kind, logConfNsN)
if err != nil {
return apLogs, fmt.Errorf("Error retrieving App Protect Log Config for Ingress %v: %w", ing.Name, err)
return apLogs, fmt.Errorf("error retrieving App Protect Log Config for Ingress %v: %w", ing.Name, err)
}
apLogs = append(apLogs, configs.AppProtectLog{
LogConf: logConf,
Expand All @@ -2637,7 +2637,7 @@ func (lbc *LoadBalancerController) getAppProtectPolicy(ing *networking.Ingress)

apPolicy, err = lbc.appProtectConfiguration.GetAppResource(appprotect.PolicyGVK.Kind, polNsN)
if err != nil {
return nil, fmt.Errorf("Error retrieving App Protect Policy for Ingress %v: %w", ing.Name, err)
return nil, fmt.Errorf("error retrieving App Protect Policy for Ingress %v: %w", ing.Name, err)
}

return apPolicy, nil
Expand Down Expand Up @@ -2943,12 +2943,12 @@ func (lbc *LoadBalancerController) getPolicies(policies []conf_v1.PolicyReferenc
}
}
if err != nil {
errors = append(errors, fmt.Errorf("Failed to get policy %s: %w", policyKey, err))
errors = append(errors, fmt.Errorf("failed to get policy %s: %w", policyKey, err))
continue
}

if !exists {
errors = append(errors, fmt.Errorf("Policy %s doesn't exist", policyKey))
errors = append(errors, fmt.Errorf("policy %s doesn't exist", policyKey))
continue
}

Expand All @@ -2961,7 +2961,7 @@ func (lbc *LoadBalancerController) getPolicies(policies []conf_v1.PolicyReferenc

err = validation.ValidatePolicy(policy, lbc.isNginxPlus, lbc.enableOIDC, lbc.appProtectEnabled)
if err != nil {
errors = append(errors, fmt.Errorf("Policy %s is invalid: %w", policyKey, err))
errors = append(errors, fmt.Errorf("policy %s is invalid: %w", policyKey, err))
continue
}

Expand Down Expand Up @@ -3238,7 +3238,7 @@ func (lbc *LoadBalancerController) createTransportServerEx(transportServer *conf
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: %w", upstreamService, err)
}

backend := &networking.IngressBackend{
Expand All @@ -3252,7 +3252,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: %w", upstreamService, err)
}

return endps, isExternal, err
Expand All @@ -3261,7 +3261,7 @@ func (lbc *LoadBalancerController) getEndpointsForUpstream(namespace string, ups
func (lbc *LoadBalancerController) getEndpointsForSubselector(namespace string, upstream conf_v1.Upstream) (endps []podEndpoint, err error) {
svc, err := lbc.getServiceForUpstream(namespace, upstream.Service, upstream.Port)
if err != nil {
return nil, fmt.Errorf("Error getting service %v: %w", upstream.Service, err)
return nil, fmt.Errorf("error getting service %v: %w", upstream.Service, err)
}

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

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

endps, err = lbc.getEndpointsForServiceWithSubselector(targetPort, upstream.Subselector, svc)
if err != nil {
return nil, fmt.Errorf("Error retrieving endpoints for the service %v: %w", upstream.Service, err)
return nil, fmt.Errorf("error retrieving endpoints for the service %v: %w", upstream.Service, err)
}

return endps, err
Expand All @@ -3297,7 +3297,7 @@ func (lbc *LoadBalancerController) getEndpointsForServiceWithSubselector(targetP
}
}
if err != nil {
return nil, fmt.Errorf("Error getting pods in namespace %v that match the selector %v: %w", svc.Namespace, labels.Merge(svc.Spec.Selector, subselector), err)
return nil, fmt.Errorf("error getting pods in namespace %v that match the selector %v: %w", svc.Namespace, labels.Merge(svc.Spec.Selector, subselector), err)
}

var svcEps api_v1.Endpoints
Expand Down Expand Up @@ -3432,7 +3432,7 @@ func (lbc *LoadBalancerController) getEndpointsForIngressBackend(backend *networ
if err != nil {
if svc.Spec.Type == api_v1.ServiceTypeExternalName {
if !lbc.isNginxPlus {
return nil, false, fmt.Errorf("Type ExternalName Services feature is only available in NGINX Plus")
return nil, false, fmt.Errorf("type ExternalName Services feature is only available in NGINX Plus")
}
result = lbc.getExternalEndpointsForIngressBackend(backend, svc)
return result, true, nil
Expand All @@ -3457,14 +3457,14 @@ func (lbc *LoadBalancerController) getEndpointsForPort(endps api_v1.Endpoints, b
if (backendPort.Name == "" && port.Port == backendPort.Number) || port.Name == backendPort.Name {
targetPort, err = lbc.getTargetPort(port, svc)
if err != nil {
return nil, fmt.Errorf("Error determining target port for port %v in Ingress: %w", backendPort, err)
return nil, fmt.Errorf("error determining target port for port %v in Ingress: %w", backendPort, err)
}
break
}
}

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", backendPort, svc.Name)
}

for _, subset := range endps.Subsets {
Expand All @@ -3489,7 +3489,7 @@ func (lbc *LoadBalancerController) getEndpointsForPort(endps api_v1.Endpoints, b
}
}

return nil, fmt.Errorf("No endpoints for target port %v in service %s", targetPort, svc.Name)
return nil, fmt.Errorf("no endpoints for target port %v in service %s", targetPort, svc.Name)
}

func (lbc *LoadBalancerController) getPodOwnerTypeAndNameFromAddress(ns, name string) (parentType, parentName string) {
Expand Down Expand Up @@ -3556,18 +3556,18 @@ func (lbc *LoadBalancerController) getTargetPort(svcPort api_v1.ServicePort, svc
}
}
if err != nil {
return 0, fmt.Errorf("Error getting pod information: %w", err)
return 0, fmt.Errorf("error getting pod information: %w", err)
}

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

pod := pods[0]

portNum, err := findPort(pod, svcPort)
if err != nil {
return 0, fmt.Errorf("Error finding named port %v in pod %s: %w", svcPort, pod.Name, err)
return 0, fmt.Errorf("error finding named port %v in pod %s: %w", svcPort, pod.Name, err)
}

return portNum, nil
Expand Down
Loading