Skip to content

Commit

Permalink
feat: upgraded the API for querying ECS details (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengxiangdong authored Jun 26, 2023
1 parent f55ce79 commit 8323fd2
Show file tree
Hide file tree
Showing 113 changed files with 3,395 additions and 1,141 deletions.
2 changes: 1 addition & 1 deletion deploy/evs-csi-plugin/kubernetes/csi-evs-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
- mountPath: /var/lib/csi/sockets/pluginproxy/
name: socket-dir
- name: evs-csi-provisioner
image: swr.cn-north-4.myhuaweicloud.com/k8s-csi/evs-csi-plugin:v0.1.7
image: swr.cn-north-4.myhuaweicloud.com/k8s-csi/evs-csi-plugin:v0.1.8
args:
- /bin/evs-csi-plugin
- "-v=5"
Expand Down
2 changes: 1 addition & 1 deletion deploy/evs-csi-plugin/kubernetes/csi-evs-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
- name: evs-csi-plugin
securityContext:
privileged: true
image: swr.cn-north-4.myhuaweicloud.com/k8s-csi/evs-csi-plugin:v0.1.7
image: swr.cn-north-4.myhuaweicloud.com/k8s-csi/evs-csi-plugin:v0.1.8
args:
- /bin/evs-csi-plugin
- "--v=5"
Expand Down
6 changes: 6 additions & 0 deletions docs/evs/evs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ For sidecar version compatibility, please refer compatibility matrix for each si
|------------------------|-------------|---------------------------|-------------------------|
| v0.1.4 | v1.5.0 | v1.20 v1.21 v1.22 v1.23 | volume resizer snapshot |
| v0.1.7 | v1.5.0 | v1.20 ~ 1.25 | encryption |
| v0.1.8 | v1.5.0 | v1.20 ~ 1.25 | |

> After `v0.1.8`, the API for querying ECS details has been upgraded,
> please use the latest IAM policies to modify your policy/role.
>
> See [IAM Policies for EVS CSI](../iam-policies.md#iam-policies-for-evs-csi) for IAM policies.
## Supported Parameters

Expand Down
31 changes: 21 additions & 10 deletions docs/iam-policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,39 @@ and project-level cloud services in the same policy, so we need to create two po

```
{
"Version":"1.1",
"Statement":[
"Version": "1.1",
"Statement": [
{
"Effect":"Allow",
"Action":[
"Effect": "Allow",
"Action": [
"EVS:*:*"
]
},
{
"Effect":"Allow",
"Action":[
"Effect": "Allow",
"Action": [
"ecs:serverVolumeAttachments:create",
"ecs:cloudServers:showServer",
"ecs:diskConfigs:use",
"ecs:cloudServers:attach",
"ecs:cloudServers:detachVolume",
"ecs:cloudServers:attachSharedVolume",
"ecs:cloudServers:listServerVolumeAttachments",
"ecs:serverKeypairs:get",
"ecs:serverVolumeAttachments:delete",
"ecs:serverVolumeAttachments:get",
"ecs:serverVolumes:use",
"ecs:serverVolumeAttachments:list",
"ecs:servers:get"
"ecs:servers:get",
"ecs:securityGroups:use"
]
},
{
"Effect": "Allow",
"Action": [
"vpc:networks:get",
"vpc:ports:get",
"vpc:securityGroupRules:get",
"vpc:subnets:get",
"vpc:routers:get",
"vpc:securityGroups:get"
]
}
]
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.7.0
golang.org/x/net v0.8.0
golang.org/x/sync v0.1.0
golang.org/x/sys v0.5.0
golang.org/x/sys v0.6.0
google.golang.org/grpc v1.50.1
google.golang.org/protobuf v1.28.1
gopkg.in/gcfg.v1 v1.2.3
Expand Down Expand Up @@ -56,8 +56,8 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.8.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -490,20 +490,20 @@ golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var allServiceCatalog = map[string]serviceCatalog{
Name: "ecs",
Version: "v1",
},
"ecsV21": {
Name: "ecs",
Version: "v2.1",
},
"evsV1": {
Name: "evs",
Version: "v1",
Expand Down Expand Up @@ -159,6 +163,10 @@ func (c *CloudCredentials) EcsV1Client() (*golangsdk.ServiceClient, error) {
return newServiceClient(c, "ecs", c.Global.Region)
}

func (c *CloudCredentials) EcsV21Client() (*golangsdk.ServiceClient, error) {
return newServiceClient(c, "ecsV21", c.Global.Region)
}

func (c *CloudCredentials) EvsV2Client() (*golangsdk.ServiceClient, error) {
return newServiceClient(c, "evsV2", c.Global.Region)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/evs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ func volumeAttachmentStatus(volume *cloudvolumes.Volume, instanceID string) Volu
return VolumeAttachError
}

func publishValidation(cc *config.CloudCredentials, volumeID, instanceID string,
capability *csi.VolumeCapability) error {
func publishValidation(cc *config.CloudCredentials, volumeID, instanceID string, capability *csi.VolumeCapability) error {
if len(volumeID) == 0 {
return status.Error(codes.InvalidArgument, "Validation failed, volume ID cannot be empty")
}
Expand Down
16 changes: 12 additions & 4 deletions pkg/evs/services/computes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"

"github.com/chnsz/golangsdk"
serversv2 "github.com/chnsz/golangsdk/openstack/compute/v2/servers"
"github.com/chnsz/golangsdk/openstack/ecs/v1/block_devices"
"github.com/chnsz/golangsdk/openstack/ecs/v1/cloudservers"
"github.com/chnsz/golangsdk/openstack/ecs/v1/jobs"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -16,13 +16,13 @@ import (
"github.com/huaweicloud/huaweicloud-csi-driver/pkg/config"
)

func GetServer(c *config.CloudCredentials, serverID string) (*cloudservers.CloudServer, error) {
client, err := getEcsV1Client(c)
func GetServer(c *config.CloudCredentials, serverID string) (*serversv2.Server, error) {
client, err := getEcsV21Client(c)
if err != nil {
return nil, err
}

cs, err := cloudservers.Get(client, serverID).Extract()
cs, err := serversv2.Get(client, serverID).Extract()
if err != nil {
if common.IsNotFound(err) {
return nil, status.Errorf(codes.NotFound, "Error, ECS instance %s does not exist", serverID)
Expand Down Expand Up @@ -157,3 +157,11 @@ func getEcsV1Client(c *config.CloudCredentials) (*golangsdk.ServiceClient, error
}
return client, nil
}

func getEcsV21Client(c *config.CloudCredentials) (*golangsdk.ServiceClient, error) {
client, err := c.EcsV21Client()
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("Failed create ECS V2.1 client: %s", err))
}
return client, nil
}
137 changes: 137 additions & 0 deletions vendor/github.com/chnsz/golangsdk/openstack/compute/v2/flavors/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8323fd2

Please sign in to comment.