summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util
diff options
context:
space:
mode:
authorTomSweeneyRedHat <tsweeney@redhat.com>2020-01-14 14:46:46 -0500
committerTomSweeneyRedHat <tsweeney@redhat.com>2020-01-14 14:46:46 -0500
commitf5bda9994d5e6cb1ee42ade5e7786059feedf633 (patch)
tree4473a0c3b4615ee58165f06ccf57a1bfe4298fe9 /vendor/k8s.io/apimachinery/pkg/util
parent564bd693cae4e8a870be7a7860ef673e793f6358 (diff)
downloadpodman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.tar.gz
podman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.tar.bz2
podman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.zip
Bump to Buildah v1.13.1
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/clock/clock.go39
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/intstr/intstr.go2
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/json/json.go28
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/naming/from_stack.go2
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/net/http.go20
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/net/interface.go73
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/net/util.go17
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go11
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/sets/byte.go6
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/sets/int.go6
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/sets/int32.go6
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/sets/int64.go6
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/sets/string.go6
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/validation/field/errors.go15
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/validation/validation.go46
15 files changed, 236 insertions, 47 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go b/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
index 0d739d961..1689e62e8 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/clock/clock.go
@@ -21,11 +21,18 @@ import (
"time"
)
+// PassiveClock allows for injecting fake or real clocks into code
+// that needs to read the current time but does not support scheduling
+// activity in the future.
+type PassiveClock interface {
+ Now() time.Time
+ Since(time.Time) time.Duration
+}
+
// Clock allows for injecting fake or real clocks into code that
// needs to do arbitrary things based on time.
type Clock interface {
- Now() time.Time
- Since(time.Time) time.Duration
+ PassiveClock
After(time.Duration) <-chan time.Time
NewTimer(time.Duration) Timer
Sleep(time.Duration)
@@ -66,10 +73,15 @@ func (RealClock) Sleep(d time.Duration) {
time.Sleep(d)
}
-// FakeClock implements Clock, but returns an arbitrary time.
-type FakeClock struct {
+// FakePassiveClock implements PassiveClock, but returns an arbitrary time.
+type FakePassiveClock struct {
lock sync.RWMutex
time time.Time
+}
+
+// FakeClock implements Clock, but returns an arbitrary time.
+type FakeClock struct {
+ FakePassiveClock
// waiters are waiting for the fake time to pass their specified time
waiters []fakeClockWaiter
@@ -82,26 +94,39 @@ type fakeClockWaiter struct {
destChan chan time.Time
}
+func NewFakePassiveClock(t time.Time) *FakePassiveClock {
+ return &FakePassiveClock{
+ time: t,
+ }
+}
+
func NewFakeClock(t time.Time) *FakeClock {
return &FakeClock{
- time: t,
+ FakePassiveClock: *NewFakePassiveClock(t),
}
}
// Now returns f's time.
-func (f *FakeClock) Now() time.Time {
+func (f *FakePassiveClock) Now() time.Time {
f.lock.RLock()
defer f.lock.RUnlock()
return f.time
}
// Since returns time since the time in f.
-func (f *FakeClock) Since(ts time.Time) time.Duration {
+func (f *FakePassiveClock) Since(ts time.Time) time.Duration {
f.lock.RLock()
defer f.lock.RUnlock()
return f.time.Sub(ts)
}
+// Sets the time.
+func (f *FakePassiveClock) SetTime(t time.Time) {
+ f.lock.Lock()
+ defer f.lock.Unlock()
+ f.time = t
+}
+
// Fake version of time.After(d).
func (f *FakeClock) After(d time.Duration) <-chan time.Time {
f.lock.Lock()
diff --git a/vendor/k8s.io/apimachinery/pkg/util/intstr/intstr.go b/vendor/k8s.io/apimachinery/pkg/util/intstr/intstr.go
index 12c8a7b6c..2df629555 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/intstr/intstr.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/intstr/intstr.go
@@ -45,7 +45,7 @@ type IntOrString struct {
}
// Type represents the stored type of IntOrString.
-type Type int
+type Type int64
const (
Int Type = iota // The IntOrString holds an int.
diff --git a/vendor/k8s.io/apimachinery/pkg/util/json/json.go b/vendor/k8s.io/apimachinery/pkg/util/json/json.go
index 10c8cb837..0e2e30175 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/json/json.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/json/json.go
@@ -19,6 +19,7 @@ package json
import (
"bytes"
"encoding/json"
+ "fmt"
"io"
)
@@ -34,6 +35,9 @@ func Marshal(v interface{}) ([]byte, error) {
return json.Marshal(v)
}
+// limit recursive depth to prevent stack overflow errors
+const maxDepth = 10000
+
// Unmarshal unmarshals the given data
// If v is a *map[string]interface{}, numbers are converted to int64 or float64
func Unmarshal(data []byte, v interface{}) error {
@@ -48,7 +52,7 @@ func Unmarshal(data []byte, v interface{}) error {
return err
}
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
- return convertMapNumbers(*v)
+ return convertMapNumbers(*v, 0)
case *[]interface{}:
// Build a decoder from the given data
@@ -60,7 +64,7 @@ func Unmarshal(data []byte, v interface{}) error {
return err
}
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
- return convertSliceNumbers(*v)
+ return convertSliceNumbers(*v, 0)
default:
return json.Unmarshal(data, v)
@@ -69,16 +73,20 @@ func Unmarshal(data []byte, v interface{}) error {
// convertMapNumbers traverses the map, converting any json.Number values to int64 or float64.
// values which are map[string]interface{} or []interface{} are recursively visited
-func convertMapNumbers(m map[string]interface{}) error {
+func convertMapNumbers(m map[string]interface{}, depth int) error {
+ if depth > maxDepth {
+ return fmt.Errorf("exceeded max depth of %d", maxDepth)
+ }
+
var err error
for k, v := range m {
switch v := v.(type) {
case json.Number:
m[k], err = convertNumber(v)
case map[string]interface{}:
- err = convertMapNumbers(v)
+ err = convertMapNumbers(v, depth+1)
case []interface{}:
- err = convertSliceNumbers(v)
+ err = convertSliceNumbers(v, depth+1)
}
if err != nil {
return err
@@ -89,16 +97,20 @@ func convertMapNumbers(m map[string]interface{}) error {
// convertSliceNumbers traverses the slice, converting any json.Number values to int64 or float64.
// values which are map[string]interface{} or []interface{} are recursively visited
-func convertSliceNumbers(s []interface{}) error {
+func convertSliceNumbers(s []interface{}, depth int) error {
+ if depth > maxDepth {
+ return fmt.Errorf("exceeded max depth of %d", maxDepth)
+ }
+
var err error
for i, v := range s {
switch v := v.(type) {
case json.Number:
s[i], err = convertNumber(v)
case map[string]interface{}:
- err = convertMapNumbers(v)
+ err = convertMapNumbers(v, depth+1)
case []interface{}:
- err = convertSliceNumbers(v)
+ err = convertSliceNumbers(v, depth+1)
}
if err != nil {
return err
diff --git a/vendor/k8s.io/apimachinery/pkg/util/naming/from_stack.go b/vendor/k8s.io/apimachinery/pkg/util/naming/from_stack.go
index 2965d5a8b..d69bf32ca 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/naming/from_stack.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/naming/from_stack.go
@@ -82,7 +82,7 @@ var stackCreator = regexp.MustCompile(`(?m)^created by (.*)\n\s+(.*):(\d+) \+0x[
func extractStackCreator() (string, int, bool) {
stack := debug.Stack()
matches := stackCreator.FindStringSubmatch(string(stack))
- if matches == nil || len(matches) != 4 {
+ if len(matches) != 4 {
return "", 0, false
}
line, err := strconv.Atoi(matches[3])
diff --git a/vendor/k8s.io/apimachinery/pkg/util/net/http.go b/vendor/k8s.io/apimachinery/pkg/util/net/http.go
index 078f00d9b..f9540c63b 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/net/http.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/net/http.go
@@ -101,6 +101,9 @@ func SetOldTransportDefaults(t *http.Transport) *http.Transport {
if t.TLSHandshakeTimeout == 0 {
t.TLSHandshakeTimeout = defaultTransport.TLSHandshakeTimeout
}
+ if t.IdleConnTimeout == 0 {
+ t.IdleConnTimeout = defaultTransport.IdleConnTimeout
+ }
return t
}
@@ -111,7 +114,7 @@ func SetTransportDefaults(t *http.Transport) *http.Transport {
// Allow clients to disable http2 if needed.
if s := os.Getenv("DISABLE_HTTP2"); len(s) > 0 {
klog.Infof("HTTP2 has been explicitly disabled")
- } else {
+ } else if allowsHTTP2(t) {
if err := http2.ConfigureTransport(t); err != nil {
klog.Warningf("Transport failed http2 configuration: %v", err)
}
@@ -119,6 +122,21 @@ func SetTransportDefaults(t *http.Transport) *http.Transport {
return t
}
+func allowsHTTP2(t *http.Transport) bool {
+ if t.TLSClientConfig == nil || len(t.TLSClientConfig.NextProtos) == 0 {
+ // the transport expressed no NextProto preference, allow
+ return true
+ }
+ for _, p := range t.TLSClientConfig.NextProtos {
+ if p == http2.NextProtoTLS {
+ // the transport explicitly allowed http/2
+ return true
+ }
+ }
+ // the transport explicitly set NextProtos and excluded http/2
+ return false
+}
+
type RoundTripperWrapper interface {
http.RoundTripper
WrappedRoundTripper() http.RoundTripper
diff --git a/vendor/k8s.io/apimachinery/pkg/util/net/interface.go b/vendor/k8s.io/apimachinery/pkg/util/net/interface.go
index daf5d2496..836494d57 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/net/interface.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/net/interface.go
@@ -36,6 +36,18 @@ const (
familyIPv6 AddressFamily = 6
)
+type AddressFamilyPreference []AddressFamily
+
+var (
+ preferIPv4 = AddressFamilyPreference{familyIPv4, familyIPv6}
+ preferIPv6 = AddressFamilyPreference{familyIPv6, familyIPv4}
+)
+
+const (
+ // LoopbackInterfaceName is the default name of the loopback interface
+ LoopbackInterfaceName = "lo"
+)
+
const (
ipv4RouteFile = "/proc/net/route"
ipv6RouteFile = "/proc/net/ipv6_route"
@@ -53,7 +65,7 @@ type RouteFile struct {
parse func(input io.Reader) ([]Route, error)
}
-// noRoutesError can be returned by ChooseBindAddress() in case of no routes
+// noRoutesError can be returned in case of no routes
type noRoutesError struct {
message string
}
@@ -254,7 +266,7 @@ func getIPFromInterface(intfName string, forFamily AddressFamily, nw networkInte
return nil, nil
}
-// memberOF tells if the IP is of the desired family. Used for checking interface addresses.
+// memberOf tells if the IP is of the desired family. Used for checking interface addresses.
func memberOf(ip net.IP, family AddressFamily) bool {
if ip.To4() != nil {
return family == familyIPv4
@@ -265,8 +277,8 @@ func memberOf(ip net.IP, family AddressFamily) bool {
// chooseIPFromHostInterfaces looks at all system interfaces, trying to find one that is up that
// has a global unicast address (non-loopback, non-link local, non-point2point), and returns the IP.
-// Searches for IPv4 addresses, and then IPv6 addresses.
-func chooseIPFromHostInterfaces(nw networkInterfacer) (net.IP, error) {
+// addressFamilies determines whether it prefers IPv4 or IPv6
+func chooseIPFromHostInterfaces(nw networkInterfacer, addressFamilies AddressFamilyPreference) (net.IP, error) {
intfs, err := nw.Interfaces()
if err != nil {
return nil, err
@@ -274,7 +286,7 @@ func chooseIPFromHostInterfaces(nw networkInterfacer) (net.IP, error) {
if len(intfs) == 0 {
return nil, fmt.Errorf("no interfaces found on host.")
}
- for _, family := range []AddressFamily{familyIPv4, familyIPv6} {
+ for _, family := range addressFamilies {
klog.V(4).Infof("Looking for system interface with a global IPv%d address", uint(family))
for _, intf := range intfs {
if !isInterfaceUp(&intf) {
@@ -321,15 +333,19 @@ func chooseIPFromHostInterfaces(nw networkInterfacer) (net.IP, error) {
// IP of the interface with a gateway on it (with priority given to IPv4). For a node
// with no internet connection, it returns error.
func ChooseHostInterface() (net.IP, error) {
+ return chooseHostInterface(preferIPv4)
+}
+
+func chooseHostInterface(addressFamilies AddressFamilyPreference) (net.IP, error) {
var nw networkInterfacer = networkInterface{}
if _, err := os.Stat(ipv4RouteFile); os.IsNotExist(err) {
- return chooseIPFromHostInterfaces(nw)
+ return chooseIPFromHostInterfaces(nw, addressFamilies)
}
routes, err := getAllDefaultRoutes()
if err != nil {
return nil, err
}
- return chooseHostInterfaceFromRoute(routes, nw)
+ return chooseHostInterfaceFromRoute(routes, nw, addressFamilies)
}
// networkInterfacer defines an interface for several net library functions. Production
@@ -377,10 +393,10 @@ func getAllDefaultRoutes() ([]Route, error) {
}
// chooseHostInterfaceFromRoute cycles through each default route provided, looking for a
-// global IP address from the interface for the route. Will first look all each IPv4 route for
-// an IPv4 IP, and then will look at each IPv6 route for an IPv6 IP.
-func chooseHostInterfaceFromRoute(routes []Route, nw networkInterfacer) (net.IP, error) {
- for _, family := range []AddressFamily{familyIPv4, familyIPv6} {
+// global IP address from the interface for the route. addressFamilies determines whether it
+// prefers IPv4 or IPv6
+func chooseHostInterfaceFromRoute(routes []Route, nw networkInterfacer, addressFamilies AddressFamilyPreference) (net.IP, error) {
+ for _, family := range addressFamilies {
klog.V(4).Infof("Looking for default routes with IPv%d addresses", uint(family))
for _, route := range routes {
if route.Family != family {
@@ -401,12 +417,19 @@ func chooseHostInterfaceFromRoute(routes []Route, nw networkInterfacer) (net.IP,
return nil, fmt.Errorf("unable to select an IP from default routes.")
}
-// If bind-address is usable, return it directly
-// If bind-address is not usable (unset, 0.0.0.0, or loopback), we will use the host's default
-// interface.
-func ChooseBindAddress(bindAddress net.IP) (net.IP, error) {
+// ResolveBindAddress returns the IP address of a daemon, based on the given bindAddress:
+// If bindAddress is unset, it returns the host's default IP, as with ChooseHostInterface().
+// If bindAddress is unspecified or loopback, it returns the default IP of the same
+// address family as bindAddress.
+// Otherwise, it just returns bindAddress.
+func ResolveBindAddress(bindAddress net.IP) (net.IP, error) {
+ addressFamilies := preferIPv4
+ if bindAddress != nil && memberOf(bindAddress, familyIPv6) {
+ addressFamilies = preferIPv6
+ }
+
if bindAddress == nil || bindAddress.IsUnspecified() || bindAddress.IsLoopback() {
- hostIP, err := ChooseHostInterface()
+ hostIP, err := chooseHostInterface(addressFamilies)
if err != nil {
return nil, err
}
@@ -414,3 +437,21 @@ func ChooseBindAddress(bindAddress net.IP) (net.IP, error) {
}
return bindAddress, nil
}
+
+// ChooseBindAddressForInterface choose a global IP for a specific interface, with priority given to IPv4.
+// This is required in case of network setups where default routes are present, but network
+// interfaces use only link-local addresses (e.g. as described in RFC5549).
+// e.g when using BGP to announce a host IP over link-local ip addresses and this ip address is attached to the lo interface.
+func ChooseBindAddressForInterface(intfName string) (net.IP, error) {
+ var nw networkInterfacer = networkInterface{}
+ for _, family := range preferIPv4 {
+ ip, err := getIPFromInterface(intfName, family, nw)
+ if err != nil {
+ return nil, err
+ }
+ if ip != nil {
+ return ip, nil
+ }
+ }
+ return nil, fmt.Errorf("unable to select an IP from %s network interface", intfName)
+}
diff --git a/vendor/k8s.io/apimachinery/pkg/util/net/util.go b/vendor/k8s.io/apimachinery/pkg/util/net/util.go
index 8344d10c8..2e7cb9499 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/net/util.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/net/util.go
@@ -54,3 +54,20 @@ func IsConnectionReset(err error) bool {
}
return false
}
+
+// Returns if the given err is "connection refused" error
+func IsConnectionRefused(err error) bool {
+ if urlErr, ok := err.(*url.Error); ok {
+ err = urlErr.Err
+ }
+ if opErr, ok := err.(*net.OpError); ok {
+ err = opErr.Err
+ }
+ if osErr, ok := err.(*os.SyscallError); ok {
+ err = osErr.Err
+ }
+ if errno, ok := err.(syscall.Errno); ok && errno == syscall.ECONNREFUSED {
+ return true
+ }
+ return false
+}
diff --git a/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go b/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go
index c7348129a..1428443f5 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go
@@ -18,6 +18,7 @@ package runtime
import (
"fmt"
+ "net/http"
"runtime"
"sync"
"time"
@@ -56,8 +57,16 @@ func HandleCrash(additionalHandlers ...func(interface{})) {
}
}
-// logPanic logs the caller tree when a panic occurs.
+// logPanic logs the caller tree when a panic occurs (except in the special case of http.ErrAbortHandler).
func logPanic(r interface{}) {
+ if r == http.ErrAbortHandler {
+ // honor the http.ErrAbortHandler sentinel panic value:
+ // ErrAbortHandler is a sentinel panic value to abort a handler.
+ // While any panic from ServeHTTP aborts the response to the client,
+ // panicking with ErrAbortHandler also suppresses logging of a stack trace to the server's error log.
+ return
+ }
+
// Same as stdlib http server code. Manually allocate stack trace buffer size
// to prevent excessively large logs
const size = 64 << 10
diff --git a/vendor/k8s.io/apimachinery/pkg/util/sets/byte.go b/vendor/k8s.io/apimachinery/pkg/util/sets/byte.go
index 766f4501e..9bfa85d43 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/sets/byte.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/sets/byte.go
@@ -46,17 +46,19 @@ func ByteKeySet(theMap interface{}) Byte {
}
// Insert adds items to the set.
-func (s Byte) Insert(items ...byte) {
+func (s Byte) Insert(items ...byte) Byte {
for _, item := range items {
s[item] = Empty{}
}
+ return s
}
// Delete removes all items from the set.
-func (s Byte) Delete(items ...byte) {
+func (s Byte) Delete(items ...byte) Byte {
for _, item := range items {
delete(s, item)
}
+ return s
}
// Has returns true if and only if item is contained in the set.
diff --git a/vendor/k8s.io/apimachinery/pkg/util/sets/int.go b/vendor/k8s.io/apimachinery/pkg/util/sets/int.go
index a0a513cd9..88bd70967 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/sets/int.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/sets/int.go
@@ -46,17 +46,19 @@ func IntKeySet(theMap interface{}) Int {
}
// Insert adds items to the set.
-func (s Int) Insert(items ...int) {
+func (s Int) Insert(items ...int) Int {
for _, item := range items {
s[item] = Empty{}
}
+ return s
}
// Delete removes all items from the set.
-func (s Int) Delete(items ...int) {
+func (s Int) Delete(items ...int) Int {
for _, item := range items {
delete(s, item)
}
+ return s
}
// Has returns true if and only if item is contained in the set.
diff --git a/vendor/k8s.io/apimachinery/pkg/util/sets/int32.go b/vendor/k8s.io/apimachinery/pkg/util/sets/int32.go
index 584eabc8b..96a485554 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/sets/int32.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/sets/int32.go
@@ -46,17 +46,19 @@ func Int32KeySet(theMap interface{}) Int32 {
}
// Insert adds items to the set.
-func (s Int32) Insert(items ...int32) {
+func (s Int32) Insert(items ...int32) Int32 {
for _, item := range items {
s[item] = Empty{}
}
+ return s
}
// Delete removes all items from the set.
-func (s Int32) Delete(items ...int32) {
+func (s Int32) Delete(items ...int32) Int32 {
for _, item := range items {
delete(s, item)
}
+ return s
}
// Has returns true if and only if item is contained in the set.
diff --git a/vendor/k8s.io/apimachinery/pkg/util/sets/int64.go b/vendor/k8s.io/apimachinery/pkg/util/sets/int64.go
index 9ca9af0c5..b375a1b06 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/sets/int64.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/sets/int64.go
@@ -46,17 +46,19 @@ func Int64KeySet(theMap interface{}) Int64 {
}
// Insert adds items to the set.
-func (s Int64) Insert(items ...int64) {
+func (s Int64) Insert(items ...int64) Int64 {
for _, item := range items {
s[item] = Empty{}
}
+ return s
}
// Delete removes all items from the set.
-func (s Int64) Delete(items ...int64) {
+func (s Int64) Delete(items ...int64) Int64 {
for _, item := range items {
delete(s, item)
}
+ return s
}
// Has returns true if and only if item is contained in the set.
diff --git a/vendor/k8s.io/apimachinery/pkg/util/sets/string.go b/vendor/k8s.io/apimachinery/pkg/util/sets/string.go
index ba00ad7df..e6f37db88 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/sets/string.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/sets/string.go
@@ -46,17 +46,19 @@ func StringKeySet(theMap interface{}) String {
}
// Insert adds items to the set.
-func (s String) Insert(items ...string) {
+func (s String) Insert(items ...string) String {
for _, item := range items {
s[item] = Empty{}
}
+ return s
}
// Delete removes all items from the set.
-func (s String) Delete(items ...string) {
+func (s String) Delete(items ...string) String {
for _, item := range items {
delete(s, item)
}
+ return s
}
// Has returns true if and only if item is contained in the set.
diff --git a/vendor/k8s.io/apimachinery/pkg/util/validation/field/errors.go b/vendor/k8s.io/apimachinery/pkg/util/validation/field/errors.go
index 4767fd1dd..0cd5d6577 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/validation/field/errors.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/validation/field/errors.go
@@ -116,6 +116,10 @@ const (
// This is similar to ErrorTypeInvalid, but the error will not include the
// too-long value. See TooLong().
ErrorTypeTooLong ErrorType = "FieldValueTooLong"
+ // ErrorTypeTooMany is used to report "too many". This is used to
+ // report that a given list has too many items. This is similar to FieldValueTooLong,
+ // but the error indicates quantity instead of length.
+ ErrorTypeTooMany ErrorType = "FieldValueTooMany"
// ErrorTypeInternal is used to report other errors that are not related
// to user input. See InternalError().
ErrorTypeInternal ErrorType = "InternalError"
@@ -138,6 +142,8 @@ func (t ErrorType) String() string {
return "Forbidden"
case ErrorTypeTooLong:
return "Too long"
+ case ErrorTypeTooMany:
+ return "Too many"
case ErrorTypeInternal:
return "Internal error"
default:
@@ -198,7 +204,14 @@ func Forbidden(field *Path, detail string) *Error {
// Invalid, but the returned error will not include the too-long
// value.
func TooLong(field *Path, value interface{}, maxLength int) *Error {
- return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d characters", maxLength)}
+ return &Error{ErrorTypeTooLong, field.String(), value, fmt.Sprintf("must have at most %d bytes", maxLength)}
+}
+
+// TooMany returns a *Error indicating "too many". This is used to
+// report that a given list has too many items. This is similar to TooLong,
+// but the returned error indicates quantity instead of length.
+func TooMany(field *Path, actualQuantity, maxQuantity int) *Error {
+ return &Error{ErrorTypeTooMany, field.String(), actualQuantity, fmt.Sprintf("must have at most %d items", maxQuantity)}
}
// InternalError returns a *Error indicating "internal error". This is used
diff --git a/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go b/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
index 2dd99992d..8e1907c2a 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
@@ -70,7 +70,11 @@ func IsQualifiedName(value string) []string {
return errs
}
-// IsFullyQualifiedName checks if the name is fully qualified.
+// IsFullyQualifiedName checks if the name is fully qualified. This is similar
+// to IsFullyQualifiedDomainName but requires a minimum of 3 segments instead of
+// 2 and does not accept a trailing . as valid.
+// TODO: This function is deprecated and preserved until all callers migrate to
+// IsFullyQualifiedDomainName; please don't add new callers.
func IsFullyQualifiedName(fldPath *field.Path, name string) field.ErrorList {
var allErrors field.ErrorList
if len(name) == 0 {
@@ -85,6 +89,26 @@ func IsFullyQualifiedName(fldPath *field.Path, name string) field.ErrorList {
return allErrors
}
+// IsFullyQualifiedDomainName checks if the domain name is fully qualified. This
+// is similar to IsFullyQualifiedName but only requires a minimum of 2 segments
+// instead of 3 and accepts a trailing . as valid.
+func IsFullyQualifiedDomainName(fldPath *field.Path, name string) field.ErrorList {
+ var allErrors field.ErrorList
+ if len(name) == 0 {
+ return append(allErrors, field.Required(fldPath, ""))
+ }
+ if strings.HasSuffix(name, ".") {
+ name = name[:len(name)-1]
+ }
+ if errs := IsDNS1123Subdomain(name); len(errs) > 0 {
+ return append(allErrors, field.Invalid(fldPath, name, strings.Join(errs, ",")))
+ }
+ if len(strings.Split(name, ".")) < 2 {
+ return append(allErrors, field.Invalid(fldPath, name, "should be a domain with at least two segments separated by dots"))
+ }
+ return allErrors
+}
+
const labelValueFmt string = "(" + qualifiedNameFmt + ")?"
const labelValueErrMsg string = "a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character"
@@ -285,6 +309,26 @@ func IsValidIP(value string) []string {
return nil
}
+// IsValidIPv4Address tests that the argument is a valid IPv4 address.
+func IsValidIPv4Address(fldPath *field.Path, value string) field.ErrorList {
+ var allErrors field.ErrorList
+ ip := net.ParseIP(value)
+ if ip == nil || ip.To4() == nil {
+ allErrors = append(allErrors, field.Invalid(fldPath, value, "must be a valid IPv4 address"))
+ }
+ return allErrors
+}
+
+// IsValidIPv6Address tests that the argument is a valid IPv6 address.
+func IsValidIPv6Address(fldPath *field.Path, value string) field.ErrorList {
+ var allErrors field.ErrorList
+ ip := net.ParseIP(value)
+ if ip == nil || ip.To4() != nil {
+ allErrors = append(allErrors, field.Invalid(fldPath, value, "must be a valid IPv6 address"))
+ }
+ return allErrors
+}
+
const percentFmt string = "[0-9]+%"
const percentErrMsg string = "a valid percent string must be a numeric string followed by an ending '%'"