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