From 911ea8102c831fa82d12ba5b243e648f71780e73 Mon Sep 17 00:00:00 2001 From: Knative Automation Date: Fri, 13 Jun 2025 11:52:48 -0400 Subject: [PATCH] upgrade to latest dependencies (#942) bumping knative.dev/pkg 4e27b2e...05e18ff: > 05e18ff pull configmap parsing into separate package (# 3185) Signed-off-by: Knative Automation --- go.mod | 2 +- go.sum | 4 +- vendor/knative.dev/pkg/configmap/parse.go | 131 ++---------------- .../knative.dev/pkg/configmap/parser/parse.go | 109 +++++++++++++++ vendor/modules.txt | 3 +- 5 files changed, 129 insertions(+), 120 deletions(-) create mode 100644 vendor/knative.dev/pkg/configmap/parser/parse.go diff --git a/go.mod b/go.mod index 1d96c32f..129d690f 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( k8s.io/code-generator v0.33.1 k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff knative.dev/hack v0.0.0-20250514121446-f525e187efdc - knative.dev/pkg v0.0.0-20250610210745-4e27b2e68090 + knative.dev/pkg v0.0.0-20250612083447-05e18ffb29c7 ) require ( diff --git a/go.sum b/go.sum index c887aabc..1117b1a6 100644 --- a/go.sum +++ b/go.sum @@ -676,8 +676,8 @@ k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJ k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= knative.dev/hack v0.0.0-20250514121446-f525e187efdc h1:8HmclJlA0zNE/G1SkgdC3/IFSSyhaSz2iIhihU6YbEo= knative.dev/hack v0.0.0-20250514121446-f525e187efdc/go.mod h1:R0ritgYtjLDO9527h5vb5X6gfvt5LCrJ55BNbVDsWiY= -knative.dev/pkg v0.0.0-20250610210745-4e27b2e68090 h1:lrYxxGsWJJjphcg7ZS4gYmC52qjoYbU/+MasnoaVn0g= -knative.dev/pkg v0.0.0-20250610210745-4e27b2e68090/go.mod h1:nrao281iv0FJ5u/c0j3zmrinAlyOUZo9hJUxbrbsxWo= +knative.dev/pkg v0.0.0-20250612083447-05e18ffb29c7 h1:034E/3HHcG7y533bMXa+d9vD5yjEow2thggnnsGlbTM= +knative.dev/pkg v0.0.0-20250612083447-05e18ffb29c7/go.mod h1:nrao281iv0FJ5u/c0j3zmrinAlyOUZo9hJUxbrbsxWo= 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= diff --git a/vendor/knative.dev/pkg/configmap/parse.go b/vendor/knative.dev/pkg/configmap/parse.go index d8caba3c..bea5b5ea 100644 --- a/vendor/knative.dev/pkg/configmap/parse.go +++ b/vendor/knative.dev/pkg/configmap/parse.go @@ -18,7 +18,6 @@ package configmap import ( "fmt" - "strconv" "strings" "time" @@ -26,144 +25,44 @@ import ( "k8s.io/apimachinery/pkg/api/validation" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" + "knative.dev/pkg/configmap/parser" ) // ParseFunc is a function taking ConfigMap data and applying a parse operation to it. -type ParseFunc func(map[string]string) error +type ParseFunc = parser.ParseFunc // AsString passes the value at key through into the target, if it exists. -func AsString(key string, target *string) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - *target = raw - } - return nil - } -} +var AsString = parser.As[string] // AsBool parses the value at key as a boolean into the target, if it exists. -func AsBool(key string, target *bool) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.ParseBool(raw) - *target = val // If err != nil — this is always false. - return err - } - return nil - } -} +var AsBool = parser.As[bool] // AsInt16 parses the value at key as an int16 into the target, if it exists. -func AsInt16(key string, target *int16) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.ParseInt(raw, 10, 16) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = int16(val) - } - return nil - } -} +var AsInt16 = parser.As[int16] // AsInt32 parses the value at key as an int32 into the target, if it exists. -func AsInt32(key string, target *int32) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.ParseInt(raw, 10, 32) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = int32(val) - } - return nil - } -} +var AsInt32 = parser.As[int32] // AsInt64 parses the value at key as an int64 into the target, if it exists. -func AsInt64(key string, target *int64) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.ParseInt(raw, 10, 64) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = val - } - return nil - } -} +var AsInt64 = parser.As[int64] // AsInt parses the value at key as an int into the target, if it exists. -func AsInt(key string, target *int) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.Atoi(raw) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = val - } - return nil - } -} +var AsInt = parser.As[int] // AsUint16 parses the value at key as an uint16 into the target, if it exists. -func AsUint16(key string, target *uint16) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.ParseUint(raw, 10, 16) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = uint16(val) - } - return nil - } -} +var AsUint16 = parser.As[uint16] // AsUint32 parses the value at key as an uint32 into the target, if it exists. -func AsUint32(key string, target *uint32) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.ParseUint(raw, 10, 32) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = uint32(val) - } - return nil - } -} +var AsUint32 = parser.As[uint32] + +// AsUint64 parses the value at key as an uint32 into the target, if it exists. +var AsUint64 = parser.As[uint32] // AsFloat64 parses the value at key as a float64 into the target, if it exists. -func AsFloat64(key string, target *float64) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := strconv.ParseFloat(raw, 64) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = val - } - return nil - } -} +var AsFloat64 = parser.As[float64] // AsDuration parses the value at key as a time.Duration into the target, if it exists. -func AsDuration(key string, target *time.Duration) ParseFunc { - return func(data map[string]string) error { - if raw, ok := data[key]; ok { - val, err := time.ParseDuration(raw) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", key, err) - } - *target = val - } - return nil - } -} +var AsDuration = parser.As[time.Duration] // AsStringSet parses the value at key as a sets.Set[string] (split by ',') into the target, if it exists. func AsStringSet(key string, target *sets.Set[string]) ParseFunc { diff --git a/vendor/knative.dev/pkg/configmap/parser/parse.go b/vendor/knative.dev/pkg/configmap/parser/parse.go new file mode 100644 index 00000000..a468727a --- /dev/null +++ b/vendor/knative.dev/pkg/configmap/parser/parse.go @@ -0,0 +1,109 @@ +/* +Copyright 2025 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 parser + +import ( + "fmt" + "strconv" + "time" +) + +// ParseFunc is a function taking ConfigMap data and applying a parse operation to it. +type ParseFunc func(map[string]string) error + +func Parse(data map[string]string, parsers ...ParseFunc) error { + for _, parse := range parsers { + if err := parse(data); err != nil { + return err + } + } + return nil +} + +func AsFunc[T any]( + key string, + target *T, + parseVal func(s string) (T, error), +) ParseFunc { + return func(data map[string]string) error { + if raw, ok := data[key]; ok { + val, err := parseVal(raw) + if err != nil { + return fmt.Errorf("failed to parse %q: %w", key, err) + } + *target = val + } + return nil + } +} + +func As[T parseable](key string, target *T) ParseFunc { + return AsFunc(key, target, parse) +} + +type parseable interface { + int | int16 | int32 | int64 | + uint | uint16 | uint32 | uint64 | + string | bool | float64 | float32 | + time.Duration +} + +//nolint:gosec // ignore integer overflow +func parse[T parseable](s string) (T, error) { + var zero T + + var val any + var err error + + switch any(zero).(type) { + case string: + val = s + case int16: + val, err = strconv.ParseInt(s, 10, 16) + val = int16(val.(int64)) + case int32: + val, err = strconv.ParseInt(s, 10, 32) + val = int32(val.(int64)) + case int64: + val, err = strconv.ParseInt(s, 10, 64) + case uint16: + val, err = strconv.ParseUint(s, 10, 16) + val = uint16(val.(uint64)) + case uint32: + val, err = strconv.ParseUint(s, 10, 32) + val = uint32(val.(uint64)) + case uint64: + val, err = strconv.ParseUint(s, 10, 64) + case float64: + val, err = strconv.ParseFloat(s, 64) + case float32: + val, err = strconv.ParseFloat(s, 64) + val = float32(val.(float64)) + case bool: + val, err = strconv.ParseBool(s) + case time.Duration: + val, err = time.ParseDuration(s) + case int: + val, err = strconv.ParseInt(s, 10, 0) + val = int(val.(int64)) + case uint: + val, err = strconv.ParseUint(s, 10, 0) + val = uint(val.(uint64)) + } + + return val.(T), err +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 4deb3491..b60cf196 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -852,7 +852,7 @@ k8s.io/utils/trace # knative.dev/hack v0.0.0-20250514121446-f525e187efdc ## explicit; go 1.21 knative.dev/hack -# knative.dev/pkg v0.0.0-20250610210745-4e27b2e68090 +# knative.dev/pkg v0.0.0-20250612083447-05e18ffb29c7 ## explicit; go 1.24.0 knative.dev/pkg/apis knative.dev/pkg/apis/duck @@ -872,6 +872,7 @@ knative.dev/pkg/codegen/cmd/injection-gen/generators/reconciler knative.dev/pkg/codegen/cmd/injection-gen/namer knative.dev/pkg/codegen/cmd/injection-gen/tags knative.dev/pkg/configmap +knative.dev/pkg/configmap/parser knative.dev/pkg/controller knative.dev/pkg/environment knative.dev/pkg/hack