diff --git a/go.mod b/go.mod index fc5b9a238..7987c9f45 100644 --- a/go.mod +++ b/go.mod @@ -14,10 +14,10 @@ require ( k8s.io/api v0.19.7 k8s.io/apimachinery v0.19.7 k8s.io/client-go v0.19.7 - knative.dev/eventing v0.23.0 - knative.dev/hack v0.0.0-20210428122153-93ad9129c268 - knative.dev/pkg v0.0.0-20210510175900-4564797bf3b7 - knative.dev/serving v0.23.0 + knative.dev/eventing v0.23.4 + knative.dev/hack v0.0.0-20210602212444-509255f29a24 + knative.dev/pkg v0.0.0-20210902175106-8d4b5e065ebb + knative.dev/serving v0.23.1 ) replace github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.2 diff --git a/go.sum b/go.sum index cc59b8317..e83a5fdf7 100644 --- a/go.sum +++ b/go.sum @@ -1239,18 +1239,20 @@ k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 h1:0T5IaWHO3sJTEmCP6mUlBvMukxPKUQWqiI/YuiBNMiQ= k8s.io/utils v0.0.0-20210111153108-fddb29f9d009/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= knative.dev/caching v0.0.0-20210512050647-922782660f7c/go.mod h1:d+fIY/LkAZAM6HsRJwmfirNDMCc1+hqGlQctLP1CmzE= -knative.dev/eventing v0.23.0 h1:0L1bVpll8kjdZNZ0FgNi4T0pPo4MmmDb6UJ06I9yHoM= -knative.dev/eventing v0.23.0/go.mod h1:vGob3H6BTseZP+/dA5ze89gM+iNHlB2Cez8FFI7A9KM= -knative.dev/hack v0.0.0-20210428122153-93ad9129c268 h1:lBIj9Epd9UQ55NEaHzAdY/UZbuaegCdGPKVC2+Z68Q0= +knative.dev/eventing v0.23.4 h1:/6JABYCHcAnDU8ysggnupvspOP0LSXRTo/QqqJCPT5I= +knative.dev/eventing v0.23.4/go.mod h1:RIUlBsCp/DoISbw7ryUsdWvFkFO8DYtpB4dlXL/o1u4= knative.dev/hack v0.0.0-20210428122153-93ad9129c268/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI= -knative.dev/hack/schema v0.0.0-20210428122153-93ad9129c268/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0= +knative.dev/hack v0.0.0-20210602212444-509255f29a24 h1:eFcqwqJueFb2yY7tJVhLnDmdZCfaewfj4+MxR1CAWGo= +knative.dev/hack v0.0.0-20210602212444-509255f29a24/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI= +knative.dev/hack/schema v0.0.0-20210602212444-509255f29a24/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0= knative.dev/networking v0.0.0-20210512050647-ace2d3306f0b h1:Ea6ym1Jfd/Hci1EGj+uPaE3d6SS1s/Br+6fFAWdJCeM= knative.dev/networking v0.0.0-20210512050647-ace2d3306f0b/go.mod h1:y7RmP2/dHO/DAC1QmpUtgTVF6/Z8whaL+wjgey+HthU= -knative.dev/pkg v0.0.0-20210510175900-4564797bf3b7 h1:i4P8emOPrLctmbaPHp5eRIOqz+XTOkit7KgZeS+onKs= knative.dev/pkg v0.0.0-20210510175900-4564797bf3b7/go.mod h1:fIl4l4OmZodkElyaHoT0LCF5wT+3+P/kinawQ4XlLtE= +knative.dev/pkg v0.0.0-20210902175106-8d4b5e065ebb h1:mo9BNfVGr9Bm+F9BfLaVBHUjThljMJhBXHII5RjuEi0= +knative.dev/pkg v0.0.0-20210902175106-8d4b5e065ebb/go.mod h1:fIl4l4OmZodkElyaHoT0LCF5wT+3+P/kinawQ4XlLtE= knative.dev/reconciler-test v0.0.0-20210512062647-d5adf72546be/go.mod h1:ZHvzjwe5aUnWDx+u5y9EPaZ++5PM9Yapp/IvBDiS+Yk= -knative.dev/serving v0.23.0 h1:7q2MTUOud7kgLPJsVUyZIEG3g+df5yTwQjc+BsomsS8= -knative.dev/serving v0.23.0/go.mod h1:hoGG2F9/qfAL/x0x14hAdciD7YxjdsaDqZ0PRNmj1gs= +knative.dev/serving v0.23.1 h1:5fead16AKU0OjN//2FOhfUamuOHWfnl149BEmwjkPDI= +knative.dev/serving v0.23.1/go.mod h1:1j9Kv89CFB671mXbVRsbbyhlBh7d3BfksOtSy9j8jQ4= modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw= modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k= diff --git a/vendor/knative.dev/eventing/pkg/adapter/v2/cloudevents.go b/vendor/knative.dev/eventing/pkg/adapter/v2/cloudevents.go index e9febad24..e1c07471f 100644 --- a/vendor/knative.dev/eventing/pkg/adapter/v2/cloudevents.go +++ b/vendor/knative.dev/eventing/pkg/adapter/v2/cloudevents.go @@ -181,8 +181,9 @@ func (c *client) reportMetrics(ctx context.Context, event cloudevents.Event, res var res *http.Result if !cloudevents.ResultAs(retryResult, &res) { c.reportError(reportArgs, result) + } else { + c.reporter.ReportRetryEventCount(reportArgs, res.StatusCode) } - c.reporter.ReportRetryEventCount(reportArgs, res.StatusCode) } } } diff --git a/vendor/knative.dev/eventing/pkg/adapter/v2/test/test_client.go b/vendor/knative.dev/eventing/pkg/adapter/v2/test/test_client.go index 3948862e0..e4e9b9f19 100644 --- a/vendor/knative.dev/eventing/pkg/adapter/v2/test/test_client.go +++ b/vendor/knative.dev/eventing/pkg/adapter/v2/test/test_client.go @@ -86,6 +86,10 @@ func (c *TestCloudEventsClient) Send(ctx context.Context, out event.Event) proto return errors.New("totally not an http result") } else if eventData.Type == "unit.sendFail" { return http.NewResult(400, "%w", protocol.ResultNACK) + } else if eventData.Type == "unit.nonHttpRetry" { + var attempts []protocol.Result + attempts = append(attempts, errors.New("totally not an http result")) + return http.NewRetriesResult(http.NewResult(200, "%w", protocol.ResultACK), 1, time.Now(), attempts) } return http.NewResult(200, "%w", protocol.ResultACK) } diff --git a/vendor/knative.dev/eventing/pkg/apis/sources/v1/ping_validation.go b/vendor/knative.dev/eventing/pkg/apis/sources/v1/ping_validation.go index d86489747..c60f49a4f 100644 --- a/vendor/knative.dev/eventing/pkg/apis/sources/v1/ping_validation.go +++ b/vendor/knative.dev/eventing/pkg/apis/sources/v1/ping_validation.go @@ -20,6 +20,7 @@ import ( "context" "encoding/base64" "encoding/json" + "errors" "fmt" "strings" @@ -37,8 +38,10 @@ func (c *PingSource) Validate(ctx context.Context) *apis.FieldError { func (cs *PingSourceSpec) Validate(ctx context.Context) *apis.FieldError { var errs *apis.FieldError - schedule := cs.Schedule + + errs = validateDescriptor(schedule) + if cs.Timezone != "" { schedule = "CRON_TZ=" + cs.Timezone + " " + schedule } @@ -98,3 +101,10 @@ func validateJSON(str string) error { var objmap map[string]interface{} return json.Unmarshal([]byte(str), &objmap) } + +func validateDescriptor(spec string) *apis.FieldError { + if strings.Contains(spec, "@every") { + return apis.ErrInvalidValue(errors.New("unsupported descriptor @every"), "schedule") + } + return nil +} diff --git a/vendor/knative.dev/eventing/pkg/apis/sources/v1beta2/ping_validation.go b/vendor/knative.dev/eventing/pkg/apis/sources/v1beta2/ping_validation.go index 5bbd2d7f0..c8fa47a60 100644 --- a/vendor/knative.dev/eventing/pkg/apis/sources/v1beta2/ping_validation.go +++ b/vendor/knative.dev/eventing/pkg/apis/sources/v1beta2/ping_validation.go @@ -20,6 +20,7 @@ import ( "context" "encoding/base64" "encoding/json" + "errors" "fmt" "strings" @@ -37,8 +38,10 @@ func (c *PingSource) Validate(ctx context.Context) *apis.FieldError { func (cs *PingSourceSpec) Validate(ctx context.Context) *apis.FieldError { var errs *apis.FieldError - schedule := cs.Schedule + + errs = validateDescriptor(schedule) + if cs.Timezone != "" { schedule = "CRON_TZ=" + cs.Timezone + " " + schedule } @@ -98,3 +101,10 @@ func validateJSON(str string) error { var objmap map[string]interface{} return json.Unmarshal([]byte(str), &objmap) } + +func validateDescriptor(spec string) *apis.FieldError { + if strings.Contains(spec, "@every") { + return apis.ErrInvalidValue(errors.New("unsupported descriptor @every"), "schedule") + } + return nil +} diff --git a/vendor/knative.dev/hack/release.sh b/vendor/knative.dev/hack/release.sh index ffa5afd44..025fcab14 100644 --- a/vendor/knative.dev/hack/release.sh +++ b/vendor/knative.dev/hack/release.sh @@ -17,9 +17,6 @@ # This is a helper script for Knative release scripts. # See README.md for instructions on how to use it. -# Print commands -set -x - source $(dirname "${BASH_SOURCE[0]}")/library.sh # Organization name in GitHub; defaults to Knative. diff --git a/vendor/knative.dev/pkg/webhook/json/decode.go b/vendor/knative.dev/pkg/webhook/json/decode.go new file mode 100644 index 000000000..9e206a10b --- /dev/null +++ b/vendor/knative.dev/pkg/webhook/json/decode.go @@ -0,0 +1,131 @@ +/* +Copyright 2021 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package json + +import ( + "bytes" + "encoding/json" + "io" +) + +var ( + emptyMeta = []byte(`:{}`) + metaPrefix = []byte(`{"metadata"`) + metaSuffix = []byte(`}`) +) + +var ( + // Unmarshal is an alias for json.Unmarshal + Unmarshal = json.Unmarshal + + //Marshal is an alias for json.Marshal + Marshal = json.Marshal +) + +// Decode will parse the json byte array to the target object. When +// unknown fields are _not_ allowed we still accept unknown +// fields in the Object's metadata +// +// See https://github.com/knative/serving/issues/11448 for details +func Decode(bites []byte, target interface{}, disallowUnknownFields bool) error { + if !disallowUnknownFields { + return json.Unmarshal(bites, target) + } + + // If we don't allow unknown fields we skip validating fields in the metadata + // block since that is opaque to us and validated by the API server + start, end, err := findMetadataOffsets(bites) + if err != nil { + return err + } else if start == -1 || end == -1 { + // If for some reason the json does not have metadata continue with normal parsing + dec := json.NewDecoder(bytes.NewReader(bites)) + dec.DisallowUnknownFields() + return dec.Decode(target) + } + + before := bites[:start] + metadata := bites[start:end] + after := bites[end:] + + // Parse everything but skip metadata + dec := json.NewDecoder(io.MultiReader( + bytes.NewReader(before), + bytes.NewReader(emptyMeta), + bytes.NewReader(after), + )) + + dec.DisallowUnknownFields() + if err := dec.Decode(target); err != nil { + return err + } + + // Now we parse just the metadata + dec = json.NewDecoder(io.MultiReader( + bytes.NewReader(metaPrefix), + bytes.NewReader(metadata), + bytes.NewReader(metaSuffix), + )) + + if err := dec.Decode(target); err != nil { + return err + } + + return nil +} + +func findMetadataOffsets(bites []byte) (start, end int64, err error) { + start, end = -1, -1 + level := 0 + + var ( + dec = json.NewDecoder(bytes.NewReader(bites)) + t json.Token + ) + + for { + t, err = dec.Token() + if err == io.EOF { //nolint + break + } + if err != nil { + return + } + + switch v := t.(type) { + case json.Delim: + if v == '{' { + level++ + } else if v == '}' { + level-- + } + case string: + if v == "metadata" && level == 1 { + start = dec.InputOffset() + x := struct{}{} + if err = dec.Decode(&x); err != nil { + return -1, -1, err + } + end = dec.InputOffset() + + // we exit early to stop processing the rest of the object + return + } + } + } + return -1, -1, nil +} diff --git a/vendor/knative.dev/pkg/webhook/psbinding/psbinding.go b/vendor/knative.dev/pkg/webhook/psbinding/psbinding.go index f1f7984f9..4832c9587 100644 --- a/vendor/knative.dev/pkg/webhook/psbinding/psbinding.go +++ b/vendor/knative.dev/pkg/webhook/psbinding/psbinding.go @@ -17,7 +17,6 @@ limitations under the License. package psbinding import ( - "bytes" "context" "encoding/json" "fmt" @@ -178,8 +177,7 @@ func (ac *Reconciler) Admit(ctx context.Context, request *admissionv1.AdmissionR } orig := &duckv1.WithPod{} - decoder := json.NewDecoder(bytes.NewBuffer(request.Object.Raw)) - if err := decoder.Decode(&orig); err != nil { + if err := json.Unmarshal(request.Object.Raw, orig); err != nil { return webhook.MakeErrorStatus("unable to decode object: %v", err) } diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go index d57cc41f1..0c8aa6874 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go @@ -17,9 +17,7 @@ limitations under the License. package defaulting import ( - "bytes" "context" - "encoding/json" "errors" "fmt" "sort" @@ -46,6 +44,7 @@ import ( "knative.dev/pkg/system" "knative.dev/pkg/webhook" certresources "knative.dev/pkg/webhook/certificates/resources" + "knative.dev/pkg/webhook/json" "knative.dev/pkg/webhook/resourcesemantics" ) @@ -237,21 +236,15 @@ func (ac *reconciler) mutate(ctx context.Context, req *admissionv1.AdmissionRequ if len(newBytes) != 0 { newObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD) - newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes)) - if ac.disallowUnknownFields { - newDecoder.DisallowUnknownFields() - } - if err := newDecoder.Decode(&newObj); err != nil { + err := json.Decode(newBytes, newObj, ac.disallowUnknownFields) + if err != nil { return nil, fmt.Errorf("cannot decode incoming new object: %w", err) } } if len(oldBytes) != 0 { oldObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD) - oldDecoder := json.NewDecoder(bytes.NewBuffer(oldBytes)) - if ac.disallowUnknownFields { - oldDecoder.DisallowUnknownFields() - } - if err := oldDecoder.Decode(&oldObj); err != nil { + err := json.Decode(oldBytes, oldObj, ac.disallowUnknownFields) + if err != nil { return nil, fmt.Errorf("cannot decode incoming old object: %w", err) } } diff --git a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go index f2d7ad9bf..0544d88a6 100644 --- a/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go +++ b/vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go @@ -17,9 +17,7 @@ limitations under the License. package validation import ( - "bytes" "context" - "encoding/json" "errors" "fmt" @@ -31,6 +29,7 @@ import ( kubeclient "knative.dev/pkg/client/injection/kube/client" "knative.dev/pkg/logging" "knative.dev/pkg/webhook" + "knative.dev/pkg/webhook/json" "knative.dev/pkg/webhook/resourcesemantics" ) @@ -110,11 +109,8 @@ func (ac *reconciler) decodeRequestAndPrepareContext( var newObj resourcesemantics.GenericCRD if len(newBytes) != 0 { newObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD) - newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes)) - if ac.disallowUnknownFields { - newDecoder.DisallowUnknownFields() - } - if err := newDecoder.Decode(&newObj); err != nil { + err := json.Decode(newBytes, newObj, ac.disallowUnknownFields) + if err != nil { return ctx, nil, fmt.Errorf("cannot decode incoming new object: %w", err) } } @@ -122,11 +118,8 @@ func (ac *reconciler) decodeRequestAndPrepareContext( var oldObj resourcesemantics.GenericCRD if len(oldBytes) != 0 { oldObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD) - oldDecoder := json.NewDecoder(bytes.NewBuffer(oldBytes)) - if ac.disallowUnknownFields { - oldDecoder.DisallowUnknownFields() - } - if err := oldDecoder.Decode(&oldObj); err != nil { + err := json.Decode(oldBytes, oldObj, ac.disallowUnknownFields) + if err != nil { return ctx, nil, fmt.Errorf("cannot decode incoming old object: %w", err) } } @@ -201,8 +194,7 @@ func (ac *reconciler) callback(ctx context.Context, req *admissionv1.AdmissionRe if c, ok := ac.callbacks[gvk]; ok { if _, supported := c.supportedVerbs[req.Operation]; supported { unstruct := &unstructured.Unstructured{} - newDecoder := json.NewDecoder(bytes.NewBuffer(toDecode)) - if err := newDecoder.Decode(&unstruct); err != nil { + if err := json.Unmarshal(toDecode, unstruct); err != nil { return fmt.Errorf("cannot decode incoming new object: %w", err) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 30003be8b..a155188c1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -917,7 +917,7 @@ k8s.io/utils/buffer k8s.io/utils/integer k8s.io/utils/pointer k8s.io/utils/trace -# knative.dev/eventing v0.23.0 +# knative.dev/eventing v0.23.4 ## explicit knative.dev/eventing/pkg/adapter/v2 knative.dev/eventing/pkg/adapter/v2/test @@ -982,14 +982,14 @@ knative.dev/eventing/test/test_images/heartbeats knative.dev/eventing/test/test_images/performance knative.dev/eventing/test/test_images/print knative.dev/eventing/test/test_images/recordevents -# knative.dev/hack v0.0.0-20210428122153-93ad9129c268 +# knative.dev/hack v0.0.0-20210602212444-509255f29a24 ## explicit knative.dev/hack # knative.dev/networking v0.0.0-20210512050647-ace2d3306f0b knative.dev/networking/pkg knative.dev/networking/pkg/apis/networking knative.dev/networking/pkg/apis/networking/v1alpha1 -# knative.dev/pkg v0.0.0-20210510175900-4564797bf3b7 +# knative.dev/pkg v0.0.0-20210902175106-8d4b5e065ebb ## explicit knative.dev/pkg/apis knative.dev/pkg/apis/duck @@ -1064,11 +1064,12 @@ knative.dev/pkg/version knative.dev/pkg/webhook knative.dev/pkg/webhook/certificates knative.dev/pkg/webhook/certificates/resources +knative.dev/pkg/webhook/json knative.dev/pkg/webhook/psbinding knative.dev/pkg/webhook/resourcesemantics knative.dev/pkg/webhook/resourcesemantics/defaulting knative.dev/pkg/webhook/resourcesemantics/validation -# knative.dev/serving v0.23.0 +# knative.dev/serving v0.23.1 ## explicit knative.dev/serving/pkg/apis/autoscaling knative.dev/serving/pkg/apis/autoscaling/v1alpha1