Reduce logs with new Kubernetes security annotations

This commit is contained in:
Ludovic Fernandez 2017-12-01 14:00:04 +01:00 committed by Traefiker
parent c228e73b26
commit aaf120f263

View file

@ -19,7 +19,7 @@ func getBoolAnnotation(meta *v1beta1.Ingress, name string, defaultValue bool) bo
case annotationStringValue == "true":
annotationValue = true
default:
log.Warnf("Unknown value %q for %q, falling back to %q", annotationStringValue, name, defaultValue)
log.Warnf("Unknown value %q for %q, falling back to %v", annotationStringValue, name, defaultValue)
}
return annotationValue
}
@ -41,21 +41,30 @@ func getSliceAnnotation(meta *v1beta1.Ingress, name string) []string {
return value
}
func getMapAnnotation(meta *v1beta1.Ingress, name string) map[string]string {
value := make(map[string]string)
if annotation := meta.Annotations[name]; annotation != "" {
for _, v := range strings.Split(annotation, ",") {
pair := strings.Split(v, ":")
func getMapAnnotation(meta *v1beta1.Ingress, annotName string) map[string]string {
if values, ok := meta.Annotations[annotName]; ok {
if len(values) == 0 {
log.Errorf("Missing value for annotation %q", annotName)
return nil
}
mapValue := make(map[string]string)
for _, parts := range strings.Split(values, ",") {
pair := strings.Split(parts, ":")
if len(pair) != 2 {
log.Debugf("Could not load annotation (%v) with value: %v, skipping...", name, pair)
log.Warnf("Could not load %q: %v, skipping...", annotName, pair)
} else {
value[pair[0]] = pair[1]
mapValue[pair[0]] = pair[1]
}
}
if len(mapValue) == 0 {
log.Errorf("Could not load %q, skipping...", annotName)
return nil
}
return mapValue
}
if len(value) == 0 {
log.Debugf("Could not load %v annotation, skipping...", name)
return nil
}
return value
return nil
}