mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Update kube-openapi, drop mapstructure
This commit is contained in:
21
vendor/k8s.io/kube-openapi/pkg/cached/cache.go
generated
vendored
21
vendor/k8s.io/kube-openapi/pkg/cached/cache.go
generated
vendored
@@ -37,8 +37,11 @@ limitations under the License.
|
||||
// # Atomicity
|
||||
//
|
||||
// Most of the operations are not atomic/thread-safe, except for
|
||||
// [Replaceable.Replace] which can be performed while the objects
|
||||
// are being read.
|
||||
// [Replaceable.Replace] which can be performed while the objects are
|
||||
// being read. Specifically, `Get` methods are NOT thread-safe. Never
|
||||
// call `Get()` without a lock on a multi-threaded environment, since
|
||||
// it's usually performing updates to caches that will require write
|
||||
// operations.
|
||||
//
|
||||
// # Etags
|
||||
//
|
||||
@@ -97,6 +100,13 @@ func (r Result[T]) Get() Result[T] {
|
||||
type Data[T any] interface {
|
||||
// Returns the cached data, as well as an "etag" to identify the
|
||||
// version of the cache, or an error if something happened.
|
||||
//
|
||||
// # Important note
|
||||
//
|
||||
// This method is NEVER thread-safe, never assume it is OK to
|
||||
// call `Get()` without holding a proper mutex in a
|
||||
// multi-threaded environment, especially since `Get()` will
|
||||
// usually update the cache and perform write operations.
|
||||
Get() Result[T]
|
||||
}
|
||||
|
||||
@@ -249,6 +259,13 @@ type Replaceable[T any] struct {
|
||||
// previously had returned a success, that success will be returned
|
||||
// instead. If the cache fails but we never returned a success, that
|
||||
// failure is returned.
|
||||
//
|
||||
// # Important note
|
||||
//
|
||||
// As all implementations of Get, this implementation is NOT
|
||||
// thread-safe. Please properly lock a mutex before calling this method
|
||||
// if you are in a multi-threaded environment, since this method will
|
||||
// update the cache and perform write operations.
|
||||
func (c *Replaceable[T]) Get() Result[T] {
|
||||
result := (*c.cache.Load()).Get()
|
||||
if result.Err != nil && c.result != nil && c.result.Err == nil {
|
||||
|
||||
81
vendor/k8s.io/kube-openapi/pkg/validation/strfmt/format.go
generated
vendored
81
vendor/k8s.io/kube-openapi/pkg/validation/strfmt/format.go
generated
vendored
@@ -16,13 +16,10 @@ package strfmt
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"k8s.io/kube-openapi/pkg/validation/errors"
|
||||
)
|
||||
|
||||
@@ -50,7 +47,6 @@ type Registry interface {
|
||||
ContainsName(string) bool
|
||||
Validates(string, string) bool
|
||||
Parse(string, string) (interface{}, error)
|
||||
MapStructureHookFunc() mapstructure.DecodeHookFunc
|
||||
}
|
||||
|
||||
type knownFormat struct {
|
||||
@@ -92,83 +88,6 @@ func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
|
||||
}
|
||||
}
|
||||
|
||||
// MapStructureHookFunc is a decode hook function for mapstructure
|
||||
func (f *defaultFormats) MapStructureHookFunc() mapstructure.DecodeHookFunc {
|
||||
return func(from reflect.Type, to reflect.Type, data interface{}) (interface{}, error) {
|
||||
if from.Kind() != reflect.String {
|
||||
return data, nil
|
||||
}
|
||||
for _, v := range f.data {
|
||||
tpe, _ := f.GetType(v.Name)
|
||||
if to == tpe {
|
||||
switch v.Name {
|
||||
case "date":
|
||||
d, err := time.Parse(RFC3339FullDate, data.(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return Date(d), nil
|
||||
case "datetime":
|
||||
input := data.(string)
|
||||
if len(input) == 0 {
|
||||
return nil, fmt.Errorf("empty string is an invalid datetime format")
|
||||
}
|
||||
return ParseDateTime(input)
|
||||
case "duration":
|
||||
dur, err := ParseDuration(data.(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return Duration(dur), nil
|
||||
case "uri":
|
||||
return URI(data.(string)), nil
|
||||
case "email":
|
||||
return Email(data.(string)), nil
|
||||
case "uuid":
|
||||
return UUID(data.(string)), nil
|
||||
case "uuid3":
|
||||
return UUID3(data.(string)), nil
|
||||
case "uuid4":
|
||||
return UUID4(data.(string)), nil
|
||||
case "uuid5":
|
||||
return UUID5(data.(string)), nil
|
||||
case "hostname":
|
||||
return Hostname(data.(string)), nil
|
||||
case "ipv4":
|
||||
return IPv4(data.(string)), nil
|
||||
case "ipv6":
|
||||
return IPv6(data.(string)), nil
|
||||
case "cidr":
|
||||
return CIDR(data.(string)), nil
|
||||
case "mac":
|
||||
return MAC(data.(string)), nil
|
||||
case "isbn":
|
||||
return ISBN(data.(string)), nil
|
||||
case "isbn10":
|
||||
return ISBN10(data.(string)), nil
|
||||
case "isbn13":
|
||||
return ISBN13(data.(string)), nil
|
||||
case "creditcard":
|
||||
return CreditCard(data.(string)), nil
|
||||
case "ssn":
|
||||
return SSN(data.(string)), nil
|
||||
case "hexcolor":
|
||||
return HexColor(data.(string)), nil
|
||||
case "rgbcolor":
|
||||
return RGBColor(data.(string)), nil
|
||||
case "byte":
|
||||
return Base64(data.(string)), nil
|
||||
case "password":
|
||||
return Password(data.(string)), nil
|
||||
default:
|
||||
return nil, errors.InvalidTypeName(v.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds a new format, return true if this was a new item instead of a replacement
|
||||
func (f *defaultFormats) Add(name string, strfmt Format, validator Validator) bool {
|
||||
f.Lock()
|
||||
|
||||
Reference in New Issue
Block a user