Log the ignored namespace only when needed
This commit is contained in:
parent
807dc46ad0
commit
7283d7eb2f
1 changed files with 9 additions and 14 deletions
|
@ -380,11 +380,11 @@ func (c configBuilder) nameAndService(ctx context.Context, namespaceService stri
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fullName := fullServiceName(svcCtx, namespace, service.Name, service.Port)
|
fullName := fullServiceName(svcCtx, namespace, service, service.Port)
|
||||||
|
|
||||||
return fullName, serversLB, nil
|
return fullName, serversLB, nil
|
||||||
case service.Kind == "TraefikService":
|
case service.Kind == "TraefikService":
|
||||||
return fullServiceName(svcCtx, namespace, service.Name, 0), nil, nil
|
return fullServiceName(svcCtx, namespace, service, 0), nil, nil
|
||||||
default:
|
default:
|
||||||
return "", nil, fmt.Errorf("unsupported service kind %s", service.Kind)
|
return "", nil, fmt.Errorf("unsupported service kind %s", service.Kind)
|
||||||
}
|
}
|
||||||
|
@ -399,27 +399,22 @@ func splitSvcNameProvider(name string) (string, string) {
|
||||||
return svc, pvd
|
return svc, pvd
|
||||||
}
|
}
|
||||||
|
|
||||||
func fullServiceName(ctx context.Context, namespace, serviceName string, port int32) string {
|
func fullServiceName(ctx context.Context, namespace string, service v1alpha1.LoadBalancerSpec, port int32) string {
|
||||||
if port != 0 {
|
if port != 0 {
|
||||||
return provider.Normalize(fmt.Sprintf("%s-%s-%d", namespace, serviceName, port))
|
return provider.Normalize(fmt.Sprintf("%s-%s-%d", namespace, service.Name, port))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(serviceName, providerNamespaceSeparator) {
|
if !strings.Contains(service.Name, providerNamespaceSeparator) {
|
||||||
return provider.Normalize(fmt.Sprintf("%s-%s", namespace, serviceName))
|
return provider.Normalize(fmt.Sprintf("%s-%s", namespace, service.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
name, pName := splitSvcNameProvider(serviceName)
|
name, pName := splitSvcNameProvider(service.Name)
|
||||||
if pName == providerName {
|
if pName == providerName {
|
||||||
return provider.Normalize(fmt.Sprintf("%s-%s", namespace, name))
|
return provider.Normalize(fmt.Sprintf("%s-%s", namespace, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, if namespace == "default", we do not know whether it had been intentionally set as such,
|
if service.Namespace != "" {
|
||||||
// or if we're simply hitting the value set by default.
|
log.FromContext(ctx).Warnf("namespace %q is ignored in cross-provider context", service.Namespace)
|
||||||
// But as it is most likely very much the latter,
|
|
||||||
// and we do not want to systematically log spam users in that case,
|
|
||||||
// we skip logging whenever the namespace is "default".
|
|
||||||
if namespace != "default" {
|
|
||||||
log.FromContext(ctx).Warnf("namespace %q is ignored in cross-provider context", namespace)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider.Normalize(name) + providerNamespaceSeparator + pName
|
return provider.Normalize(name) + providerNamespaceSeparator + pName
|
||||||
|
|
Loading…
Add table
Reference in a new issue