Skip to content

Commit

Permalink
fix(plugin): webhook errors contained []byte value (#671)
Browse files Browse the repository at this point in the history
In case a value is invalid, the error should show the invalid value
rendered as a string instead of the []byte.
  • Loading branch information
IvoGoman authored Oct 28, 2024
1 parent 1ba5c64 commit 087721e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/admission/plugin_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package admission

import (
"context"
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -199,8 +200,12 @@ func validatePluginOptionValues(optionValues []greenhousev1alpha1.PluginOptionVa
// validate that the Plugin.OptionValue matches the type of the PluginDefinition.Option
if val.Value != nil {
if err := pluginOption.IsValidValue(val.Value); err != nil {
var v any
if err := json.Unmarshal(val.Value.Raw, &v); err != nil {
v = err
}
allErrs = append(allErrs, field.Invalid(
fieldPathWithIndex.Child("value"), val.Value.Raw, err.Error(),
fieldPathWithIndex.Child("value"), v, err.Error(),
))
}
}
Expand Down

0 comments on commit 087721e

Please sign in to comment.