Skip to content

Commit

Permalink
fix: setdir in CNI client (#2027)
Browse files Browse the repository at this point in the history
so invoking from inside the CNS Pod works on Windows

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
  • Loading branch information
rbtr committed Jun 22, 2023
1 parent 9a410fc commit 0822d0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 2 additions & 8 deletions cni/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions cni/client/const_linux.go
Original file line number Diff line number Diff line change
@@ -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 = ""
6 changes: 6 additions & 0 deletions cni/client/const_windows.go
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 0822d0c

Please sign in to comment.