Skip to content

Commit

Permalink
refactor: apply review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored and traefiker committed Dec 1, 2017
1 parent ad15cf3 commit b439288
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions provider/kubernetes/annotations_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -41,21 +41,26 @@ func getSliceAnnotation(meta *v1beta1.Ingress, name string) []string {
return value
}

func getMapAnnotation(meta *v1beta1.Ingress, labelName string) map[string]string {
if values, ok := meta.Annotations[labelName]; ok {
mapValue := make(map[string]string)
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.Warnf("Could not load %q: %v, skipping...", labelName, pair)
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...", labelName)
log.Errorf("Could not load %q, skipping...", annotName)
return nil
}
return mapValue
Expand Down

0 comments on commit b439288

Please sign in to comment.