Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/kind-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- v1.19.11
- v1.20.7
- v1.21.1
- v1.22.0

test-suite:
- ./test/conformance/runtime
Expand All @@ -47,6 +48,11 @@ jobs:
kind-image-sha: sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
kingress: kourier
cluster-suffix: c${{ github.run_id }}.local
- k8s-version: v1.22.0
kind-version: v0.11.1
kind-image-sha: sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047
kingress: kourier
cluster-suffix: c${{ github.run_id }}.local

# The tests in api/v1alpha1 require the --enable-alpha flag to be set,
# and alpha components to be deployed.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ require (
knative.dev/pkg v0.0.0-20210830224055-82f3a9f1c5bc
sigs.k8s.io/yaml v1.2.0
)

replace knative.dev/pkg => github.com/dprotaso/pkg v0.0.0-20210901150029-18a3eca54c9e
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dprotaso/pkg v0.0.0-20210901150029-18a3eca54c9e h1:VLosTbS2fe5OmdGxQDSmRpGow2UP2LZYMAbLloAn27Y=
github.com/dprotaso/pkg v0.0.0-20210901150029-18a3eca54c9e/go.mod h1:jMSqkNMsrzuy+XR4Yr/BMy7SDVbUOl3KKB6+5MR+ZU8=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
Expand Down Expand Up @@ -1532,9 +1534,6 @@ knative.dev/hack v0.0.0-20210806075220-815cd312d65c h1:nOXoDWAAItwr4o0dp3nHr6skg
knative.dev/hack v0.0.0-20210806075220-815cd312d65c/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/networking v0.0.0-20210830024827-a31c669a4bfb h1:deLkPZl+gyC1Zdvq2642JnF/XEtJJmnK2t723mds8EU=
knative.dev/networking v0.0.0-20210830024827-a31c669a4bfb/go.mod h1:Fs/qlyN6KutqokVyRHhKqMLPpYX/KvrrSxtGb4Ew+xc=
knative.dev/pkg v0.0.0-20210827184538-2bd91f75571c/go.mod h1:jMSqkNMsrzuy+XR4Yr/BMy7SDVbUOl3KKB6+5MR+ZU8=
knative.dev/pkg v0.0.0-20210830224055-82f3a9f1c5bc h1:cvJR8kJM4dj2YiLpxNLOkr+QXWAFku2X9kO1r9pXWPw=
knative.dev/pkg v0.0.0-20210830224055-82f3a9f1c5bc/go.mod h1:jMSqkNMsrzuy+XR4Yr/BMy7SDVbUOl3KKB6+5MR+ZU8=
pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
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
27 changes: 27 additions & 0 deletions third_party/VENDOR-LICENSE/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 changes: 27 additions & 0 deletions third_party/VENDOR-LICENSE/vendor/golang.org/x/crypto/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions third_party/VENDOR-LICENSE/vendor/golang.org/x/net/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions third_party/VENDOR-LICENSE/vendor/golang.org/x/sys/cpu/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions third_party/VENDOR-LICENSE/vendor/golang.org/x/text/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 {
break
}
if err != nil {
return
}

switch v := t.(type) {
case json.Delim:
if v == '{' {
level += 1
} else if v == '}' {
level -= 1
}
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
}
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 Down Expand Up @@ -47,6 +45,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 @@ -241,21 +240,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
Loading