diff --git a/cni/client/client.go b/cni/client/client.go index d78aa8790b..69e1bf4196 100644 --- a/cni/client/client.go +++ b/cni/client/client.go @@ -14,12 +14,6 @@ import ( utilexec "k8s.io/utils/exec" ) -type Client interface { - GetEndpointState() (*api.AzureCNIState, error) -} - -var _ (Client) = (*client)(nil) - type client struct { exec utilexec.Interface } @@ -30,7 +24,7 @@ func New(exec utilexec.Interface) *client { func (c *client) GetEndpointState() (*api.AzureCNIState, error) { cmd := c.exec.Command(platform.CNIBinaryPath) - + cmd.SetDir(CNIExecDir) envs := os.Environ() cmdenv := fmt.Sprintf("%s=%s", cni.Cmd, cni.CmdGetEndpointsState) log.Printf("Setting cmd to %s", cmdenv) @@ -52,7 +46,7 @@ func (c *client) GetEndpointState() (*api.AzureCNIState, error) { func (c *client) GetVersion() (*semver.Version, error) { cmd := c.exec.Command(platform.CNIBinaryPath, "-v") - + cmd.SetDir(CNIExecDir) output, err := cmd.CombinedOutput() if err != nil { return nil, fmt.Errorf("failed to get Azure CNI version with err: [%w], output: [%s]", err, string(output)) diff --git a/cni/client/const_linux.go b/cni/client/const_linux.go new file mode 100644 index 0000000000..518088eb11 --- /dev/null +++ b/cni/client/const_linux.go @@ -0,0 +1,7 @@ +package client + +// CNIExecDir is the working directory that the invoker must execute the CNI from +// in order for it to correctly map its state and lock files. +// Does not need to be set on Linux, as absolute paths are correctly used during +// the actual CNI execution. +const CNIExecDir = "" diff --git a/cni/client/const_windows.go b/cni/client/const_windows.go new file mode 100644 index 0000000000..4c3b352763 --- /dev/null +++ b/cni/client/const_windows.go @@ -0,0 +1,6 @@ +package client + +// CNIExecDir is the working directory that the invoker must execute the CNI from +// in order for it to correctly map its state and lock files. +// Only needs to be set on Windows. +const CNIExecDir = "C:\\k"