Skip to content

Commit 9d94455

Browse files
upgrade to latest dependencies (#404)
bumping knative.dev/pkg dd0db4b...953af01: > 953af01 [release-0.24] allow unknown metadata fields (# 2255) > 03e7ca5 Drop redundant pointers and decoders (# 2260) bumping knative.dev/eventing a574b7b...a8533da: > a8533da 🔥 Fix broken job name for 0.24 release (# 5665) > b4cabbf [release-0.24] [PingSource] disable @every (# 5590) Signed-off-by: Knative Automation <[email protected]>
1 parent 6db1380 commit 9d94455

File tree

9 files changed

+174
-38
lines changed

9 files changed

+174
-38
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ require (
3131
k8s.io/client-go v0.20.7
3232
k8s.io/code-generator v0.21.0
3333
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7
34-
knative.dev/eventing v0.24.0
34+
knative.dev/eventing v0.24.2
3535
knative.dev/hack v0.0.0-20210622141627-e28525d8d260
36-
knative.dev/pkg v0.0.0-20210622173328-dd0db4b05c80
36+
knative.dev/pkg v0.0.0-20210902173607-953af0138c75
3737
knative.dev/reconciler-test v0.0.0-20210623134345-88c84739abd9
3838
)
3939

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,13 +1475,14 @@ k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
14751475
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
14761476
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 h1:0T5IaWHO3sJTEmCP6mUlBvMukxPKUQWqiI/YuiBNMiQ=
14771477
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
1478-
knative.dev/eventing v0.24.0 h1:CoaQwZBizxZyOFJUvFcyb7vYSvpYBmfb4IYRNWUdTPE=
1479-
knative.dev/eventing v0.24.0/go.mod h1:9xo0SWkIfpXrx0lvGQO7MUlPF8cu+QCMd2gGxj6wxrU=
1478+
knative.dev/eventing v0.24.2 h1:yW3pOUKm/PixfH/lGsDVX9UdHahR2uzMoewV4PkRbK8=
1479+
knative.dev/eventing v0.24.2/go.mod h1:9xo0SWkIfpXrx0lvGQO7MUlPF8cu+QCMd2gGxj6wxrU=
14801480
knative.dev/hack v0.0.0-20210622141627-e28525d8d260 h1:f2eMtOubAOc/Q7JlvFPDKXiPlJVK+VpX2Cot8hRzCgQ=
14811481
knative.dev/hack v0.0.0-20210622141627-e28525d8d260/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
14821482
knative.dev/hack/schema v0.0.0-20210622141627-e28525d8d260/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
1483-
knative.dev/pkg v0.0.0-20210622173328-dd0db4b05c80 h1:GHJ3lglE0/YHfBMMJqluqUNLOmsNXh7s7DBnfrkpRMM=
14841483
knative.dev/pkg v0.0.0-20210622173328-dd0db4b05c80/go.mod h1:kGegTnbZ+ljFjAE3E1+8wgaH2LMv8qYi+72o3F3cbdc=
1484+
knative.dev/pkg v0.0.0-20210902173607-953af0138c75 h1:U9Im5Wp0oKV2ZWP+V9RZSDgRqv4IhfnzObMrgzWdDRQ=
1485+
knative.dev/pkg v0.0.0-20210902173607-953af0138c75/go.mod h1:kGegTnbZ+ljFjAE3E1+8wgaH2LMv8qYi+72o3F3cbdc=
14851486
knative.dev/reconciler-test v0.0.0-20210623134345-88c84739abd9 h1:j+ZLX0o1vBxEpTc7J6QT6sSBblQHpZhJP4vxbFe+C5Y=
14861487
knative.dev/reconciler-test v0.0.0-20210623134345-88c84739abd9/go.mod h1:4wqv2WyWUC5yhTesRUVwgjv/fHTHny1RYBfdB6tVDok=
14871488
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=

vendor/knative.dev/eventing/pkg/apis/sources/v1/ping_validation.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/base64"
2222
"encoding/json"
23+
"errors"
2324
"fmt"
2425
"strings"
2526

@@ -37,8 +38,10 @@ func (c *PingSource) Validate(ctx context.Context) *apis.FieldError {
3738

3839
func (cs *PingSourceSpec) Validate(ctx context.Context) *apis.FieldError {
3940
var errs *apis.FieldError
40-
4141
schedule := cs.Schedule
42+
43+
errs = validateDescriptor(schedule)
44+
4245
if cs.Timezone != "" {
4346
schedule = "CRON_TZ=" + cs.Timezone + " " + schedule
4447
}
@@ -98,3 +101,10 @@ func validateJSON(str string) error {
98101
var objmap map[string]interface{}
99102
return json.Unmarshal([]byte(str), &objmap)
100103
}
104+
105+
func validateDescriptor(spec string) *apis.FieldError {
106+
if strings.Contains(spec, "@every") {
107+
return apis.ErrInvalidValue(errors.New("unsupported descriptor @every"), "schedule")
108+
}
109+
return nil
110+
}

vendor/knative.dev/eventing/pkg/apis/sources/v1beta2/ping_validation.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/base64"
2222
"encoding/json"
23+
"errors"
2324
"fmt"
2425
"strings"
2526

@@ -37,8 +38,10 @@ func (c *PingSource) Validate(ctx context.Context) *apis.FieldError {
3738

3839
func (cs *PingSourceSpec) Validate(ctx context.Context) *apis.FieldError {
3940
var errs *apis.FieldError
40-
4141
schedule := cs.Schedule
42+
43+
errs = validateDescriptor(schedule)
44+
4245
if cs.Timezone != "" {
4346
schedule = "CRON_TZ=" + cs.Timezone + " " + schedule
4447
}
@@ -98,3 +101,10 @@ func validateJSON(str string) error {
98101
var objmap map[string]interface{}
99102
return json.Unmarshal([]byte(str), &objmap)
100103
}
104+
105+
func validateDescriptor(spec string) *apis.FieldError {
106+
if strings.Contains(spec, "@every") {
107+
return apis.ErrInvalidValue(errors.New("unsupported descriptor @every"), "schedule")
108+
}
109+
return nil
110+
}

vendor/knative.dev/pkg/webhook/configmaps/configmaps.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package configmaps
1818

1919
import (
20-
"bytes"
2120
"context"
2221
"encoding/json"
2322
"errors"
@@ -192,8 +191,7 @@ func (ac *reconciler) validate(ctx context.Context, req *admissionv1.AdmissionRe
192191

193192
var newObj corev1.ConfigMap
194193
if len(newBytes) != 0 {
195-
newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes))
196-
if err := newDecoder.Decode(&newObj); err != nil {
194+
if err := json.Unmarshal(newBytes, &newObj); err != nil {
197195
return fmt.Errorf("cannot decode incoming new object: %w", err)
198196
}
199197
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
Copyright 2021 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package json
18+
19+
import (
20+
"bytes"
21+
"encoding/json"
22+
"io"
23+
)
24+
25+
var (
26+
emptyMeta = []byte(`:{}`)
27+
metaPrefix = []byte(`{"metadata"`)
28+
metaSuffix = []byte(`}`)
29+
)
30+
31+
var (
32+
// Unmarshal is an alias for json.Unmarshal
33+
Unmarshal = json.Unmarshal
34+
35+
//Marshal is an alias for json.Marshal
36+
Marshal = json.Marshal
37+
)
38+
39+
// Decode will parse the json byte array to the target object. When
40+
// unknown fields are _not_ allowed we still accept unknown
41+
// fields in the Object's metadata
42+
//
43+
// See https://github.com/knative/serving/issues/11448 for details
44+
func Decode(bites []byte, target interface{}, disallowUnknownFields bool) error {
45+
if !disallowUnknownFields {
46+
return json.Unmarshal(bites, target)
47+
}
48+
49+
// If we don't allow unknown fields we skip validating fields in the metadata
50+
// block since that is opaque to us and validated by the API server
51+
start, end, err := findMetadataOffsets(bites)
52+
if err != nil {
53+
return err
54+
} else if start == -1 || end == -1 {
55+
// If for some reason the json does not have metadata continue with normal parsing
56+
dec := json.NewDecoder(bytes.NewReader(bites))
57+
dec.DisallowUnknownFields()
58+
return dec.Decode(target)
59+
}
60+
61+
before := bites[:start]
62+
metadata := bites[start:end]
63+
after := bites[end:]
64+
65+
// Parse everything but skip metadata
66+
dec := json.NewDecoder(io.MultiReader(
67+
bytes.NewReader(before),
68+
bytes.NewReader(emptyMeta),
69+
bytes.NewReader(after),
70+
))
71+
72+
dec.DisallowUnknownFields()
73+
if err := dec.Decode(target); err != nil {
74+
return err
75+
}
76+
77+
// Now we parse just the metadata
78+
dec = json.NewDecoder(io.MultiReader(
79+
bytes.NewReader(metaPrefix),
80+
bytes.NewReader(metadata),
81+
bytes.NewReader(metaSuffix),
82+
))
83+
84+
if err := dec.Decode(target); err != nil {
85+
return err
86+
}
87+
88+
return nil
89+
}
90+
91+
func findMetadataOffsets(bites []byte) (start, end int64, err error) {
92+
start, end = -1, -1
93+
level := 0
94+
95+
var (
96+
dec = json.NewDecoder(bytes.NewReader(bites))
97+
t json.Token
98+
)
99+
100+
for {
101+
t, err = dec.Token()
102+
if err == io.EOF { //nolint
103+
break
104+
}
105+
if err != nil {
106+
return
107+
}
108+
109+
switch v := t.(type) {
110+
case json.Delim:
111+
if v == '{' {
112+
level++
113+
} else if v == '}' {
114+
level--
115+
}
116+
case string:
117+
if v == "metadata" && level == 1 {
118+
start = dec.InputOffset()
119+
x := struct{}{}
120+
if err = dec.Decode(&x); err != nil {
121+
return -1, -1, err
122+
}
123+
end = dec.InputOffset()
124+
125+
// we exit early to stop processing the rest of the object
126+
return
127+
}
128+
}
129+
}
130+
return -1, -1, nil
131+
}

vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ limitations under the License.
1717
package defaulting
1818

1919
import (
20-
"bytes"
2120
"context"
22-
"encoding/json"
2321
"errors"
2422
"fmt"
2523
"sort"
@@ -47,6 +45,7 @@ import (
4745
"knative.dev/pkg/system"
4846
"knative.dev/pkg/webhook"
4947
certresources "knative.dev/pkg/webhook/certificates/resources"
48+
"knative.dev/pkg/webhook/json"
5049
"knative.dev/pkg/webhook/resourcesemantics"
5150
)
5251

@@ -241,21 +240,15 @@ func (ac *reconciler) mutate(ctx context.Context, req *admissionv1.AdmissionRequ
241240

242241
if len(newBytes) != 0 {
243242
newObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD)
244-
newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes))
245-
if ac.disallowUnknownFields {
246-
newDecoder.DisallowUnknownFields()
247-
}
248-
if err := newDecoder.Decode(&newObj); err != nil {
243+
err := json.Decode(newBytes, newObj, ac.disallowUnknownFields)
244+
if err != nil {
249245
return nil, fmt.Errorf("cannot decode incoming new object: %w", err)
250246
}
251247
}
252248
if len(oldBytes) != 0 {
253249
oldObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD)
254-
oldDecoder := json.NewDecoder(bytes.NewBuffer(oldBytes))
255-
if ac.disallowUnknownFields {
256-
oldDecoder.DisallowUnknownFields()
257-
}
258-
if err := oldDecoder.Decode(&oldObj); err != nil {
250+
err := json.Decode(oldBytes, oldObj, ac.disallowUnknownFields)
251+
if err != nil {
259252
return nil, fmt.Errorf("cannot decode incoming old object: %w", err)
260253
}
261254
}

vendor/knative.dev/pkg/webhook/resourcesemantics/validation/validation_admit.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ limitations under the License.
1717
package validation
1818

1919
import (
20-
"bytes"
2120
"context"
22-
"encoding/json"
2321
"errors"
2422
"fmt"
2523

@@ -31,6 +29,7 @@ import (
3129
kubeclient "knative.dev/pkg/client/injection/kube/client"
3230
"knative.dev/pkg/logging"
3331
"knative.dev/pkg/webhook"
32+
"knative.dev/pkg/webhook/json"
3433
"knative.dev/pkg/webhook/resourcesemantics"
3534
)
3635

@@ -110,23 +109,17 @@ func (ac *reconciler) decodeRequestAndPrepareContext(
110109
var newObj resourcesemantics.GenericCRD
111110
if len(newBytes) != 0 {
112111
newObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD)
113-
newDecoder := json.NewDecoder(bytes.NewBuffer(newBytes))
114-
if ac.disallowUnknownFields {
115-
newDecoder.DisallowUnknownFields()
116-
}
117-
if err := newDecoder.Decode(&newObj); err != nil {
112+
err := json.Decode(newBytes, newObj, ac.disallowUnknownFields)
113+
if err != nil {
118114
return ctx, nil, fmt.Errorf("cannot decode incoming new object: %w", err)
119115
}
120116
}
121117

122118
var oldObj resourcesemantics.GenericCRD
123119
if len(oldBytes) != 0 {
124120
oldObj = handler.DeepCopyObject().(resourcesemantics.GenericCRD)
125-
oldDecoder := json.NewDecoder(bytes.NewBuffer(oldBytes))
126-
if ac.disallowUnknownFields {
127-
oldDecoder.DisallowUnknownFields()
128-
}
129-
if err := oldDecoder.Decode(&oldObj); err != nil {
121+
err := json.Decode(oldBytes, oldObj, ac.disallowUnknownFields)
122+
if err != nil {
130123
return ctx, nil, fmt.Errorf("cannot decode incoming old object: %w", err)
131124
}
132125
}
@@ -201,8 +194,7 @@ func (ac *reconciler) callback(ctx context.Context, req *admissionv1.AdmissionRe
201194
if c, ok := ac.callbacks[gvk]; ok {
202195
if _, supported := c.supportedVerbs[req.Operation]; supported {
203196
unstruct := &unstructured.Unstructured{}
204-
newDecoder := json.NewDecoder(bytes.NewBuffer(toDecode))
205-
if err := newDecoder.Decode(&unstruct); err != nil {
197+
if err := json.Unmarshal(toDecode, unstruct); err != nil {
206198
return fmt.Errorf("cannot decode incoming new object: %w", err)
207199
}
208200

vendor/modules.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ k8s.io/utils/buffer
10211021
k8s.io/utils/integer
10221022
k8s.io/utils/pointer
10231023
k8s.io/utils/trace
1024-
# knative.dev/eventing v0.24.0
1024+
# knative.dev/eventing v0.24.2
10251025
## explicit
10261026
knative.dev/eventing/pkg/adapter/v2
10271027
knative.dev/eventing/pkg/adapter/v2/util/crstatusevent
@@ -1117,7 +1117,7 @@ knative.dev/eventing/test/test_images/print
11171117
# knative.dev/hack v0.0.0-20210622141627-e28525d8d260
11181118
## explicit
11191119
knative.dev/hack
1120-
# knative.dev/pkg v0.0.0-20210622173328-dd0db4b05c80
1120+
# knative.dev/pkg v0.0.0-20210902173607-953af0138c75
11211121
## explicit
11221122
knative.dev/pkg/apis
11231123
knative.dev/pkg/apis/duck
@@ -1215,6 +1215,7 @@ knative.dev/pkg/webhook
12151215
knative.dev/pkg/webhook/certificates
12161216
knative.dev/pkg/webhook/certificates/resources
12171217
knative.dev/pkg/webhook/configmaps
1218+
knative.dev/pkg/webhook/json
12181219
knative.dev/pkg/webhook/resourcesemantics
12191220
knative.dev/pkg/webhook/resourcesemantics/defaulting
12201221
knative.dev/pkg/webhook/resourcesemantics/validation

0 commit comments

Comments
 (0)