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)
|
||||
}
|
||||
|
||||
func getListener() (net.Listener, error) {
|
||||
func getListener(socketPath string) (net.Listener, error) {
|
||||
l, err := activation.Listeners()
|
||||
if err != nil {
|
||||
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,
|
||||
// ensure the RPC server does not get scheduled onto those
|
||||
runtime.LockOSThread()
|
||||
@ -166,7 +166,7 @@ func runDaemon(pidfilePath string, hostPrefix string) error {
|
||||
}
|
||||
}
|
||||
|
||||
l, err := getListener()
|
||||
l, err := getListener(socketPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting listener: %v", err)
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
@ -28,18 +29,24 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
)
|
||||
|
||||
const socketPath = "/run/cni/dhcp.sock"
|
||||
const defaultSocketPath = "/run/cni/defaultdhcp.sock"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) > 1 && os.Args[1] == "daemon" {
|
||||
var pidfilePath string
|
||||
var hostPrefix string
|
||||
var socketPath string
|
||||
daemonFlags := flag.NewFlagSet("daemon", flag.ExitOnError)
|
||||
daemonFlags.StringVar(&pidfilePath, "pidfile", "", "optional path to write daemon PID to")
|
||||
daemonFlags.StringVar(&hostPrefix, "hostprefix", "", "optional prefix to netns")
|
||||
daemonFlags.StringVar(&socketPath, "socketpath", "", "optional dhcp server socketpath")
|
||||
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())
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -78,7 +85,31 @@ func cmdGet(args *skel.CmdArgs) error {
|
||||
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 {
|
||||
socketPath, err := getSocketPath(args.StdinData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error obtaining socketPath: %v", err)
|
||||
}
|
||||
|
||||
client, err := rpc.DialHTTP("unix", socketPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error dialing DHCP daemon: %v", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user