mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
rebase: update kubernetes to 1.26.1
update kubernetes and its dependencies to v1.26.1 Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
e9e33fb851
commit
9c8de9471e
181
vendor/k8s.io/utils/net/ipfamily.go
generated
vendored
Normal file
181
vendor/k8s.io/utils/net/ipfamily.go
generated
vendored
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package net
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
// IPFamily refers to a specific family if not empty, i.e. "4" or "6".
|
||||
type IPFamily string
|
||||
|
||||
// Constants for valid IPFamilys:
|
||||
const (
|
||||
IPFamilyUnknown IPFamily = ""
|
||||
|
||||
IPv4 IPFamily = "4"
|
||||
IPv6 IPFamily = "6"
|
||||
)
|
||||
|
||||
// IsDualStackIPs returns true if:
|
||||
// - all elements of ips are valid
|
||||
// - at least one IP from each family (v4 and v6) is present
|
||||
func IsDualStackIPs(ips []net.IP) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for i, ip := range ips {
|
||||
switch IPFamilyOf(ip) {
|
||||
case IPv4:
|
||||
v4Found = true
|
||||
case IPv6:
|
||||
v6Found = true
|
||||
default:
|
||||
return false, fmt.Errorf("invalid IP[%d]: %v", i, ip)
|
||||
}
|
||||
}
|
||||
|
||||
return (v4Found && v6Found), nil
|
||||
}
|
||||
|
||||
// IsDualStackIPStrings returns true if:
|
||||
// - all elements of ips can be parsed as IPs
|
||||
// - at least one IP from each family (v4 and v6) is present
|
||||
func IsDualStackIPStrings(ips []string) (bool, error) {
|
||||
parsedIPs := make([]net.IP, 0, len(ips))
|
||||
for i, ip := range ips {
|
||||
parsedIP := ParseIPSloppy(ip)
|
||||
if parsedIP == nil {
|
||||
return false, fmt.Errorf("invalid IP[%d]: %v", i, ip)
|
||||
}
|
||||
parsedIPs = append(parsedIPs, parsedIP)
|
||||
}
|
||||
return IsDualStackIPs(parsedIPs)
|
||||
}
|
||||
|
||||
// IsDualStackCIDRs returns true if:
|
||||
// - all elements of cidrs are non-nil
|
||||
// - at least one CIDR from each family (v4 and v6) is present
|
||||
func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for i, cidr := range cidrs {
|
||||
switch IPFamilyOfCIDR(cidr) {
|
||||
case IPv4:
|
||||
v4Found = true
|
||||
case IPv6:
|
||||
v6Found = true
|
||||
default:
|
||||
return false, fmt.Errorf("invalid CIDR[%d]: %v", i, cidr)
|
||||
}
|
||||
}
|
||||
|
||||
return (v4Found && v6Found), nil
|
||||
}
|
||||
|
||||
// IsDualStackCIDRStrings returns if
|
||||
// - all elements of cidrs can be parsed as CIDRs
|
||||
// - at least one CIDR from each family (v4 and v6) is present
|
||||
func IsDualStackCIDRStrings(cidrs []string) (bool, error) {
|
||||
parsedCIDRs, err := ParseCIDRs(cidrs)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return IsDualStackCIDRs(parsedCIDRs)
|
||||
}
|
||||
|
||||
// IPFamilyOf returns the IP family of ip, or IPFamilyUnknown if it is invalid.
|
||||
func IPFamilyOf(ip net.IP) IPFamily {
|
||||
switch {
|
||||
case ip.To4() != nil:
|
||||
return IPv4
|
||||
case ip.To16() != nil:
|
||||
return IPv6
|
||||
default:
|
||||
return IPFamilyUnknown
|
||||
}
|
||||
}
|
||||
|
||||
// IPFamilyOfString returns the IP family of ip, or IPFamilyUnknown if ip cannot
|
||||
// be parsed as an IP.
|
||||
func IPFamilyOfString(ip string) IPFamily {
|
||||
return IPFamilyOf(ParseIPSloppy(ip))
|
||||
}
|
||||
|
||||
// IPFamilyOfCIDR returns the IP family of cidr.
|
||||
func IPFamilyOfCIDR(cidr *net.IPNet) IPFamily {
|
||||
if cidr == nil {
|
||||
return IPFamilyUnknown
|
||||
}
|
||||
return IPFamilyOf(cidr.IP)
|
||||
}
|
||||
|
||||
// IPFamilyOfCIDRString returns the IP family of cidr.
|
||||
func IPFamilyOfCIDRString(cidr string) IPFamily {
|
||||
ip, _, _ := ParseCIDRSloppy(cidr)
|
||||
return IPFamilyOf(ip)
|
||||
}
|
||||
|
||||
// IsIPv6 returns true if netIP is IPv6 (and false if it is IPv4, nil, or invalid).
|
||||
func IsIPv6(netIP net.IP) bool {
|
||||
return IPFamilyOf(netIP) == 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.
|
||||
func IsIPv6String(ip string) bool {
|
||||
return IPFamilyOfString(ip) == 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.
|
||||
func IsIPv6CIDR(cidr *net.IPNet) bool {
|
||||
return IPFamilyOfCIDR(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.
|
||||
func IsIPv6CIDRString(cidr string) bool {
|
||||
return IPFamilyOfCIDRString(cidr) == IPv6
|
||||
}
|
||||
|
||||
// IsIPv4 returns true if netIP is IPv4 (and false if it is IPv6, nil, or invalid).
|
||||
func IsIPv4(netIP net.IP) bool {
|
||||
return IPFamilyOf(netIP) == 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.
|
||||
func IsIPv4String(ip string) bool {
|
||||
return IPFamilyOfString(ip) == 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.
|
||||
func IsIPv4CIDR(cidr *net.IPNet) bool {
|
||||
return IPFamilyOfCIDR(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.
|
||||
func IsIPv4CIDRString(cidr string) bool {
|
||||
return IPFamilyOfCIDRString(cidr) == IPv4
|
||||
}
|
126
vendor/k8s.io/utils/net/net.go
generated
vendored
126
vendor/k8s.io/utils/net/net.go
generated
vendored
@ -29,138 +29,16 @@ import (
|
||||
// order is maintained
|
||||
func ParseCIDRs(cidrsString []string) ([]*net.IPNet, error) {
|
||||
cidrs := make([]*net.IPNet, 0, len(cidrsString))
|
||||
for _, cidrString := range cidrsString {
|
||||
for i, cidrString := range cidrsString {
|
||||
_, cidr, err := ParseCIDRSloppy(cidrString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse cidr value:%q with error:%v", cidrString, err)
|
||||
return nil, fmt.Errorf("invalid CIDR[%d]: %v (%v)", i, cidr, err)
|
||||
}
|
||||
cidrs = append(cidrs, cidr)
|
||||
}
|
||||
return cidrs, nil
|
||||
}
|
||||
|
||||
// IsDualStackIPs returns if a slice of ips is:
|
||||
// - all are valid ips
|
||||
// - at least one ip from each family (v4 or v6)
|
||||
func IsDualStackIPs(ips []net.IP) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for _, ip := range ips {
|
||||
if ip == nil {
|
||||
return false, fmt.Errorf("ip %v is invalid", ip)
|
||||
}
|
||||
|
||||
if v4Found && v6Found {
|
||||
continue
|
||||
}
|
||||
|
||||
if IsIPv6(ip) {
|
||||
v6Found = true
|
||||
continue
|
||||
}
|
||||
|
||||
v4Found = true
|
||||
}
|
||||
|
||||
return (v4Found && v6Found), nil
|
||||
}
|
||||
|
||||
// IsDualStackIPStrings returns if
|
||||
// - all are valid ips
|
||||
// - at least one ip from each family (v4 or v6)
|
||||
func IsDualStackIPStrings(ips []string) (bool, error) {
|
||||
parsedIPs := make([]net.IP, 0, len(ips))
|
||||
for _, ip := range ips {
|
||||
parsedIP := ParseIPSloppy(ip)
|
||||
parsedIPs = append(parsedIPs, parsedIP)
|
||||
}
|
||||
return IsDualStackIPs(parsedIPs)
|
||||
}
|
||||
|
||||
// IsDualStackCIDRs returns if
|
||||
// - all are valid cidrs
|
||||
// - at least one cidr from each family (v4 or v6)
|
||||
func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error) {
|
||||
v4Found := false
|
||||
v6Found := false
|
||||
for _, cidr := range cidrs {
|
||||
if cidr == nil {
|
||||
return false, fmt.Errorf("cidr %v is invalid", cidr)
|
||||
}
|
||||
|
||||
if v4Found && v6Found {
|
||||
continue
|
||||
}
|
||||
|
||||
if IsIPv6(cidr.IP) {
|
||||
v6Found = true
|
||||
continue
|
||||
}
|
||||
v4Found = true
|
||||
}
|
||||
|
||||
return v4Found && v6Found, nil
|
||||
}
|
||||
|
||||
// IsDualStackCIDRStrings returns if
|
||||
// - all are valid cidrs
|
||||
// - at least one cidr from each family (v4 or v6)
|
||||
func IsDualStackCIDRStrings(cidrs []string) (bool, error) {
|
||||
parsedCIDRs, err := ParseCIDRs(cidrs)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return IsDualStackCIDRs(parsedCIDRs)
|
||||
}
|
||||
|
||||
// IsIPv6 returns if netIP is IPv6.
|
||||
func IsIPv6(netIP net.IP) bool {
|
||||
return netIP != nil && netIP.To4() == nil
|
||||
}
|
||||
|
||||
// IsIPv6String returns if ip is IPv6.
|
||||
func IsIPv6String(ip string) bool {
|
||||
netIP := ParseIPSloppy(ip)
|
||||
return IsIPv6(netIP)
|
||||
}
|
||||
|
||||
// IsIPv6CIDRString returns if cidr is IPv6.
|
||||
// This assumes cidr is a valid CIDR.
|
||||
func IsIPv6CIDRString(cidr string) bool {
|
||||
ip, _, _ := ParseCIDRSloppy(cidr)
|
||||
return IsIPv6(ip)
|
||||
}
|
||||
|
||||
// IsIPv6CIDR returns if a cidr is ipv6
|
||||
func IsIPv6CIDR(cidr *net.IPNet) bool {
|
||||
ip := cidr.IP
|
||||
return IsIPv6(ip)
|
||||
}
|
||||
|
||||
// IsIPv4 returns if netIP is IPv4.
|
||||
func IsIPv4(netIP net.IP) bool {
|
||||
return netIP != nil && netIP.To4() != nil
|
||||
}
|
||||
|
||||
// IsIPv4String returns if ip is IPv4.
|
||||
func IsIPv4String(ip string) bool {
|
||||
netIP := ParseIPSloppy(ip)
|
||||
return IsIPv4(netIP)
|
||||
}
|
||||
|
||||
// IsIPv4CIDR returns if a cidr is ipv4
|
||||
func IsIPv4CIDR(cidr *net.IPNet) bool {
|
||||
ip := cidr.IP
|
||||
return IsIPv4(ip)
|
||||
}
|
||||
|
||||
// IsIPv4CIDRString returns if cidr is IPv4.
|
||||
// This assumes cidr is a valid CIDR.
|
||||
func IsIPv4CIDRString(cidr string) bool {
|
||||
ip, _, _ := ParseCIDRSloppy(cidr)
|
||||
return IsIPv4(ip)
|
||||
}
|
||||
|
||||
// ParsePort parses a string representing an IP port. If the string is not a
|
||||
// valid port number, this returns an error.
|
||||
func ParsePort(port string, allowZero bool) (int, error) {
|
||||
|
18
vendor/k8s.io/utils/net/port.go
generated
vendored
18
vendor/k8s.io/utils/net/port.go
generated
vendored
@ -23,15 +23,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// IPFamily refers to a specific family if not empty, i.e. "4" or "6".
|
||||
type IPFamily string
|
||||
|
||||
// Constants for valid IPFamilys:
|
||||
const (
|
||||
IPv4 IPFamily = "4"
|
||||
IPv6 IPFamily = "6"
|
||||
)
|
||||
|
||||
// Protocol is a network protocol support by LocalPort.
|
||||
type Protocol string
|
||||
|
||||
@ -67,7 +58,7 @@ func NewLocalPort(desc, ip string, ipFamily IPFamily, port int, protocol Protoco
|
||||
if protocol != TCP && protocol != UDP {
|
||||
return nil, fmt.Errorf("Unsupported protocol %s", protocol)
|
||||
}
|
||||
if ipFamily != "" && ipFamily != "4" && ipFamily != "6" {
|
||||
if ipFamily != IPFamilyUnknown && ipFamily != IPv4 && ipFamily != IPv6 {
|
||||
return nil, fmt.Errorf("Invalid IP family %s", ipFamily)
|
||||
}
|
||||
if ip != "" {
|
||||
@ -75,9 +66,10 @@ func NewLocalPort(desc, ip string, ipFamily IPFamily, port int, protocol Protoco
|
||||
if parsedIP == nil {
|
||||
return nil, fmt.Errorf("invalid ip address %s", ip)
|
||||
}
|
||||
asIPv4 := parsedIP.To4()
|
||||
if asIPv4 == nil && ipFamily == IPv4 || asIPv4 != nil && ipFamily == IPv6 {
|
||||
return nil, fmt.Errorf("ip address and family mismatch %s, %s", ip, ipFamily)
|
||||
if ipFamily != IPFamilyUnknown {
|
||||
if IPFamily(parsedIP) != ipFamily {
|
||||
return nil, fmt.Errorf("ip address and family mismatch %s, %s", ip, ipFamily)
|
||||
}
|
||||
}
|
||||
}
|
||||
return &LocalPort{Description: desc, IP: ip, IPFamily: ipFamily, Port: port, Protocol: protocol}, nil
|
||||
|
Reference in New Issue
Block a user