Skip to content

Commit

Permalink
upgrade to latest dependencies (knative-extensions#698)
Browse files Browse the repository at this point in the history
bumping knative.dev/pkg 6ce976c...198b463:
  > 198b463 Cleanup: Turn multiple warnings into multiple warnings. (# 2619)
  > 728dfd8 Add FieldError#WrappedErrors to allow dependent code to have access (readonly) (# 2618)

Signed-off-by: Knative Automation <automation@knative.team>

Signed-off-by: Knative Automation <automation@knative.team>
  • Loading branch information
knative-automation authored Oct 28, 2022
1 parent 5313745 commit 79fed83
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1
knative.dev/hack v0.0.0-20221024013916-9d2ae47c16b2
knative.dev/hack/schema v0.0.0-20221024013916-9d2ae47c16b2
knative.dev/pkg v0.0.0-20221025200856-6ce976ce9255
knative.dev/pkg v0.0.0-20221027173407-198b4637065d
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ knative.dev/hack v0.0.0-20221024013916-9d2ae47c16b2 h1:DvWcy2c6wvjDo+rPRWe9Rn5QE
knative.dev/hack v0.0.0-20221024013916-9d2ae47c16b2/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/hack/schema v0.0.0-20221024013916-9d2ae47c16b2 h1:X3EYiEmuqxiVSOPG1CsuRO+QUA956BvUw79A6oXrrs0=
knative.dev/hack/schema v0.0.0-20221024013916-9d2ae47c16b2/go.mod h1:GeIb+PLd5mllawcpHEGF5J5fYTQrvgEO5liao8lUKUs=
knative.dev/pkg v0.0.0-20221025200856-6ce976ce9255 h1:zTqomdMAkcKojViE1zh7AYhmJRaL9GYzMhmXhFPZxA8=
knative.dev/pkg v0.0.0-20221025200856-6ce976ce9255/go.mod h1:j5kO7gKmWGj2DJpefCEiPbItToiYf+2bCtI+A6REkQo=
knative.dev/pkg v0.0.0-20221027173407-198b4637065d h1:sqnBiIFVRo/TWxMNF+gNgwFM2JVdWQKtrtwidTVi5Zk=
knative.dev/pkg v0.0.0-20221027173407-198b4637065d/go.mod h1:j5kO7gKmWGj2DJpefCEiPbItToiYf+2bCtI+A6REkQo=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
59 changes: 35 additions & 24 deletions vendor/knative.dev/pkg/apis/field_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ var _ error = (*FieldError)(nil)

// ViaField is used to propagate a validation error along a field access.
// For example, if a type recursively validates its "spec" via:
// if err := foo.Spec.Validate(); err != nil {
// // Augment any field paths with the context that they were accessed
// // via "spec".
// return err.ViaField("spec")
// }
//
// if err := foo.Spec.Validate(); err != nil {
// // Augment any field paths with the context that they were accessed
// // via "spec".
// return err.ViaField("spec")
// }
func (fe *FieldError) ViaField(prefix ...string) *FieldError {
if fe == nil {
return nil
Expand All @@ -114,11 +115,12 @@ func (fe *FieldError) ViaField(prefix ...string) *FieldError {

// ViaIndex is used to attach an index to the next ViaField provided.
// For example, if a type recursively validates a parameter that has a collection:
// for i, c := range spec.Collection {
// if err := doValidation(c); err != nil {
// return err.ViaIndex(i).ViaField("collection")
// }
// }
//
// for i, c := range spec.Collection {
// if err := doValidation(c); err != nil {
// return err.ViaIndex(i).ViaField("collection")
// }
// }
func (fe *FieldError) ViaIndex(index int) *FieldError {
return fe.ViaField(asIndex(index))
}
Expand All @@ -130,11 +132,12 @@ func (fe *FieldError) ViaFieldIndex(field string, index int) *FieldError {

// ViaKey is used to attach a key to the next ViaField provided.
// For example, if a type recursively validates a parameter that has a collection:
// for k, v := range spec.Bag {
// if err := doValidation(v); err != nil {
// return err.ViaKey(k).ViaField("bag")
// }
// }
//
// for k, v := range spec.Bag {
// if err := doValidation(v); err != nil {
// return err.ViaKey(k).ViaField("bag")
// }
// }
func (fe *FieldError) ViaKey(key string) *FieldError {
return fe.ViaField(asKey(key))
}
Expand All @@ -145,7 +148,8 @@ func (fe *FieldError) ViaFieldKey(field, key string) *FieldError {
}

// At is a way to alter the level of the diagnostics held in this FieldError.
// ErrMissingField("foo").At(WarningLevel)
//
// ErrMissingField("foo").At(WarningLevel)
func (fe *FieldError) At(l DiagnosticLevel) *FieldError {
if fe == nil {
return nil
Expand All @@ -166,9 +170,10 @@ func (fe *FieldError) At(l DiagnosticLevel) *FieldError {
}

// Filter is a way to access the set of diagnostics having a particular level.
// if err := x.Validate(ctx).Filter(ErrorLevel); err != nil {
// return err
// }
//
// if err := x.Validate(ctx).Filter(ErrorLevel); err != nil {
// return err
// }
func (fe *FieldError) Filter(l DiagnosticLevel) *FieldError {
if fe == nil {
return nil
Expand Down Expand Up @@ -251,10 +256,15 @@ func (fe *FieldError) normalized() []*FieldError {
return errors
}

// WrappedErrors returns the value of the errors after normalizing and deduping using merge().
func (fe *FieldError) WrappedErrors() []*FieldError {
return merge(fe.normalized())
}

// Error implements error
func (fe *FieldError) Error() string {
// Get the list of errors as a flat merged list.
normedErrors := merge(fe.normalized())
normedErrors := fe.WrappedErrors()
errs := make([]string, 0, len(normedErrors))
for _, e := range normedErrors {
if e.Details == "" {
Expand Down Expand Up @@ -282,10 +292,11 @@ func asKey(key string) string {

// flatten takes in a array of path components and looks for chances to flatten
// objects that have index prefixes, examples:
// err([0]).ViaField(bar).ViaField(foo) -> foo.bar.[0] converts to foo.bar[0]
// err(bar).ViaIndex(0).ViaField(foo) -> foo.[0].bar converts to foo[0].bar
// err(bar).ViaField(foo).ViaIndex(0) -> [0].foo.bar converts to [0].foo.bar
// err(bar).ViaIndex(0).ViaIndex(1).ViaField(foo) -> foo.[1].[0].bar converts to foo[1][0].bar
//
// err([0]).ViaField(bar).ViaField(foo) -> foo.bar.[0] converts to foo.bar[0]
// err(bar).ViaIndex(0).ViaField(foo) -> foo.[0].bar converts to foo[0].bar
// err(bar).ViaField(foo).ViaIndex(0) -> [0].foo.bar converts to [0].foo.bar
// err(bar).ViaIndex(0).ViaIndex(1).ViaField(foo) -> foo.[1].[0].bar converts to foo[1][0].bar
func flatten(path []string) string {
var newPath []string
for _, part := range path {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ func (ac *reconciler) Admit(ctx context.Context, request *admissionv1.AdmissionR
// below all overwrite `resp`, but the `defer` affords us one final
// crack at things.
defer func() {
resp.Warnings = []string{warnings.Error()}
resp.Warnings = make([]string, 0, len(warnings))
for _, w := range warnings {
resp.Warnings = append(resp.Warnings, w.Error())
}
}()
}
if errors != nil {
Expand Down Expand Up @@ -157,7 +160,7 @@ func (ac *reconciler) decodeRequestAndPrepareContext(
return ctx, newObj, nil
}

func validate(ctx context.Context, resource resourcesemantics.GenericCRD, req *admissionv1.AdmissionRequest) (err error, warn error) {
func validate(ctx context.Context, resource resourcesemantics.GenericCRD, req *admissionv1.AdmissionRequest) (err error, warn []error) {
logger := logging.FromContext(ctx)

// Only run validation for supported create and update validation.
Expand Down Expand Up @@ -187,7 +190,11 @@ func validate(ctx context.Context, resource resourcesemantics.GenericCRD, req *a
err = errorResult
}
if warningResult := result.Filter(apis.WarningLevel); warningResult != nil {
warn = warningResult
ws := warningResult.WrappedErrors()
warn = make([]error, 0, len(ws))
for _, w := range ws {
warn = append(warn, w)
}
}
}
return err, warn
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ knative.dev/hack/schema/commands
knative.dev/hack/schema/docs
knative.dev/hack/schema/registry
knative.dev/hack/schema/schema
# knative.dev/pkg v0.0.0-20221025200856-6ce976ce9255
# knative.dev/pkg v0.0.0-20221027173407-198b4637065d
## explicit; go 1.18
knative.dev/pkg/apis
knative.dev/pkg/apis/duck
Expand Down

0 comments on commit 79fed83

Please # to comment.