Allow socket path used by dhcp plugin to be supplied via dhcp ipam configuration
Allow socket path to be supplied as flag when starting dhcp daemon
This commit is contained in:
parent
66837d6f3b
commit
6d3215a256
@ -127,7 +127,7 @@ func (d *DHCP) clearLease(contID, netName string) {
|
|||||||
delete(d.leases, contID+netName)
|
delete(d.leases, contID+netName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getListener() (net.Listener, error) {
|
func getListener(socketPath string) (net.Listener, error) {
|
||||||
l, err := activation.Listeners()
|
l, err := activation.Listeners()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -151,7 +151,7 @@ func getListener() (net.Listener, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDaemon(pidfilePath string, hostPrefix string) error {
|
func runDaemon(pidfilePath string, hostPrefix string, socketPath string) error {
|
||||||
// since other goroutines (on separate threads) will change namespaces,
|
// since other goroutines (on separate threads) will change namespaces,
|
||||||
// ensure the RPC server does not get scheduled onto those
|
// ensure the RPC server does not get scheduled onto those
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
@ -166,7 +166,7 @@ func runDaemon(pidfilePath string, hostPrefix string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := getListener()
|
l, err := getListener(socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error getting listener: %v", err)
|
return fmt.Errorf("Error getting listener: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -28,18 +29,24 @@ import (
|
|||||||
"github.com/containernetworking/cni/pkg/version"
|
"github.com/containernetworking/cni/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const socketPath = "/run/cni/dhcp.sock"
|
const defaultSocketPath = "/run/cni/defaultdhcp.sock"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) > 1 && os.Args[1] == "daemon" {
|
if len(os.Args) > 1 && os.Args[1] == "daemon" {
|
||||||
var pidfilePath string
|
var pidfilePath string
|
||||||
var hostPrefix string
|
var hostPrefix string
|
||||||
|
var socketPath string
|
||||||
daemonFlags := flag.NewFlagSet("daemon", flag.ExitOnError)
|
daemonFlags := flag.NewFlagSet("daemon", flag.ExitOnError)
|
||||||
daemonFlags.StringVar(&pidfilePath, "pidfile", "", "optional path to write daemon PID to")
|
daemonFlags.StringVar(&pidfilePath, "pidfile", "", "optional path to write daemon PID to")
|
||||||
daemonFlags.StringVar(&hostPrefix, "hostprefix", "", "optional prefix to netns")
|
daemonFlags.StringVar(&hostPrefix, "hostprefix", "", "optional prefix to netns")
|
||||||
|
daemonFlags.StringVar(&socketPath, "socketpath", "", "optional dhcp server socketpath")
|
||||||
daemonFlags.Parse(os.Args[2:])
|
daemonFlags.Parse(os.Args[2:])
|
||||||
|
|
||||||
if err := runDaemon(pidfilePath, hostPrefix); err != nil {
|
if socketPath == "" {
|
||||||
|
socketPath = defaultSocketPath
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := runDaemon(pidfilePath, hostPrefix, socketPath); err != nil {
|
||||||
log.Printf(err.Error())
|
log.Printf(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -78,7 +85,31 @@ func cmdGet(args *skel.CmdArgs) error {
|
|||||||
return fmt.Errorf("not implemented")
|
return fmt.Errorf("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SocketPathConf struct {
|
||||||
|
DaemonSocketPath string `json:"daemonSocketPath,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TempNetConf struct {
|
||||||
|
IPAM SocketPathConf `json:"ipam,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSocketPath(stdinData []byte) (string, error) {
|
||||||
|
conf := TempNetConf{}
|
||||||
|
if err := json.Unmarshal(stdinData, &conf); err != nil {
|
||||||
|
return "", fmt.Errorf("error parsing socket path conf: %v", err)
|
||||||
|
}
|
||||||
|
if conf.IPAM.DaemonSocketPath == "" {
|
||||||
|
return defaultSocketPath, nil
|
||||||
|
}
|
||||||
|
return conf.IPAM.DaemonSocketPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
func rpcCall(method string, args *skel.CmdArgs, result interface{}) error {
|
func rpcCall(method string, args *skel.CmdArgs, result interface{}) error {
|
||||||
|
socketPath, err := getSocketPath(args.StdinData)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error obtaining socketPath: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
client, err := rpc.DialHTTP("unix", socketPath)
|
client, err := rpc.DialHTTP("unix", socketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error dialing DHCP daemon: %v", err)
|
return fmt.Errorf("error dialing DHCP daemon: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user