Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ vet: ## Run go vet against code.
go vet ./...

build: generate fmt vet manifests ## Build manager binary.
go build -o bin/agent-sandbox-controller cmd/agent-sandbox-controller/main.go
go build -o bin/agent-sandbox-controller ./cmd/agent-sandbox-controller

.PHONY: build-okactl
build-okactl: ## Build okactl CLI binary.
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent-runtime/storage-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func runMount(cmd *cobra.Command) error {
return fmt.Errorf("failed to decode CSI request config: %w", err)
}

csiReq := csi.NodePublishVolumeRequest{}
if err := proto.Unmarshal(configRaw, &csiReq); err != nil {
csiReq := &csi.NodePublishVolumeRequest{}
if err := proto.Unmarshal(configRaw, csiReq); err != nil {
cmd.Help() // #nosec G104 -- help output error is non-actionable
return fmt.Errorf("failed to unmarshal CSI request: %w", err)
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func main() {
}
}

func validateGeneralParams(csiReq csi.NodePublishVolumeRequest) error {
func validateGeneralParams(csiReq *csi.NodePublishVolumeRequest) error {
if strings.TrimSpace(csiReq.VolumeContext["csi.storage.k8s.io/pod.uid"]) == "" {
return fmt.Errorf("Pod UID is required. Use csi.storage.k8s.io/pod.uid setting")
}
Expand Down
20 changes: 9 additions & 11 deletions pkg/agent-runtime/storage-cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ func TestRootCmdExecute_VersionSubcommand(t *testing.T) {

// newCSIRequestWithVolumeContext builds a minimal NodePublishVolumeRequest
// with the provided volume context; used to drive validateGeneralParams.
func newCSIRequestWithVolumeContext(ctx map[string]string) csi.NodePublishVolumeRequest {
return csi.NodePublishVolumeRequest{VolumeContext: ctx}
func newCSIRequestWithVolumeContext(ctx map[string]string) *csi.NodePublishVolumeRequest {
return &csi.NodePublishVolumeRequest{VolumeContext: ctx}
}

// captureStdout swaps os.Stdout for the duration of fn and returns the
Expand Down Expand Up @@ -348,8 +348,8 @@ func ensureSubcommand(t *testing.T, parent, child *cobra.Command) {
type fakeProvider struct {
driverName string
subDir string
validateFn func(csi.NodePublishVolumeRequest) error
mountFn func(context.Context, csi.NodePublishVolumeRequest) error
validateFn func(*csi.NodePublishVolumeRequest) error
mountFn func(context.Context, *csi.NodePublishVolumeRequest) error
}

func (f *fakeProvider) Driver() string { return f.driverName }
Expand All @@ -359,19 +359,19 @@ func (f *fakeProvider) SubDir() string {
}
return "fake"
}
func (f *fakeProvider) Validate(req csi.NodePublishVolumeRequest) error {
func (f *fakeProvider) Validate(req *csi.NodePublishVolumeRequest) error {
if f.validateFn != nil {
return f.validateFn(req)
}
return nil
}
func (f *fakeProvider) Mount(ctx context.Context, req csi.NodePublishVolumeRequest, debug bool) error {
func (f *fakeProvider) Mount(ctx context.Context, req *csi.NodePublishVolumeRequest, debug bool) error {
if f.mountFn != nil {
return f.mountFn(ctx, req)
}
return nil
}
func (f *fakeProvider) Unmount(_ context.Context, _ csi.NodePublishVolumeRequest) error {
func (f *fakeProvider) Unmount(_ context.Context, _ *csi.NodePublishVolumeRequest) error {
return nil
}

Expand Down Expand Up @@ -444,15 +444,15 @@ func TestRunMount(t *testing.T) {
lookupValidateErr := func(_ string) (storage.Provider, bool) {
return &fakeProvider{
driverName: fakeDriver,
validateFn: func(_ csi.NodePublishVolumeRequest) error {
validateFn: func(_ *csi.NodePublishVolumeRequest) error {
return fmt.Errorf("validate: secret key missing")
},
}, true
}
lookupMountErr := func(_ string) (storage.Provider, bool) {
return &fakeProvider{
driverName: fakeDriver,
mountFn: func(_ context.Context, _ csi.NodePublishVolumeRequest) error {
mountFn: func(_ context.Context, _ *csi.NodePublishVolumeRequest) error {
return fmt.Errorf("mount: socket not found")
},
}, true
Expand Down Expand Up @@ -613,5 +613,3 @@ func TestRunMount_PodUIDFromEnv(t *testing.T) {
// POD_UID env fills the missing pod uid so validateGeneralParams passes.
assert.NoError(t, runMount(silentCmd()))
}


4 changes: 2 additions & 2 deletions pkg/agent-runtime/storage-cli/storage/csi_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var newClientFn = func(socketPath string) (csi.NodeClient, io.Closer, error) {
// debug controls whether the full PublishContext (which may contain credentials
// such as AK/SK or tokens) is included in the log output. Pass true only in
// non-production environments for troubleshooting.
func RunNodePublishVolume(ctx context.Context, driver string, req csi.NodePublishVolumeRequest, debug bool) error {
func RunNodePublishVolume(ctx context.Context, driver string, req *csi.NodePublishVolumeRequest, debug bool) error {
socketPath := path.Join(CsiSocketDir, driver, CsiSocketFile)
client, closer, err := newClientFn(socketPath)
if err != nil {
Expand All @@ -71,7 +71,7 @@ func RunNodePublishVolume(ctx context.Context, driver string, req csi.NodePublis
defer cancel()

start := time.Now()
resp, err := client.NodePublishVolume(callCtx, &req, grpc.WaitForReady(true))
resp, err := client.NodePublishVolume(callCtx, req, grpc.WaitForReady(true))
if err != nil {
return fmt.Errorf("NodePublishVolume failed for driver %q: %w", driver, err)
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/agent-runtime/storage-cli/storage/csi_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func (c *nopCloser) Close() error {
type fakeNodeClient struct {
csi.NodeClient

gotReq *csi.NodePublishVolumeRequest
gotCtx context.Context
resp *csi.NodePublishVolumeResponse
err error
calls atomic.Int32
onCall func(ctx context.Context)
gotReq *csi.NodePublishVolumeRequest
gotCtx context.Context
resp *csi.NodePublishVolumeResponse
err error
calls atomic.Int32
onCall func(ctx context.Context)
}

func (f *fakeNodeClient) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest, _ ...grpc.CallOption) (*csi.NodePublishVolumeResponse, error) {
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestRunNodePublishVolume(t *testing.T) {
ctx, cancel := tt.ctx()
defer cancel()

err := RunNodePublishVolume(ctx, driver, csi.NodePublishVolumeRequest{VolumeId: "vol-1"}, false)
err := RunNodePublishVolume(ctx, driver, &csi.NodePublishVolumeRequest{VolumeId: "vol-1"}, false)

if tt.expectError == "" {
assert.NoError(t, err)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestRunNodePublishVolumeAppliesTimeout(t *testing.T) {
return fake, &nopCloser{}, nil
})

err := RunNodePublishVolume(context.Background(), "fake.csi.example.com", csi.NodePublishVolumeRequest{}, false)
err := RunNodePublishVolume(context.Background(), "fake.csi.example.com", &csi.NodePublishVolumeRequest{}, false)
assert.NoError(t, err)
assert.Equal(t, int32(1), fake.calls.Load())
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestRunNodePublishVolumeBuildsSocketPath(t *testing.T) {
return &fakeNodeClient{resp: &csi.NodePublishVolumeResponse{}}, &nopCloser{}, nil
})

err := RunNodePublishVolume(context.Background(), tt.driver, csi.NodePublishVolumeRequest{}, false)
err := RunNodePublishVolume(context.Background(), tt.driver, &csi.NodePublishVolumeRequest{}, false)
assert.NoError(t, err)
assert.Equal(t, tt.want, seenPath)
// Sanity-check the layout: the socket must live under CsiSocketDir.
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent-runtime/storage-cli/storage/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ type Provider interface {

// Validate checks driver-specific fields on the CSI request before
// the mount is attempted. It MUST NOT mutate the request.
Validate(req csi.NodePublishVolumeRequest) error
Validate(req *csi.NodePublishVolumeRequest) error

// Mount performs the driver-specific mount. The default open-source
// implementation forwards to the CSI plugin via NodePublishVolume; see
// RunNodePublishVolume.
//
// debug controls whether sensitive fields (e.g. PublishContext) are included
// in log output. Pass true only in non-production environments.
Mount(ctx context.Context, req csi.NodePublishVolumeRequest, debug bool) error
Mount(ctx context.Context, req *csi.NodePublishVolumeRequest, debug bool) error

// Unmount performs the driver-specific unmount. Drivers that have not
// implemented unmount yet may return nil.
Unmount(ctx context.Context, req csi.NodePublishVolumeRequest) error
Unmount(ctx context.Context, req *csi.NodePublishVolumeRequest) error
}
10 changes: 5 additions & 5 deletions pkg/agent-runtime/storage-cli/storage/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type fakeProvider struct {
subDir string
}

func (f *fakeProvider) Driver() string { return f.driver }
func (f *fakeProvider) SubDir() string { return f.subDir }
func (f *fakeProvider) Validate(_ csi.NodePublishVolumeRequest) error { return nil }
func (f *fakeProvider) Mount(_ context.Context, _ csi.NodePublishVolumeRequest, _ bool) error {
func (f *fakeProvider) Driver() string { return f.driver }
func (f *fakeProvider) SubDir() string { return f.subDir }
func (f *fakeProvider) Validate(_ *csi.NodePublishVolumeRequest) error { return nil }
func (f *fakeProvider) Mount(_ context.Context, _ *csi.NodePublishVolumeRequest, _ bool) error {
return nil
}
func (f *fakeProvider) Unmount(_ context.Context, _ csi.NodePublishVolumeRequest) error {
func (f *fakeProvider) Unmount(_ context.Context, _ *csi.NodePublishVolumeRequest) error {
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/agent-runtime/storage-cli/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
func TestValidateGeneralParams(t *testing.T) {
tests := []struct {
name string
csiReq csi.NodePublishVolumeRequest
csiReq *csi.NodePublishVolumeRequest
wantErr bool
}{
{
name: "valid request with pod uid",
csiReq: csi.NodePublishVolumeRequest{
csiReq: &csi.NodePublishVolumeRequest{
VolumeContext: map[string]string{
"csi.storage.k8s.io/pod.uid": "test-pod-uid",
},
Expand All @@ -39,7 +39,7 @@ func TestValidateGeneralParams(t *testing.T) {
},
{
name: "request without pod uid",
csiReq: csi.NodePublishVolumeRequest{
csiReq: &csi.NodePublishVolumeRequest{
VolumeContext: map[string]string{
"csi.storage.k8s.io/pod.uid": "",
},
Expand All @@ -48,14 +48,14 @@ func TestValidateGeneralParams(t *testing.T) {
},
{
name: "request without pod uid key",
csiReq: csi.NodePublishVolumeRequest{
csiReq: &csi.NodePublishVolumeRequest{
VolumeContext: map[string]string{},
},
wantErr: true,
},
{
name: "nil volume context",
csiReq: csi.NodePublishVolumeRequest{},
csiReq: &csi.NodePublishVolumeRequest{},
wantErr: true,
},
}
Expand Down
Loading