Avoid closing over range variables

This commit is contained in:
Maciej Szulik 2017-01-10 16:53:49 +01:00
parent 6f37347fce
commit 19a25e480f
2 changed files with 4 additions and 3 deletions

View File

@ -41,7 +41,7 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
case "metadata.name", "metadata.namespace", "status.successful":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
return "", "", fmt.Errorf("field label %q not supported for Job", label)
}
},
)

View File

@ -36,14 +36,15 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
}
// Add field label conversions for kinds having selectable nothing but ObjectMeta fields.
for _, kind := range []string{"Job", "JobTemplate", "CronJob"} {
for _, k := range []string{"Job", "JobTemplate", "CronJob"} {
kind := k // don't close over range variables
err = scheme.AddFieldLabelConversionFunc("batch/v2alpha1", kind,
func(label, value string) (string, string, error) {
switch label {
case "metadata.name", "metadata.namespace", "status.successful":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
return "", "", fmt.Errorf("field label %q not supported for %q", label, kind)
}
})
if err != nil {