Skip to content

Commit

Permalink
upgrade to latest dependencies (#284)
Browse files Browse the repository at this point in the history
bumping knative.dev/eventing 200e54c...4e6cde3:
  > 4e6cde3 [release-0.23] [PingSource] disable @every (# 5591)
  > a5a8f89 Fix subtest client scope (# 5532)
  > ecc1c20 Update Knative dependency for release-0.23 (# 5470)
  > aa5d54e Fix cloudevent adapter panic (# 5425)
  > e3ad363 Add podAntiAffinity labels to remaining HA control plane pods (# 5413)
bumping knative.dev/hack 93ad912...509255f:
  > 509255f Do not print debug info when running release.sh (# 71)
bumping knative.dev/pkg 4564797...8d4b5e0:
  > 8d4b5e0 [release-0.23] allow unknown metadata fields (# 2256)
  > a0d1c92 Drop redundant pointers and decoders (# 2261)

Signed-off-by: Knative Automation <automation@knative.team>
  • Loading branch information
knative-automation authored Sep 4, 2021
1 parent 0ea3f14 commit fb1f8be
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 49 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ require (
k8s.io/client-go v0.19.7
k8s.io/code-generator v0.19.7
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6
knative.dev/eventing v0.23.0
knative.dev/hack v0.0.0-20210428122153-93ad9129c268
knative.dev/pkg v0.0.0-20210510175900-4564797bf3b7
knative.dev/eventing v0.23.4
knative.dev/hack v0.0.0-20210602212444-509255f29a24
knative.dev/pkg v0.0.0-20210902175106-8d4b5e065ebb
)

replace (
Expand Down
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1173,13 +1173,15 @@ k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6 h1:+WnxoVtG8TMiudHBSEtrVL
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H64/qeyjQoUZhGpeFDVdxjTeEVN2o=
k8s.io/utils v0.0.0-20200729134348-d5654de09c73 h1:uJmqzgNWG7XyClnU/mLPBWwfKKF1K8Hf8whTseBgJcg=
k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
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/pkg v0.0.0-20210510175900-4564797bf3b7 h1:i4P8emOPrLctmbaPHp5eRIOqz+XTOkit7KgZeS+onKs=
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/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=
pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
3 changes: 2 additions & 1 deletion vendor/knative.dev/eventing/pkg/adapter/v2/cloudevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"strings"

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"strings"

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
3 changes: 0 additions & 3 deletions vendor/knative.dev/hack/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions vendor/knative.dev/pkg/webhook/configmaps/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package configmaps

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -188,8 +187,7 @@ func (ac *reconciler) validate(ctx context.Context, req *admissionv1.AdmissionRe

var newObj corev1.ConfigMap
if len(newBytes) != 0 {
newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes))
if err := newDecoder.Decode(&newObj); err != nil {
if err := json.Unmarshal(newBytes, &newObj); err != nil {
return fmt.Errorf("cannot decode incoming new object: %w", err)
}
}
Expand Down
131 changes: 131 additions & 0 deletions vendor/knative.dev/pkg/webhook/json/decode.go
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 1 addition & 3 deletions vendor/knative.dev/pkg/webhook/psbinding/psbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package psbinding

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ limitations under the License.
package defaulting

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"sort"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ limitations under the License.
package validation

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"

Expand All @@ -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"
)

Expand Down Expand Up @@ -110,23 +109,17 @@ 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)
}
}

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)
}
}
Expand Down Expand Up @@ -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)
}

Expand Down
Loading

0 comments on commit fb1f8be

Please sign in to comment.