Skip to content

Commit

Permalink
Merge pull request #4 from saurabhc123/csi-driver
Browse files Browse the repository at this point in the history
Add implementation of CSI-Driver for Windows
  • Loading branch information
jiuchoe4 authored Jul 3, 2024
2 parents c09614e + 7cad351 commit b88b1e3
Show file tree
Hide file tree
Showing 413 changed files with 88,524 additions and 11,399 deletions.
21 changes: 21 additions & 0 deletions agent/ebs/watcher_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build linux && unit
// +build linux,unit

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package ebs

const (
CSIDriverSocketPath = "/var/run/ecs/ebs-csi-driver/csi-driver.sock"
)
2 changes: 1 addition & 1 deletion agent/ebs/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ func TestTick(t *testing.T) {
tc.setDiscoveryClientExpectations(discoveryClient)
}

watcher := NewWatcher(context.Background(), taskEngineState, taskEngine, dockerClient)
watcher := NewWatcher(context.Background(), taskEngineState, taskEngine, dockerClient, CSIDriverSocketPath)
watcher.discoveryClient = discoveryClient
watcher.tick()

Expand Down
21 changes: 21 additions & 0 deletions agent/ebs/watcher_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build windows && unit
// +build windows,unit

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package ebs

const (
CSIDriverSocketPath = "C:\\Program Files\\Amazon\\ECS\\ebs-csi-driver\\csi-driver.sock"
)
47 changes: 0 additions & 47 deletions ecs-agent/daemonimages/csidriver/driver/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ limitations under the License.
package driver

import (
"context"
"fmt"
"os"
"path/filepath"

diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1"
diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1"

"github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver/mounter"
mountutils "k8s.io/mount-utils"
)
Expand Down Expand Up @@ -70,42 +62,3 @@ func newNodeMounter() (Mounter, error) {
}
return &NodeMounter{safeMounter}, nil
}

// DeviceIdentifier is for mocking os io functions used for the driver to
// identify an EBS volume's corresponding device (in Linux, the path under
// /dev; in Windows, the volume number) so that it can mount it. For volumes
// already mounted, see GetDeviceNameFromMount.
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#identify-nvme-ebs-device
type DeviceIdentifier interface {
Lstat(name string) (os.FileInfo, error)
EvalSymlinks(path string) (string, error)
ListDiskIDs() (map[uint32]*diskapi.DiskIDs, error)
}

type nodeDeviceIdentifier struct{}

func newNodeDeviceIdentifier() DeviceIdentifier {
return &nodeDeviceIdentifier{}
}

func (i *nodeDeviceIdentifier) Lstat(name string) (os.FileInfo, error) {
return os.Lstat(name)
}

func (i *nodeDeviceIdentifier) EvalSymlinks(path string) (string, error) {
return filepath.EvalSymlinks(path)
}

func (i *nodeDeviceIdentifier) ListDiskIDs() (map[uint32]*diskapi.DiskIDs, error) {
diskClient, err := diskclient.NewClient()
if err != nil {
return nil, fmt.Errorf("error creating csi-proxy disk client: %q", err)
}
defer diskClient.Close()

response, err := diskClient.ListDiskIDs(context.TODO(), &diskapi.ListDiskIDsRequest{})
if err != nil {
return nil, fmt.Errorf("error listing disk ids: %q", err)
}
return response.GetDiskIDs(), nil
}
25 changes: 25 additions & 0 deletions ecs-agent/daemonimages/csidriver/driver/mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package driver
import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -164,3 +165,27 @@ func (m *NodeMounter) Unstage(path string) error {
func (m *NodeMounter) NewResizeFs() (Resizefs, error) {
return mountutils.NewResizeFs(m.Exec), nil
}

// DeviceIdentifier is for mocking os io functions used for the driver to
// identify an EBS volume's corresponding device (in Linux, the path under
// /dev; in Windows, the volume number) so that it can mount it. For volumes
// already mounted, see GetDeviceNameFromMount.
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#identify-nvme-ebs-device
type DeviceIdentifier interface {
Lstat(name string) (os.FileInfo, error)
EvalSymlinks(path string) (string, error)
}

type nodeDeviceIdentifier struct{}

func newNodeDeviceIdentifier() DeviceIdentifier {
return &nodeDeviceIdentifier{}
}

func (i *nodeDeviceIdentifier) Lstat(name string) (os.FileInfo, error) {
return os.Lstat(name)
}

func (i *nodeDeviceIdentifier) EvalSymlinks(path string) (string, error) {
return filepath.EvalSymlinks(path)
}
32 changes: 32 additions & 0 deletions ecs-agent/daemonimages/csidriver/driver/mount_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ limitations under the License.
package driver

import (
"context"
"fmt"
"regexp"

"github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver/mounter"
"github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver/resizefs"
diskapi "github.com/kubernetes-csi/csi-proxy/client/api/disk/v1"
diskclient "github.com/kubernetes-csi/csi-proxy/client/groups/disk/v1"
mountutils "k8s.io/mount-utils"
)

Expand Down Expand Up @@ -162,3 +165,32 @@ func (m *NodeMounter) NewResizeFs() (Resizefs, error) {
}
return resizefs.NewResizeFs(proxyMounter), nil
}

// DeviceIdentifier is for mocking os io functions used for the driver to
// identify an EBS volume's corresponding device (in Linux, the path under
// /dev; in Windows, the volume number) so that it can mount it. For volumes
// already mounted, see GetDeviceNameFromMount.
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html#identify-nvme-ebs-device
type DeviceIdentifier interface {
ListDiskIDs() (map[uint32]*diskapi.DiskIDs, error)
}

type nodeDeviceIdentifier struct{}

func newNodeDeviceIdentifier() DeviceIdentifier {
return &nodeDeviceIdentifier{}
}

func (i *nodeDeviceIdentifier) ListDiskIDs() (map[uint32]*diskapi.DiskIDs, error) {
diskClient, err := diskclient.NewClient()
if err != nil {
return nil, fmt.Errorf("error creating csi-proxy disk client: %q", err)
}
defer diskClient.Close()

response, err := diskClient.ListDiskIDs(context.TODO(), &diskapi.ListDiskIDsRequest{})
if err != nil {
return nil, fmt.Errorf("error listing disk ids: %q", err)
}
return response.GetDiskIDs(), nil
}
36 changes: 22 additions & 14 deletions ecs-agent/daemonimages/csidriver/go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
module github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver

go 1.19
go 1.22.3

require (
github.com/container-storage-interface/spec v1.8.0
github.com/container-storage-interface/spec v1.9.0
github.com/golang/mock v1.6.0
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.18.0
google.golang.org/grpc v1.58.3
k8s.io/apimachinery v0.28.2
k8s.io/klog/v2 v2.100.1
k8s.io/mount-utils v0.28.2
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
github.com/kubernetes-csi/csi-proxy/client v1.1.3
github.com/kubernetes-sigs/aws-ebs-csi-driver v1.31.0
github.com/stretchr/testify v1.9.0
golang.org/x/sys v0.20.0
google.golang.org/grpc v1.64.0
k8s.io/apimachinery v0.30.1
k8s.io/klog/v2 v2.120.1
k8s.io/mount-utils v0.30.1
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/kubernetes-csi/csi-proxy/v2 v2.0.0-alpha.1 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/tools v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b88b1e3

Please sign in to comment.