code
stringlengths 12
335k
| docstring
stringlengths 20
20.8k
| func_name
stringlengths 1
105
| language
stringclasses 1
value | repo
stringclasses 498
values | path
stringlengths 5
172
| url
stringlengths 43
235
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func IsDualStackCIDRStrings(cidrs []string) (bool, error) {
parsedCIDRs, err := ParseCIDRs(cidrs)
if err != nil {
return false, err
}
return IsDualStackCIDRs(parsedCIDRs)
} | IsDualStackCIDRStrings returns if
- all elements of cidrs can be parsed as CIDRs
- at least one CIDR from each family (v4 and v6) is present | IsDualStackCIDRStrings | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IPFamilyOf(ip net.IP) IPFamily {
switch {
case ip.To4() != nil:
return IPv4
case ip.To16() != nil:
return IPv6
default:
return IPFamilyUnknown
}
} | IPFamilyOf returns the IP family of ip, or IPFamilyUnknown if it is invalid. | IPFamilyOf | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IPFamilyOfString(ip string) IPFamily {
return IPFamilyOf(ParseIPSloppy(ip))
} | IPFamilyOfString returns the IP family of ip, or IPFamilyUnknown if ip cannot
be parsed as an IP. | IPFamilyOfString | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IPFamilyOfCIDR(cidr *net.IPNet) IPFamily {
if cidr == nil {
return IPFamilyUnknown
}
return IPFamilyOf(cidr.IP)
} | IPFamilyOfCIDR returns the IP family of cidr. | IPFamilyOfCIDR | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IPFamilyOfCIDRString(cidr string) IPFamily {
ip, _, _ := ParseCIDRSloppy(cidr)
return IPFamilyOf(ip)
} | IPFamilyOfCIDRString returns the IP family of cidr. | IPFamilyOfCIDRString | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv6(netIP net.IP) bool {
return IPFamilyOf(netIP) == IPv6
} | IsIPv6 returns true if netIP is IPv6 (and false if it is IPv4, nil, or invalid). | IsIPv6 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv6String(ip string) bool {
return IPFamilyOfString(ip) == IPv6
} | IsIPv6String returns true if ip contains a single IPv6 address and nothing else. It
returns false if ip is an empty string, an IPv4 address, or anything else that is not a
single IPv6 address. | IsIPv6String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv6CIDR(cidr *net.IPNet) bool {
return IPFamilyOfCIDR(cidr) == IPv6
} | IsIPv6CIDR returns true if a cidr is a valid IPv6 CIDR. It returns false if cidr is
nil or an IPv4 CIDR. Its behavior is not defined if cidr is invalid. | IsIPv6CIDR | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv6CIDRString(cidr string) bool {
return IPFamilyOfCIDRString(cidr) == IPv6
} | IsIPv6CIDRString returns true if cidr contains a single IPv6 CIDR and nothing else. It
returns false if cidr is an empty string, an IPv4 CIDR, or anything else that is not a
single valid IPv6 CIDR. | IsIPv6CIDRString | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv4(netIP net.IP) bool {
return IPFamilyOf(netIP) == IPv4
} | IsIPv4 returns true if netIP is IPv4 (and false if it is IPv6, nil, or invalid). | IsIPv4 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv4String(ip string) bool {
return IPFamilyOfString(ip) == IPv4
} | IsIPv4String returns true if ip contains a single IPv4 address and nothing else. It
returns false if ip is an empty string, an IPv6 address, or anything else that is not a
single IPv4 address. | IsIPv4String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv4CIDR(cidr *net.IPNet) bool {
return IPFamilyOfCIDR(cidr) == IPv4
} | IsIPv4CIDR returns true if cidr is a valid IPv4 CIDR. It returns false if cidr is nil
or an IPv6 CIDR. Its behavior is not defined if cidr is invalid. | IsIPv4CIDR | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func IsIPv4CIDRString(cidr string) bool {
return IPFamilyOfCIDRString(cidr) == IPv4
} | IsIPv4CIDRString returns true if cidr contains a single IPv4 CIDR and nothing else. It
returns false if cidr is an empty string, an IPv6 CIDR, or anything else that is not a
single valid IPv4 CIDR. | IsIPv4CIDRString | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipfamily.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go | Apache-2.0 |
func ParseCIDRs(cidrsString []string) ([]*net.IPNet, error) {
cidrs := make([]*net.IPNet, 0, len(cidrsString))
for i, cidrString := range cidrsString {
_, cidr, err := ParseCIDRSloppy(cidrString)
if err != nil {
return nil, fmt.Errorf("invalid CIDR[%d]: %v (%v)", i, cidr, err)
}
cidrs = append(cidrs, cidr)
}
return cidrs, nil
} | ParseCIDRs parses a list of cidrs and return error if any is invalid.
order is maintained | ParseCIDRs | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/net.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/net.go | Apache-2.0 |
func ParsePort(port string, allowZero bool) (int, error) {
portInt, err := strconv.ParseUint(port, 10, 16)
if err != nil {
return 0, err
}
if portInt == 0 && !allowZero {
return 0, errors.New("0 is not a valid port number")
}
return int(portInt), nil
} | ParsePort parses a string representing an IP port. If the string is not a
valid port number, this returns an error. | ParsePort | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/net.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/net.go | Apache-2.0 |
func BigForIP(ip net.IP) *big.Int {
// NOTE: Convert to 16-byte representation so we can
// handle v4 and v6 values the same way.
return big.NewInt(0).SetBytes(ip.To16())
} | BigForIP creates a big.Int based on the provided net.IP | BigForIP | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/net.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/net.go | Apache-2.0 |
func AddIPOffset(base *big.Int, offset int) net.IP {
r := big.NewInt(0).Add(base, big.NewInt(int64(offset))).Bytes()
r = append(make([]byte, 16), r...)
return net.IP(r[len(r)-16:])
} | AddIPOffset adds the provided integer offset to a base big.Int representing a net.IP
NOTE: If you started with a v4 address and overflow it, you get a v6 result. | AddIPOffset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/net.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/net.go | Apache-2.0 |
func RangeSize(subnet *net.IPNet) int64 {
ones, bits := subnet.Mask.Size()
if bits == 32 && (bits-ones) >= 31 || bits == 128 && (bits-ones) >= 127 {
return 0
}
// this checks that we are not overflowing an int64
if bits-ones >= 63 {
return math.MaxInt64
}
return int64(1) << uint(bits-ones)
} | RangeSize returns the size of a range in valid addresses.
returns the size of the subnet (or math.MaxInt64 if the range size would overflow int64) | RangeSize | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/net.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/net.go | Apache-2.0 |
func GetIndexedIP(subnet *net.IPNet, index int) (net.IP, error) {
ip := AddIPOffset(BigForIP(subnet.IP), index)
if !subnet.Contains(ip) {
return nil, fmt.Errorf("can't generate IP with index %d from subnet. subnet too small. subnet: %q", index, subnet)
}
return ip, nil
} | GetIndexedIP returns a net.IP that is subnet.IP + index in the contiguous IP space. | GetIndexedIP | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/net.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/net.go | Apache-2.0 |
func ParseIPNets(specs ...string) (IPNetSet, error) {
ipnetset := make(IPNetSet)
for _, spec := range specs {
spec = strings.TrimSpace(spec)
_, ipnet, err := ParseCIDRSloppy(spec)
if err != nil {
return nil, err
}
k := ipnet.String() // In case of normalization
ipnetset[k] = ipnet
}
return ipnetset, nil
} | ParseIPNets parses string slice to IPNetSet. | ParseIPNets | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) Insert(items ...*net.IPNet) {
for _, item := range items {
s[item.String()] = item
}
} | Insert adds items to the set. | Insert | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) Delete(items ...*net.IPNet) {
for _, item := range items {
delete(s, item.String())
}
} | Delete removes all items from the set. | Delete | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) Has(item *net.IPNet) bool {
_, contained := s[item.String()]
return contained
} | Has returns true if and only if item is contained in the set. | Has | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) HasAll(items ...*net.IPNet) bool {
for _, item := range items {
if !s.Has(item) {
return false
}
}
return true
} | HasAll returns true if and only if all items are contained in the set. | HasAll | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) Difference(s2 IPNetSet) IPNetSet {
result := make(IPNetSet)
for k, i := range s {
_, found := s2[k]
if found {
continue
}
result[k] = i
}
return result
} | Difference returns a set of objects that are not in s2
For example:
s1 = {a1, a2, a3}
s2 = {a1, a2, a4, a5}
s1.Difference(s2) = {a3}
s2.Difference(s1) = {a4, a5} | Difference | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) StringSlice() []string {
a := make([]string, 0, len(s))
for k := range s {
a = append(a, k)
}
return a
} | StringSlice returns a []string with the String representation of each element in the set.
Order is undefined. | StringSlice | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) IsSuperset(s2 IPNetSet) bool {
for k := range s2 {
_, found := s[k]
if !found {
return false
}
}
return true
} | IsSuperset returns true if and only if s1 is a superset of s2. | IsSuperset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) Equal(s2 IPNetSet) bool {
return len(s) == len(s2) && s.IsSuperset(s2)
} | Equal returns true if and only if s1 is equal (as a set) to s2.
Two sets are equal if their membership is identical.
(In practice, this means same elements, order doesn't matter) | Equal | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPNetSet) Len() int {
return len(s)
} | Len returns the size of the set. | Len | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func ParseIPSet(items ...string) (IPSet, error) {
ipset := make(IPSet)
for _, item := range items {
ip := ParseIPSloppy(strings.TrimSpace(item))
if ip == nil {
return nil, fmt.Errorf("error parsing IP %q", item)
}
ipset[ip.String()] = ip
}
return ipset, nil
} | ParseIPSet parses string slice to IPSet | ParseIPSet | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) Insert(items ...net.IP) {
for _, item := range items {
s[item.String()] = item
}
} | Insert adds items to the set. | Insert | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) Delete(items ...net.IP) {
for _, item := range items {
delete(s, item.String())
}
} | Delete removes all items from the set. | Delete | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) Has(item net.IP) bool {
_, contained := s[item.String()]
return contained
} | Has returns true if and only if item is contained in the set. | Has | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) HasAll(items ...net.IP) bool {
for _, item := range items {
if !s.Has(item) {
return false
}
}
return true
} | HasAll returns true if and only if all items are contained in the set. | HasAll | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) Difference(s2 IPSet) IPSet {
result := make(IPSet)
for k, i := range s {
_, found := s2[k]
if found {
continue
}
result[k] = i
}
return result
} | Difference returns a set of objects that are not in s2
For example:
s1 = {a1, a2, a3}
s2 = {a1, a2, a4, a5}
s1.Difference(s2) = {a3}
s2.Difference(s1) = {a4, a5} | Difference | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) StringSlice() []string {
a := make([]string, 0, len(s))
for k := range s {
a = append(a, k)
}
return a
} | StringSlice returns a []string with the String representation of each element in the set.
Order is undefined. | StringSlice | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) IsSuperset(s2 IPSet) bool {
for k := range s2 {
_, found := s[k]
if !found {
return false
}
}
return true
} | IsSuperset returns true if and only if s1 is a superset of s2. | IsSuperset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) Equal(s2 IPSet) bool {
return len(s) == len(s2) && s.IsSuperset(s2)
} | Equal returns true if and only if s1 is equal (as a set) to s2.
Two sets are equal if their membership is identical.
(In practice, this means same elements, order doesn't matter) | Equal | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func (s IPSet) Len() int {
return len(s)
} | Len returns the size of the set. | Len | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/net/ipnet.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipnet.go | Apache-2.0 |
func Equal(s1, s2 []string) bool {
if len(s1) != len(s2) {
return false
}
for i, n := range s1 {
if n != s2[i] {
return false
}
}
return true
} | Equal reports whether two slices are equal: the same length and all
elements equal. If the lengths are different, Equal returns false.
Otherwise, the elements are compared in index order, and the
comparison stops at the first unequal pair. | Equal | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/strings/slices/slices.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/strings/slices/slices.go | Apache-2.0 |
func Filter(d, s []string, keep func(string) bool) []string {
for _, n := range s {
if keep(n) {
d = append(d, n)
}
}
return d
} | Filter appends to d each element e of s for which keep(e) returns true.
It returns the modified d. d may be s[:0], in which case the kept
elements will be stored in the same slice.
if the slices overlap in some other way, the results are unspecified.
To create a new slice with the filtered results, pass nil for d. | Filter | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/strings/slices/slices.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/strings/slices/slices.go | Apache-2.0 |
func Contains(s []string, v string) bool {
return Index(s, v) >= 0
} | Contains reports whether v is present in s. | Contains | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/strings/slices/slices.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/strings/slices/slices.go | Apache-2.0 |
func Index(s []string, v string) int {
// "Contains" may be replaced with "Index(s, v) >= 0":
// https://github.com/golang/go/issues/45955#issuecomment-873377947
for i, n := range s {
if n == v {
return i
}
}
return -1
} | Index returns the index of the first occurrence of v in s, or -1 if
not present. | Index | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/strings/slices/slices.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/strings/slices/slices.go | Apache-2.0 |
func Clone(s []string) []string {
// https://github.com/go101/go101/wiki/There-is-not-a-perfect-way-to-clone-slices-in-Go
if s == nil {
return nil
}
c := make([]string, len(s))
copy(c, s)
return c
} | Clone returns a new clone of s. | Clone | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/strings/slices/slices.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/strings/slices/slices.go | Apache-2.0 |
func NewRingGrowing(initialSize int) *RingGrowing {
return &RingGrowing{
data: make([]interface{}, initialSize),
n: initialSize,
}
} | NewRingGrowing constructs a new RingGrowing instance with provided parameters. | NewRingGrowing | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/buffer/ring_growing.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/buffer/ring_growing.go | Apache-2.0 |
func (r *RingGrowing) ReadOne() (data interface{}, ok bool) {
if r.readable == 0 {
return nil, false
}
r.readable--
element := r.data[r.beg]
r.data[r.beg] = nil // Remove reference to the object to help GC
if r.beg == r.n-1 {
// Was the last element
r.beg = 0
} else {
r.beg++
}
return element, true
} | ReadOne reads (consumes) first item from the buffer if it is available, otherwise returns false. | ReadOne | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/buffer/ring_growing.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/buffer/ring_growing.go | Apache-2.0 |
func (r *RingGrowing) WriteOne(data interface{}) {
if r.readable == r.n {
// Time to grow
newN := r.n * 2
newData := make([]interface{}, newN)
to := r.beg + r.readable
if to <= r.n {
copy(newData, r.data[r.beg:to])
} else {
copied := copy(newData, r.data[r.beg:])
copy(newData[copied:], r.data[:(to%r.n)])
}
r.beg = 0
r.data = newData
r.n = newN
}
r.data[(r.readable+r.beg)%r.n] = data
r.readable++
} | WriteOne adds an item to the end of the buffer, growing it if it is full. | WriteOne | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/buffer/ring_growing.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/buffer/ring_growing.go | Apache-2.0 |
func AllPtrFieldsNil(obj interface{}) bool {
v := reflect.ValueOf(obj)
if !v.IsValid() {
panic(fmt.Sprintf("reflect.ValueOf() produced a non-valid Value for %#v", obj))
}
if v.Kind() == reflect.Ptr {
if v.IsNil() {
return true
}
v = v.Elem()
}
for i := 0; i < v.NumField(); i++ {
if v.Field(i).Kind() == reflect.Ptr && !v.Field(i).IsNil() {
return false
}
}
return true
} | AllPtrFieldsNil tests whether all pointer fields in a struct are nil. This is useful when,
for example, an API struct is handled by plugins which need to distinguish
"no plugin accepted this spec" from "this spec is empty".
This function is only valid for structs and pointers to structs. Any other
type will cause a panic. Passing a typed nil pointer will return true. | AllPtrFieldsNil | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/ptr/ptr.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/ptr/ptr.go | Apache-2.0 |
func IntMax(a, b int) int {
if b > a {
return b
}
return a
} | IntMax returns the maximum of the params | IntMax | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/integer/integer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/integer/integer.go | Apache-2.0 |
func IntMin(a, b int) int {
if b < a {
return b
}
return a
} | IntMin returns the minimum of the params | IntMin | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/integer/integer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/integer/integer.go | Apache-2.0 |
func Int32Max(a, b int32) int32 {
if b > a {
return b
}
return a
} | Int32Max returns the maximum of the params | Int32Max | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/integer/integer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/integer/integer.go | Apache-2.0 |
func Int32Min(a, b int32) int32 {
if b < a {
return b
}
return a
} | Int32Min returns the minimum of the params | Int32Min | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/integer/integer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/integer/integer.go | Apache-2.0 |
func Int64Max(a, b int64) int64 {
if b > a {
return b
}
return a
} | Int64Max returns the maximum of the params | Int64Max | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/integer/integer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/integer/integer.go | Apache-2.0 |
func Int64Min(a, b int64) int64 {
if b < a {
return b
}
return a
} | Int64Min returns the minimum of the params | Int64Min | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/integer/integer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/integer/integer.go | Apache-2.0 |
func RoundToInt32(a float64) int32 {
if a < 0 {
return int32(a - 0.5)
}
return int32(a + 0.5)
} | RoundToInt32 rounds floats into integer numbers. | RoundToInt32 | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/utils/integer/integer.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/integer/integer.go | Apache-2.0 |
func (info Info) String() string {
return info.GitVersion
} | String returns info as a human-friendly version string. | String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/version/types.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/version/types.go | Apache-2.0 |
func CompareKubeAwareVersionStrings(v1, v2 string) int {
if v1 == v2 {
return 0
}
v1major, v1type, v1minor, ok1 := parseKubeVersion(v1)
v2major, v2type, v2minor, ok2 := parseKubeVersion(v2)
switch {
case !ok1 && !ok2:
return strings.Compare(v2, v1)
case !ok1 && ok2:
return -1
case ok1 && !ok2:
return 1
}
if v1type != v2type {
return int(v1type) - int(v2type)
}
if v1major != v2major {
return v1major - v2major
}
return v1minor - v2minor
} | CompareKubeAwareVersionStrings compares two kube-like version strings.
Kube-like version strings are starting with a v, followed by a major version, optional "alpha" or "beta" strings
followed by a minor version (e.g. v1, v2beta1). Versions will be sorted based on GA/alpha/beta first and then major
and minor versions. e.g. v2, v1, v1beta2, v1beta1, v1alpha1. | CompareKubeAwareVersionStrings | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/version/helpers.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/version/helpers.go | Apache-2.0 |
func JoinPreservingTrailingSlash(elem ...string) string {
// do the basic path join
result := path.Join(elem...)
// find the last non-empty segment
for i := len(elem) - 1; i >= 0; i-- {
if len(elem[i]) > 0 {
// if the last segment ended in a slash, ensure our result does as well
if strings.HasSuffix(elem[i], "/") && !strings.HasSuffix(result, "/") {
result += "/"
}
break
}
}
return result
} | JoinPreservingTrailingSlash does a path.Join of the specified elements,
preserving any trailing slash on the last non-empty segment | JoinPreservingTrailingSlash | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func IsTimeout(err error) bool {
var neterr net.Error
if errors.As(err, &neterr) {
return neterr != nil && neterr.Timeout()
}
return false
} | IsTimeout returns true if the given error is a network timeout error | IsTimeout | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func IsProbableEOF(err error) bool {
if err == nil {
return false
}
var uerr *url.Error
if errors.As(err, &uerr) {
err = uerr.Err
}
msg := err.Error()
switch {
case err == io.EOF:
return true
case err == io.ErrUnexpectedEOF:
return true
case msg == "http: can't write HTTP request on broken connection":
return true
case strings.Contains(msg, "http2: server sent GOAWAY and closed the connection"):
return true
case strings.Contains(msg, "connection reset by peer"):
return true
case strings.Contains(strings.ToLower(msg), "use of closed network connection"):
return true
}
return false
} | IsProbableEOF returns true if the given error resembles a connection termination
scenario that would justify assuming that the watch is empty.
These errors are what the Go http stack returns back to us which are general
connection closure errors (strongly correlated) and callers that need to
differentiate probable errors in connection behavior between normal "this is
disconnected" should use the method. | IsProbableEOF | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func SetOldTransportDefaults(t *http.Transport) *http.Transport {
if t.Proxy == nil || isDefault(t.Proxy) {
// http.ProxyFromEnvironment doesn't respect CIDRs and that makes it impossible to exclude things like pod and service IPs from proxy settings
// ProxierWithNoProxyCIDR allows CIDR rules in NO_PROXY
t.Proxy = NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment)
}
// If no custom dialer is set, use the default context dialer
//lint:file-ignore SA1019 Keep supporting deprecated Dial method of custom transports
if t.DialContext == nil && t.Dial == nil {
t.DialContext = defaultTransport.DialContext
}
if t.TLSHandshakeTimeout == 0 {
t.TLSHandshakeTimeout = defaultTransport.TLSHandshakeTimeout
}
if t.IdleConnTimeout == 0 {
t.IdleConnTimeout = defaultTransport.IdleConnTimeout
}
return t
} | SetOldTransportDefaults applies the defaults from http.DefaultTransport
for the Proxy, Dial, and TLSHandshakeTimeout fields if unset | SetOldTransportDefaults | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func SetTransportDefaults(t *http.Transport) *http.Transport {
t = SetOldTransportDefaults(t)
// Allow clients to disable http2 if needed.
if s := os.Getenv("DISABLE_HTTP2"); len(s) > 0 {
klog.Info("HTTP2 has been explicitly disabled")
} else if allowsHTTP2(t) {
if err := configureHTTP2Transport(t); err != nil {
klog.Warningf("Transport failed http2 configuration: %v", err)
}
}
return t
} | SetTransportDefaults applies the defaults from http.DefaultTransport
for the Proxy, Dial, and TLSHandshakeTimeout fields if unset | SetTransportDefaults | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func CloseIdleConnectionsFor(transport http.RoundTripper) {
if transport == nil {
return
}
type closeIdler interface {
CloseIdleConnections()
}
switch transport := transport.(type) {
case closeIdler:
transport.CloseIdleConnections()
case RoundTripperWrapper:
CloseIdleConnectionsFor(transport.WrappedRoundTripper())
default:
klog.Warningf("unknown transport type: %T", transport)
} | CloseIdleConnectionsFor close idles connections for the Transport.
If the Transport is wrapped it iterates over the wrapped round trippers
until it finds one that implements the CloseIdleConnections method.
If the Transport does not have a CloseIdleConnections method
then this function does nothing. | CloseIdleConnectionsFor | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func SourceIPs(req *http.Request) []net.IP {
var srcIPs []net.IP
hdr := req.Header
// First check the X-Forwarded-For header for requests via proxy.
hdrForwardedFor := hdr.Get("X-Forwarded-For")
if hdrForwardedFor != "" {
// X-Forwarded-For can be a csv of IPs in case of multiple proxies.
// Use the first valid one.
parts := strings.Split(hdrForwardedFor, ",")
for _, part := range parts {
ip := netutils.ParseIPSloppy(strings.TrimSpace(part))
if ip != nil {
srcIPs = append(srcIPs, ip)
}
}
}
// Try the X-Real-Ip header.
hdrRealIp := hdr.Get("X-Real-Ip")
if hdrRealIp != "" {
ip := netutils.ParseIPSloppy(hdrRealIp)
// Only append the X-Real-Ip if it's not already contained in the X-Forwarded-For chain.
if ip != nil && !containsIP(srcIPs, ip) {
srcIPs = append(srcIPs, ip)
}
}
// Always include the request Remote Address as it cannot be easily spoofed.
var remoteIP net.IP
// Remote Address in Go's HTTP server is in the form host:port so we need to split that first.
host, _, err := net.SplitHostPort(req.RemoteAddr)
if err == nil {
remoteIP = netutils.ParseIPSloppy(host)
}
// Fallback if Remote Address was just IP.
if remoteIP == nil {
remoteIP = netutils.ParseIPSloppy(req.RemoteAddr)
}
// Don't duplicate remote IP if it's already the last address in the chain.
if remoteIP != nil && (len(srcIPs) == 0 || !remoteIP.Equal(srcIPs[len(srcIPs)-1])) {
srcIPs = append(srcIPs, remoteIP)
}
return srcIPs
} | SourceIPs splits the comma separated X-Forwarded-For header and joins it with
the X-Real-Ip header and/or req.RemoteAddr, ignoring invalid IPs.
The X-Real-Ip is omitted if it's already present in the X-Forwarded-For chain.
The req.RemoteAddr is always the last IP in the returned list.
It returns nil if all of these are empty or invalid. | SourceIPs | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func containsIP(ips []net.IP, ip net.IP) bool {
for _, v := range ips {
if v.Equal(ip) {
return true
}
}
return false
} | Checks whether the given IP address is contained in the list of IPs. | containsIP | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func GetClientIP(req *http.Request) net.IP {
ips := SourceIPs(req)
if len(ips) == 0 {
return nil
}
return ips[0]
} | Extracts and returns the clients IP from the given request.
Looks at X-Forwarded-For header, X-Real-Ip header and request.RemoteAddr in that order.
Returns nil if none of them are set or is set to an invalid value. | GetClientIP | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func AppendForwardedForHeader(req *http.Request) {
// Copied from net/http/httputil/reverseproxy.go:
if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
// If we aren't the first proxy retain prior
// X-Forwarded-For information as a comma+space
// separated list and fold multiple headers into one.
if prior, ok := req.Header["X-Forwarded-For"]; ok {
clientIP = strings.Join(prior, ", ") + ", " + clientIP
}
req.Header.Set("X-Forwarded-For", clientIP)
}
} | Prepares the X-Forwarded-For header for another forwarding hop by appending the previous sender's
IP address to the X-Forwarded-For chain. | AppendForwardedForHeader | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func isDefault(transportProxier func(*http.Request) (*url.URL, error)) bool {
transportProxierPointer := fmt.Sprintf("%p", transportProxier)
return transportProxierPointer == defaultProxyFuncPointer
} | isDefault checks to see if the transportProxierFunc is pointing to the default one | isDefault | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func NewProxierWithNoProxyCIDR(delegate func(req *http.Request) (*url.URL, error)) func(req *http.Request) (*url.URL, error) {
// we wrap the default method, so we only need to perform our check if the NO_PROXY (or no_proxy) envvar has a CIDR in it
noProxyEnv := os.Getenv("NO_PROXY")
if noProxyEnv == "" {
noProxyEnv = os.Getenv("no_proxy")
}
noProxyRules := strings.Split(noProxyEnv, ",")
cidrs := []*net.IPNet{}
for _, noProxyRule := range noProxyRules {
_, cidr, _ := netutils.ParseCIDRSloppy(noProxyRule)
if cidr != nil {
cidrs = append(cidrs, cidr)
}
}
if len(cidrs) == 0 {
return delegate
}
return func(req *http.Request) (*url.URL, error) {
ip := netutils.ParseIPSloppy(req.URL.Hostname())
if ip == nil {
return delegate(req)
}
for _, cidr := range cidrs {
if cidr.Contains(ip) {
return nil, nil
}
}
return delegate(req)
}
} | NewProxierWithNoProxyCIDR constructs a Proxier function that respects CIDRs in NO_PROXY and delegates if
no matching CIDRs are found | NewProxierWithNoProxyCIDR | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func CloneRequest(req *http.Request) *http.Request {
r := new(http.Request)
// shallow clone
*r = *req
// deep copy headers
r.Header = CloneHeader(req.Header)
return r
} | CloneRequest creates a shallow copy of the request along with a deep copy of the Headers. | CloneRequest | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func CloneHeader(in http.Header) http.Header {
out := make(http.Header, len(in))
for key, values := range in {
newValues := make([]string, len(values))
copy(newValues, values)
out[key] = newValues
}
return out
} | CloneHeader creates a deep copy of an http.Header. | CloneHeader | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func ParseWarningHeaders(headers []string) ([]WarningHeader, []error) {
var (
results []WarningHeader
errs []error
)
for _, header := range headers {
for len(header) > 0 {
result, remainder, err := ParseWarningHeader(header)
if err != nil {
errs = append(errs, err)
break
}
results = append(results, result)
header = remainder
}
}
return results, errs
} | ParseWarningHeaders extract RFC2616 14.46 warnings headers from the specified set of header values.
Multiple comma-separated warnings per header are supported.
If errors are encountered on a header, the remainder of that header are skipped and subsequent headers are parsed.
Returns successfully parsed warnings and any errors encountered. | ParseWarningHeaders | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func ParseWarningHeader(header string) (result WarningHeader, remainder string, err error) {
// https://tools.ietf.org/html/rfc2616#section-14.46
// updated by
// https://tools.ietf.org/html/rfc7234#section-5.5
// https://tools.ietf.org/html/rfc7234#appendix-A
// Some requirements regarding production and processing of the Warning
// header fields have been relaxed, as it is not widely implemented.
// Furthermore, the Warning header field no longer uses RFC 2047
// encoding, nor does it allow multiple languages, as these aspects were
// not implemented.
//
// Format is one of:
// warn-code warn-agent "warn-text"
// warn-code warn-agent "warn-text" "warn-date"
//
// warn-code is a three digit number
// warn-agent is unquoted and contains no spaces
// warn-text is quoted with backslash escaping (RFC2047-encoded according to RFC2616, not encoded according to RFC7234)
// warn-date is optional, quoted, and in HTTP-date format (no embedded or escaped quotes)
//
// additional warnings can optionally be included in the same header by comma-separating them:
// warn-code warn-agent "warn-text" "warn-date"[, warn-code warn-agent "warn-text" "warn-date", ...]
// tolerate leading whitespace
header = strings.TrimSpace(header)
parts := strings.SplitN(header, " ", 3)
if len(parts) != 3 {
return WarningHeader{}, "", errors.New("invalid warning header: fewer than 3 segments")
}
code, agent, textDateRemainder := parts[0], parts[1], parts[2]
// verify code format
if !codeMatcher.Match([]byte(code)) {
return WarningHeader{}, "", errors.New("invalid warning header: code segment is not 3 digits between 100-299")
}
codeInt, _ := strconv.ParseInt(code, 10, 64)
// verify agent presence
if len(agent) == 0 {
return WarningHeader{}, "", errors.New("invalid warning header: empty agent segment")
}
if !utf8.ValidString(agent) || hasAnyRunes(agent, unicode.IsControl) {
return WarningHeader{}, "", errors.New("invalid warning header: invalid agent")
}
// verify textDateRemainder presence
if len(textDateRemainder) == 0 {
return WarningHeader{}, "", errors.New("invalid warning header: empty text segment")
}
// extract text
text, dateAndRemainder, err := parseQuotedString(textDateRemainder)
if err != nil {
return WarningHeader{}, "", fmt.Errorf("invalid warning header: %v", err)
}
// tolerate RFC2047-encoded text from warnings produced according to RFC2616
if decodedText, err := wordDecoder.DecodeHeader(text); err == nil {
text = decodedText
}
if !utf8.ValidString(text) || hasAnyRunes(text, unicode.IsControl) {
return WarningHeader{}, "", errors.New("invalid warning header: invalid text")
}
result = WarningHeader{Code: int(codeInt), Agent: agent, Text: text}
if len(dateAndRemainder) > 0 {
if dateAndRemainder[0] == '"' {
// consume date
foundEndQuote := false
for i := 1; i < len(dateAndRemainder); i++ {
if dateAndRemainder[i] == '"' {
foundEndQuote = true
remainder = strings.TrimSpace(dateAndRemainder[i+1:])
break
}
}
if !foundEndQuote {
return WarningHeader{}, "", errors.New("invalid warning header: unterminated date segment")
}
} else {
remainder = dateAndRemainder
}
}
if len(remainder) > 0 {
if remainder[0] == ',' {
// consume comma if present
remainder = strings.TrimSpace(remainder[1:])
} else {
return WarningHeader{}, "", errors.New("invalid warning header: unexpected token after warn-date")
}
}
return result, remainder, nil
} | ParseWarningHeader extracts one RFC2616 14.46 warning from the specified header,
returning an error if the header does not contain a correctly formatted warning.
Any remaining content in the header is returned. | ParseWarningHeader | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/http.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/http.go | Apache-2.0 |
func SplitSchemeNamePort(id string) (scheme, name, port string, valid bool) {
parts := strings.Split(id, ":")
switch len(parts) {
case 1:
name = parts[0]
case 2:
name = parts[0]
port = parts[1]
case 3:
scheme = parts[0]
name = parts[1]
port = parts[2]
default:
return "", "", "", false
}
if len(name) > 0 && validSchemes.Has(scheme) {
return scheme, name, port, true
} else {
return "", "", "", false
}
} | SplitSchemeNamePort takes a string of the following forms:
- "<name>", returns "", "<name>","", true
- "<name>:<port>", returns "", "<name>","<port>",true
- "<scheme>:<name>:<port>", returns "<scheme>","<name>","<port>",true
Name must be non-empty or valid will be returned false.
Scheme must be "http" or "https" if specified
Port is returned as a string, and it is not required to be numeric (could be
used for a named port, for example). | SplitSchemeNamePort | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/port_split.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/port_split.go | Apache-2.0 |
func JoinSchemeNamePort(scheme, name, port string) string {
if len(scheme) > 0 {
// Must include three segments to specify scheme
return scheme + ":" + name + ":" + port
}
if len(port) > 0 {
// Must include two segments to specify port
return name + ":" + port
}
// Return name alone
return name
} | JoinSchemeNamePort returns a string that specifies the scheme, name, and port:
- "<name>"
- "<name>:<port>"
- "<scheme>:<name>:<port>"
None of the parameters may contain a ':' character
Name is required
Scheme must be "", "http", or "https" | JoinSchemeNamePort | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/port_split.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/port_split.go | Apache-2.0 |
func IsNoRoutesError(err error) bool {
if err == nil {
return false
}
switch err.(type) {
case noRoutesError:
return true
default:
return false
} | IsNoRoutesError checks if an error is of type noRoutesError | IsNoRoutesError | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/interface.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/interface.go | Apache-2.0 |
func (pr *PortRange) Contains(p int) bool {
return (p >= pr.Base) && ((p - pr.Base) < pr.Size)
} | Contains tests whether a given port falls within the PortRange. | Contains | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | Apache-2.0 |
func (pr PortRange) String() string {
if pr.Size == 0 {
return ""
}
return fmt.Sprintf("%d-%d", pr.Base, pr.Base+pr.Size-1)
} | String converts the PortRange to a string representation, which can be
parsed by PortRange.Set or ParsePortRange. | String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | Apache-2.0 |
func (pr *PortRange) Set(value string) error {
const (
SinglePortNotation = 1 << iota
HyphenNotation
PlusNotation
)
value = strings.TrimSpace(value)
hyphenIndex := strings.Index(value, "-")
plusIndex := strings.Index(value, "+")
if value == "" {
pr.Base = 0
pr.Size = 0
return nil
}
var err error
var low, high int
var notation int
if plusIndex == -1 && hyphenIndex == -1 {
notation |= SinglePortNotation
}
if hyphenIndex != -1 {
notation |= HyphenNotation
}
if plusIndex != -1 {
notation |= PlusNotation
}
switch notation {
case SinglePortNotation:
var port int
port, err = strconv.Atoi(value)
if err != nil {
return err
}
low = port
high = port
case HyphenNotation:
low, err = strconv.Atoi(value[:hyphenIndex])
if err != nil {
return err
}
high, err = strconv.Atoi(value[hyphenIndex+1:])
if err != nil {
return err
}
case PlusNotation:
var offset int
low, err = strconv.Atoi(value[:plusIndex])
if err != nil {
return err
}
offset, err = strconv.Atoi(value[plusIndex+1:])
if err != nil {
return err
}
high = low + offset
default:
return fmt.Errorf("unable to parse port range: %s", value)
}
if low > 65535 || high > 65535 {
return fmt.Errorf("the port range cannot be greater than 65535: %s", value)
}
if high < low {
return fmt.Errorf("end port cannot be less than start port: %s", value)
}
pr.Base = low
pr.Size = 1 + high - low
return nil
} | Set parses a string of the form "value", "min-max", or "min+offset", inclusive at both ends, and
sets the PortRange from it. This is part of the flag.Value and pflag.Value
interfaces. | Set | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | Apache-2.0 |
func (*PortRange) Type() string {
return "portRange"
} | Type returns a descriptive string about this type. This is part of the
pflag.Value interface. | Type | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | Apache-2.0 |
func ParsePortRange(value string) (*PortRange, error) {
pr := &PortRange{}
err := pr.Set(value)
if err != nil {
return nil, err
}
return pr, nil
} | ParsePortRange parses a string of the form "min-max", inclusive at both
ends, and initializes a new PortRange from it. | ParsePortRange | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/port_range.go | Apache-2.0 |
func IPNetEqual(ipnet1, ipnet2 *net.IPNet) bool {
if ipnet1 == nil || ipnet2 == nil {
return false
}
if reflect.DeepEqual(ipnet1.Mask, ipnet2.Mask) && ipnet1.Contains(ipnet2.IP) && ipnet2.Contains(ipnet1.IP) {
return true
}
return false
} | IPNetEqual checks if the two input IPNets are representing the same subnet.
For example,
10.0.0.1/24 and 10.0.0.0/24 are the same subnet.
10.0.0.1/24 and 10.0.0.0/25 are not the same subnet. | IPNetEqual | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/util.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/util.go | Apache-2.0 |
func IsConnectionReset(err error) bool {
var errno syscall.Errno
if errors.As(err, &errno) {
return errno == syscall.ECONNRESET
}
return false
} | Returns if the given err is "connection reset by peer" error. | IsConnectionReset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/util.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/util.go | Apache-2.0 |
func IsHTTP2ConnectionLost(err error) bool {
return err != nil && strings.Contains(err.Error(), "http2: client connection lost")
} | Returns if the given err is "http2: client connection lost" error. | IsHTTP2ConnectionLost | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/util.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/util.go | Apache-2.0 |
func IsConnectionRefused(err error) bool {
var errno syscall.Errno
if errors.As(err, &errno) {
return errno == syscall.ECONNREFUSED
}
return false
} | Returns if the given err is "connection refused" error | IsConnectionRefused | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/net/util.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/net/util.go | Apache-2.0 |
func Pretty(a interface{}) string {
return prettyPrintConfig.Sdump(a)
} | Pretty wrap the spew.Sdump with Indent, and disabled methods like error() and String()
The output may change over time, so for guaranteed output please take more direct control | Pretty | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/dump/dump.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/dump/dump.go | Apache-2.0 |
func ForHash(a interface{}) string {
return prettyPrintConfigForHash.Sprintf("%#v", a)
} | ForHash keeps the original Spew.Sprintf format to ensure the same checksum | ForHash | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/dump/dump.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/dump/dump.go | Apache-2.0 |
func OneLine(a interface{}) string {
return prettyPrintConfig.Sprintf("%#v", a)
} | OneLine outputs the object in one line | OneLine | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/dump/dump.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/dump/dump.go | Apache-2.0 |
func (b *Backoff) Step() time.Duration {
if b == nil {
return 0
}
var nextDuration time.Duration
nextDuration, b.Duration, b.Steps = delay(b.Steps, b.Duration, b.Cap, b.Factor, b.Jitter)
return nextDuration
} | Step returns an amount of time to sleep determined by the original
Duration and Jitter. The backoff is mutated to update its Steps and
Duration. A nil Backoff always has a zero-duration step. | Step | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func (b Backoff) DelayFunc() DelayFunc {
steps := b.Steps
duration := b.Duration
cap := b.Cap
factor := b.Factor
jitter := b.Jitter
return func() time.Duration {
var nextDuration time.Duration
// jitter is applied per step and is not cumulative over multiple steps
nextDuration, duration, steps = delay(steps, duration, cap, factor, jitter)
return nextDuration
}
} | DelayFunc returns a function that will compute the next interval to
wait given the arguments in b. It does not mutate the original backoff
but the function is safe to use only from a single goroutine. | DelayFunc | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func (b Backoff) Timer() Timer {
if b.Steps > 1 || b.Jitter != 0 {
return &variableTimer{new: internalClock.NewTimer, fn: b.DelayFunc()}
}
if b.Duration > 0 {
return &fixedTimer{new: internalClock.NewTicker, interval: b.Duration}
}
return newNoopTimer()
} | Timer returns a timer implementation appropriate to this backoff's parameters
for use with wait functions. | Timer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func delay(steps int, duration, cap time.Duration, factor, jitter float64) (_ time.Duration, next time.Duration, nextSteps int) {
// when steps is non-positive, do not alter the base duration
if steps < 1 {
if jitter > 0 {
return Jitter(duration, jitter), duration, 0
}
return duration, duration, 0
}
steps--
// calculate the next step's interval
if factor != 0 {
next = time.Duration(float64(duration) * factor)
if cap > 0 && next > cap {
next = cap
steps = 0
}
} else {
next = duration
}
// add jitter for this step
if jitter > 0 {
duration = Jitter(duration, jitter)
}
return duration, next, steps
} | delay implements the core delay algorithm used in this package. | delay | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func (b Backoff) DelayWithReset(c clock.Clock, resetInterval time.Duration) DelayFunc {
if b.Factor <= 0 {
return b.DelayFunc()
}
if resetInterval <= 0 {
b.Steps = 0
b.Factor = 0
return b.DelayFunc()
}
return (&backoffManager{
backoff: b,
initialBackoff: b,
resetInterval: resetInterval,
clock: c,
lastStart: c.Now(),
timer: nil,
}).Step
} | DelayWithReset returns a DelayFunc that will return the appropriate next interval to
wait. Every resetInterval the backoff parameters are reset to their initial state.
This method is safe to invoke from multiple goroutines, but all calls will advance
the backoff state when Factor is set. If Factor is zero, this method is the same as
invoking b.DelayFunc() since Steps has no impact without Factor. If resetInterval is
zero no backoff will be performed as the same calling DelayFunc with a zero factor
and steps. | DelayWithReset | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func Until(f func(), period time.Duration, stopCh <-chan struct{}) {
JitterUntil(f, period, 0.0, true, stopCh)
} | Until loops until stop channel is closed, running f every period.
Until is syntactic sugar on top of JitterUntil with zero jitter factor and
with sliding = true (which means the timer for period starts after the f
completes). | Until | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func UntilWithContext(ctx context.Context, f func(context.Context), period time.Duration) {
JitterUntilWithContext(ctx, f, period, 0.0, true)
} | UntilWithContext loops until context is done, running f every period.
UntilWithContext is syntactic sugar on top of JitterUntilWithContext
with zero jitter factor and with sliding = true (which means the timer
for period starts after the f completes). | UntilWithContext | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func NonSlidingUntil(f func(), period time.Duration, stopCh <-chan struct{}) {
JitterUntil(f, period, 0.0, false, stopCh)
} | NonSlidingUntil loops until stop channel is closed, running f every
period.
NonSlidingUntil is syntactic sugar on top of JitterUntil with zero jitter
factor, with sliding = false (meaning the timer for period starts at the same
time as the function starts). | NonSlidingUntil | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func NonSlidingUntilWithContext(ctx context.Context, f func(context.Context), period time.Duration) {
JitterUntilWithContext(ctx, f, period, 0.0, false)
} | NonSlidingUntilWithContext loops until context is done, running f every
period.
NonSlidingUntilWithContext is syntactic sugar on top of JitterUntilWithContext
with zero jitter factor, with sliding = false (meaning the timer for period
starts at the same time as the function starts). | NonSlidingUntilWithContext | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, stopCh <-chan struct{}) {
BackoffUntil(f, NewJitteredBackoffManager(period, jitterFactor, &clock.RealClock{}), sliding, stopCh)
} | JitterUntil loops until stop channel is closed, running f every period.
If jitterFactor is positive, the period is jittered before every run of f.
If jitterFactor is not positive, the period is unchanged and not jittered.
If sliding is true, the period is computed after f runs. If it is false then
period includes the runtime for f.
Close stopCh to stop. f may not be invoked if stop channel is already
closed. Pass NeverStop to if you don't want it stop. | JitterUntil | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func BackoffUntil(f func(), backoff BackoffManager, sliding bool, stopCh <-chan struct{}) {
var t clock.Timer
for {
select {
case <-stopCh:
return
default:
}
if !sliding {
t = backoff.Backoff()
}
func() {
defer runtime.HandleCrash()
f()
}()
if sliding {
t = backoff.Backoff()
}
// NOTE: b/c there is no priority selection in golang
// it is possible for this to race, meaning we could
// trigger t.C and stopCh, and t.C select falls through.
// In order to mitigate we re-check stopCh at the beginning
// of every loop to prevent extra executions of f().
select {
case <-stopCh:
if !t.Stop() {
<-t.C()
}
return
case <-t.C():
}
}
} | BackoffUntil loops until stop channel is closed, run f every duration given by BackoffManager.
If sliding is true, the period is computed after f runs. If it is false then
period includes the runtime for f. | BackoffUntil | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
func JitterUntilWithContext(ctx context.Context, f func(context.Context), period time.Duration, jitterFactor float64, sliding bool) {
JitterUntil(func() { f(ctx) }, period, jitterFactor, sliding, ctx.Done())
} | JitterUntilWithContext loops until context is done, running f every period.
If jitterFactor is positive, the period is jittered before every run of f.
If jitterFactor is not positive, the period is unchanged and not jittered.
If sliding is true, the period is computed after f runs. If it is false then
period includes the runtime for f.
Cancel context to stop. f may not be invoked if context is already expired. | JitterUntilWithContext | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/wait/backoff.go | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.