host-local: allow ip request via CNI_ARGS
A specific IP can now be requested via the environment variable CNI_ARGS, e.g. `CNI_ARGS=ip=1.2.3.4`. The plugin will try to reserve the specified IP. If this is not successful the execution will fail.
This commit is contained in:
@ -32,6 +32,11 @@ type IPAMConfig struct {
|
||||
Subnet ip.IPNet `json:"subnet"`
|
||||
Gateway net.IP `json:"gateway"`
|
||||
Routes []plugin.Route `json:"routes"`
|
||||
Args *IPAMArgs `json:"-"`
|
||||
}
|
||||
|
||||
type IPAMArgs struct {
|
||||
IP net.IP `json:"ip",omitempty`
|
||||
}
|
||||
|
||||
type Net struct {
|
||||
@ -40,12 +45,20 @@ type Net struct {
|
||||
}
|
||||
|
||||
// NewIPAMConfig creates a NetworkConfig from the given network name.
|
||||
func LoadIPAMConfig(bytes []byte) (*IPAMConfig, error) {
|
||||
func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, error) {
|
||||
n := Net{}
|
||||
if err := json.Unmarshal(bytes, &n); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if args != "" {
|
||||
ipamArgs := IPAMArgs{}
|
||||
err := plugin.LoadArgs(args, &ipamArgs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if n.IPAM == nil {
|
||||
return nil, fmt.Errorf("%q missing 'ipam' key")
|
||||
}
|
||||
|
Reference in New Issue
Block a user