diff --git a/cmd/ipam-node/main.go b/cmd/ipam-node/main.go index b187e6f..1a000e9 100644 --- a/cmd/ipam-node/main.go +++ b/cmd/ipam-node/main.go @@ -31,6 +31,9 @@ import ( // Options stores command line options type Options struct { + CNIBinDir string + NvIpamCNIBinFile string + SkipNvIpamCNIBinaryCopy bool NvIpamCNIDataDir string NvIpamCNIDataDirHost string CNIConfDir string @@ -51,6 +54,10 @@ func (o *Options) addFlags() { // suppress error message for help pflag.ErrHelp = nil //nolint:golint,reassign fs := pflag.CommandLine + fs.StringVar(&o.CNIBinDir, + "cni-bin-dir", "/host/opt/cni/bin", "CNI binary directory") + fs.StringVar(&o.NvIpamCNIBinFile, + "nv-ipam-bin-file", "/nv-ipam", "nv-ipam binary file path") fs.StringVar(&o.NvIpamCNIDataDir, "nv-ipam-cni-data-dir", "/host/var/lib/cni/nv-ipam", "nv-ipam CNI data directory") fs.StringVar(&o.NvIpamCNIDataDirHost, @@ -73,6 +80,11 @@ func (o *Options) addFlags() { } func (o *Options) verifyFileExists() error { + // CNIBinDir + if _, err := os.Stat(o.CNIBinDir); err != nil { + return fmt.Errorf("cni-bin-dir is not found: %v", err) + } + // CNIConfDir if _, err := os.Stat(o.CNIConfDir); err != nil { return fmt.Errorf("cni-conf-dir is not found: %v", err) @@ -285,6 +297,15 @@ func main() { return } + // copy nv-ipam binary + if !opt.SkipNvIpamCNIBinaryCopy { + // Copy + if err = cmdutils.CopyFileAtomic(opt.NvIpamCNIBinFile, opt.CNIBinDir, "_nv-ipam", "nv-ipam"); err != nil { + log.Printf("failed at nv-ipam copy: %v\n", err) + return + } + } + // copy host-local binary if !opt.SkipHostLocalBinaryCopy { // Copy diff --git a/deploy/nv-ipam-node.yaml b/deploy/nv-ipam-node.yaml index 194ceb4..8de5129 100644 --- a/deploy/nv-ipam-node.yaml +++ b/deploy/nv-ipam-node.yaml @@ -79,6 +79,8 @@ spec: securityContext: privileged: true volumeMounts: + - name: cnibin + mountPath: /host/opt/cni/bin - name: cni mountPath: /host/etc/cni/net.d - name: hostlocalcnibin @@ -87,6 +89,10 @@ spec: mountPath: /host/var/lib/cni/nv-ipam/state/host-local terminationGracePeriodSeconds: 10 volumes: + - name: cnibin + hostPath: + path: /opt/cni/bin + type: DirectoryOrCreate - name: cni hostPath: path: /etc/cni/net.d