Skip to content

Commit 0822d0c

Browse files
authored
fix: setdir in CNI client (#2027)
so invoking from inside the CNS Pod works on Windows Signed-off-by: Evan Baker <[email protected]>
1 parent 9a410fc commit 0822d0c

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

cni/client/client.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ import (
1414
utilexec "k8s.io/utils/exec"
1515
)
1616

17-
type Client interface {
18-
GetEndpointState() (*api.AzureCNIState, error)
19-
}
20-
21-
var _ (Client) = (*client)(nil)
22-
2317
type client struct {
2418
exec utilexec.Interface
2519
}
@@ -30,7 +24,7 @@ func New(exec utilexec.Interface) *client {
3024

3125
func (c *client) GetEndpointState() (*api.AzureCNIState, error) {
3226
cmd := c.exec.Command(platform.CNIBinaryPath)
33-
27+
cmd.SetDir(CNIExecDir)
3428
envs := os.Environ()
3529
cmdenv := fmt.Sprintf("%s=%s", cni.Cmd, cni.CmdGetEndpointsState)
3630
log.Printf("Setting cmd to %s", cmdenv)
@@ -52,7 +46,7 @@ func (c *client) GetEndpointState() (*api.AzureCNIState, error) {
5246

5347
func (c *client) GetVersion() (*semver.Version, error) {
5448
cmd := c.exec.Command(platform.CNIBinaryPath, "-v")
55-
49+
cmd.SetDir(CNIExecDir)
5650
output, err := cmd.CombinedOutput()
5751
if err != nil {
5852
return nil, fmt.Errorf("failed to get Azure CNI version with err: [%w], output: [%s]", err, string(output))

cni/client/const_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package client
2+
3+
// CNIExecDir is the working directory that the invoker must execute the CNI from
4+
// in order for it to correctly map its state and lock files.
5+
// Does not need to be set on Linux, as absolute paths are correctly used during
6+
// the actual CNI execution.
7+
const CNIExecDir = ""

cni/client/const_windows.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package client
2+
3+
// CNIExecDir is the working directory that the invoker must execute the CNI from
4+
// in order for it to correctly map its state and lock files.
5+
// Only needs to be set on Windows.
6+
const CNIExecDir = "C:\\k"

0 commit comments

Comments
 (0)