vendor in latests containers/common

To include export HostContainersInternal

Signed-off-by: Black-Hole1 <bh@bugs.cc>
This commit is contained in:
Black-Hole1
2023-06-21 15:05:14 +08:00
parent a77f896bab
commit ae6e390760
21 changed files with 124 additions and 100 deletions

View File

@@ -15,7 +15,7 @@ import (
"github.com/sirupsen/logrus"
)
func (n *cniNetwork) NetworkUpdate(name string, options types.NetworkUpdateOptions) error {
func (n *cniNetwork) NetworkUpdate(_ string, _ types.NetworkUpdateOptions) error {
return fmt.Errorf("NetworkUpdate is not supported for backend CNI: %w", types.ErrInvalidArg)
}

View File

@@ -13,7 +13,7 @@ import (
)
const (
hostContainersInternal = "host.containers.internal"
HostContainersInternal = "host.containers.internal"
localhost = "localhost"
)
@@ -50,7 +50,7 @@ type Params struct {
// containerIps. The container ip entry is only added when the name was not already
// added before.
func New(params *Params) error {
if err := new(params); err != nil {
if err := newHost(params); err != nil {
return fmt.Errorf("failed to create new hosts file: %w", err)
}
return nil
@@ -97,7 +97,7 @@ func Remove(file string, entries HostEntries) error {
}
// new see comment on New()
func new(params *Params) error {
func newHost(params *Params) error {
entries, err := parseExtraHosts(params.ExtraHosts)
if err != nil {
return err
@@ -118,15 +118,12 @@ func new(params *Params) error {
l2 := HostEntry{IP: "::1", Names: lh}
containerIPs = append(containerIPs, l1, l2)
if params.HostContainersInternalIP != "" {
e := HostEntry{IP: params.HostContainersInternalIP, Names: []string{hostContainersInternal}}
e := HostEntry{IP: params.HostContainersInternalIP, Names: []string{HostContainersInternal}}
containerIPs = append(containerIPs, e)
}
containerIPs = append(containerIPs, params.ContainerIPs...)
if err := writeHostFile(params.TargetFile, entries, containerIPs); err != nil {
return err
}
return nil
return writeHostFile(params.TargetFile, entries, containerIPs)
}
// add see comment on Add()

View File

@@ -34,3 +34,21 @@ func ParseVlan(vlan string) (int, error) {
}
return v, nil
}
// ParseIsolate parses the isolate option
func ParseIsolate(isolate string) (string, error) {
switch isolate {
case "":
return "false", nil
case "strict":
return isolate, nil
default:
// isolate option accepts "strict" and Rust boolean values "true" or "false"
optIsolateBool, err := strconv.ParseBool(isolate)
if err != nil {
return "", fmt.Errorf("failed to parse isolate option: %w", err)
}
// Rust boolean only support "true" or "false" while go can parse 1 and 0 as well so we need to change it
return strconv.FormatBool(optIsolateBool), nil
}
}

View File

@@ -187,12 +187,11 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo
}
case types.IsolateOption:
val, err := strconv.ParseBool(value)
val, err := internalutil.ParseIsolate(value)
if err != nil {
return nil, err
}
// rust only support "true" or "false" while go can parse 1 and 0 as well so we need to change it
newNetwork.Options[types.IsolateOption] = strconv.FormatBool(val)
newNetwork.Options[types.IsolateOption] = val
case types.MetricOption:
_, err := strconv.ParseUint(value, 10, 32)
if err != nil {
@@ -244,7 +243,7 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo
return nil, err
}
//validate routes
// validate routes
err = internalutil.ValidateRoutes(newNetwork.Routes)
if err != nil {
return nil, err

View File

@@ -173,20 +173,23 @@ func getFreeIPFromBucket(bucket *bbolt.Bucket, subnet *types.Subnet) (net.IP, er
if rangeStart == nil {
// let start with the first ip in subnet
rangeStart = util.NextIP(subnet.Subnet.IP)
} else if util.Cmp(rangeStart, subnet.Subnet.IP) == 0 {
// when we start on the subnet ip we need to inc by one as the subnet ip cannot be assigned
rangeStart = util.NextIP(rangeStart)
}
lastIP, err := util.LastIPInSubnet(&subnet.Subnet.IPNet)
// this error should never happen but lets check anyways to prevent panics
if err != nil {
return nil, fmt.Errorf("failed to get lastIP: %w", err)
}
if rangeEnd == nil {
lastIP, err := util.LastIPInSubnet(&subnet.Subnet.IPNet)
// this error should never happen but lets check anyways to prevent panics
if err != nil {
return nil, fmt.Errorf("failed to get lastIP: %w", err)
}
// ipv4 uses the last ip in a subnet for broadcast so we cannot use it
if util.IsIPv4(lastIP) {
lastIP = util.PrevIP(lastIP)
}
rangeEnd = lastIP
}
// ipv4 uses the last ip in a subnet for broadcast so we cannot use it
if util.IsIPv4(rangeEnd) && util.Cmp(rangeEnd, lastIP) == 0 {
rangeEnd = util.PrevIP(rangeEnd)
}
lastIPByte := bucket.Get(lastIPKey)
curIP := net.IP(lastIPByte)