Skip to content

Commit 21bd233

Browse files
authored
Add interface for csi client (#3899)
* Add interface for csi client * Add comments * Add comments
1 parent 822a471 commit 21bd233

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

ecs-agent/csiclient/csi_client.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
114
package csiclient
215

316
import (
@@ -18,13 +31,21 @@ const (
1831
PROTOCOL = "unix"
1932
)
2033

34+
// CSIClient is an interface that specifies all supported operations in the Container Storage Interface(CSI)
35+
// driver for Agent uses. The CSI driver provides many volume related operations to manage the lifecycle of
36+
// Amazon EBS volumes, including mounting, umounting, resizing and volume stats.
37+
type CSIClient interface {
38+
GetVolumeMetrics(volumeId string, hostMountPath string) (*Metrics, error)
39+
}
40+
2141
// csiClient encapsulates all CSI methods.
2242
type csiClient struct {
2343
csiSocket string
2444
}
2545

26-
func NewCSIClient(socketIn string) csiClient {
27-
return csiClient{csiSocket: socketIn}
46+
// NewCSIClient creates a CSI client for the communication with CSI driver daemon.
47+
func NewCSIClient(socketIn string) CSIClient {
48+
return &csiClient{csiSocket: socketIn}
2849
}
2950

3051
// GetVolumeMetrics returns volume usage.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package csiclient
15+
16+
const gibToBytes = 1024 * 1024 * 1024
17+
18+
// dummyCSIClient can be used to test the behaviour of csi client.
19+
type dummyCSIClient struct {
20+
}
21+
22+
func (c *dummyCSIClient) GetVolumeMetrics(volumeId string, hostMountPath string) (*Metrics, error) {
23+
return &Metrics{
24+
Used: 15 * gibToBytes,
25+
Capacity: 20 * gibToBytes,
26+
}, nil
27+
}
28+
29+
func NewDummyCSIClient() CSIClient {
30+
return &dummyCSIClient{}
31+
}

ecs-agent/csiclient/volume.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
114
package csiclient
215

316
// Metrics represents the used and capacity bytes of the Volume.
417
type Metrics struct {
518
// Used represents the total bytes used by the Volume.
6-
Used int64
19+
Used int64 `json:"Used"`
720

821
// Capacity represents the total capacity (bytes) of the volume's underlying storage.
9-
Capacity int64
22+
Capacity int64 `json:"Capacity"`
1023
}

0 commit comments

Comments
 (0)