Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interface for csi client #3899

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 21 additions & 2 deletions ecs-agent/csiclient/csi_client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// 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 csiclient

import (
Expand All @@ -18,13 +31,19 @@ const (
PROTOCOL = "unix"
)

// CSIClient is an interface that specifies all supported operations for Agent uses.
xxx0624 marked this conversation as resolved.
Show resolved Hide resolved
type CSIClient interface {
GetVolumeMetrics(volumeId string, hostMountPath string) (*Metrics, error)
}

// csiClient encapsulates all CSI methods.
type csiClient struct {
csiSocket string
}

func NewCSIClient(socketIn string) csiClient {
return csiClient{csiSocket: socketIn}
// NewCSIClient creates a CSI client for the communication with CSI driver daemon.
func NewCSIClient(socketIn string) CSIClient {
return &csiClient{csiSocket: socketIn}
}

// GetVolumeMetrics returns volume usage.
Expand Down
31 changes: 31 additions & 0 deletions ecs-agent/csiclient/dummy_csiclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 csiclient

const volumeSizeGib = 1024 * 1024 * 1024
xxx0624 marked this conversation as resolved.
Show resolved Hide resolved

// dummyCSIClient can be used to test the behaviour of csi client.
type dummyCSIClient struct {
}

func (c *dummyCSIClient) GetVolumeMetrics(volumeId string, hostMountPath string) (*Metrics, error) {
return &Metrics{
Used: 15 * volumeSizeGib,
Capacity: 20 * volumeSizeGib,
}, nil
}

func NewDummyCSIClient() CSIClient {
return &dummyCSIClient{}
}
17 changes: 15 additions & 2 deletions ecs-agent/csiclient/volume.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
// 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 csiclient

// Metrics represents the used and capacity bytes of the Volume.
type Metrics struct {
// Used represents the total bytes used by the Volume.
Used int64
Used int64 `json:"Used"`

// Capacity represents the total capacity (bytes) of the volume's underlying storage.
Capacity int64
Capacity int64 `json:"Capacity"`
}