Skip to content

Commit

Permalink
Merge a64379e into b4ae9b3
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheng Pan committed Oct 11, 2019
2 parents b4ae9b3 + a64379e commit d556721
Show file tree
Hide file tree
Showing 15 changed files with 1,021 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -39,7 +39,7 @@ test:

.PHONY: test-e2e
test-e2e:
echo "success"
TESTCONFIG=./tester/e2e-test-config.yaml go run tester/cmd/main.go

.PHONY: image
image:
Expand Down
3 changes: 3 additions & 0 deletions go.mod
@@ -1,14 +1,17 @@
module github.com/kubernetes-sigs/aws-fsx-csi-driver

require (
github.com/aws/aws-k8s-tester/e2e/tester v0.0.0-20191006044911-6f09e24ed288
github.com/aws/aws-sdk-go v1.23.21
github.com/container-storage-interface/spec v1.1.0
github.com/golang/mock v1.3.1
github.com/kubernetes-csi/csi-test v2.0.1+incompatible
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
google.golang.org/grpc v1.23.0
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/client-go v0.0.0
k8s.io/klog v0.4.0
k8s.io/kubernetes v1.16.1
)
Expand Down
70 changes: 67 additions & 3 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/driver/driver.go
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
driverName = "fsx.csi.aws.com"
DriverName = "fsx.csi.aws.com"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/identity.go
Expand Up @@ -24,7 +24,7 @@ import (

func (d *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
resp := &csi.GetPluginInfoResponse{
Name: driverName,
Name: DriverName,
VendorVersion: driverVersion,
}

Expand Down
25 changes: 25 additions & 0 deletions tester/cmd/main.go
@@ -0,0 +1,25 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License 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 main

import (
"github.com/aws/aws-k8s-tester/e2e/tester"
)

func main() {
tester.Start()
}
85 changes: 85 additions & 0 deletions tester/e2e-test-config.yaml
@@ -0,0 +1,85 @@
cluster:
kops:
stateFile: s3://k8s-kops-csi-e2e
zones: us-west-2a
nodeCount: 3
nodeSize: c5.large
kubernetesVersion: 1.15.3
featureGates: |2
kubeAPIServer:
featureGates:
CSIDriverRegistry: "true"
CSINodeInfo: "true"
CSIBlockVolume: "true"
CSIMigration: "true"
CSIMigrationAWS: "true"
ExpandCSIVolumes: "true"
VolumeSnapshotDataSource: "true"
CSIInlineVolume: "true"
kubeControllerManager:
featureGates:
CSIDriverRegistry: "true"
CSINodeInfo: "true"
CSIBlockVolume: "true"
CSIMigration: "true"
CSIMigrationAWS: "true"
ExpandCSIVolumes: "true"
CSIInlineVolume: "true"
kubelet:
featureGates:
CSIDriverRegistry: "true"
CSINodeInfo: "true"
CSIBlockVolume: "true"
CSIMigration: "true"
CSIMigrationAWS: "true"
ExpandCSIVolumes: "true"
CSIInlineVolume: "true"
iamPolicies: |2
additionalPolicies:
node: |
[
{
"Effect": "Allow",
"Action": [
"iam:CreateServiceLinkedRole",
"iam:AttachRolePolicy",
"iam:PutRolePolicy"
],
"Resource": "arn:aws:iam::*:role/aws-service-role/s3.data-source.lustre.fsx.amazonaws.com/*"
},
{
"Effect": "Allow",
"Action": [
"s3:*",
"fsx:*"
],
"Resource": ["*"]
}
]
build: |
eval $(aws ecr get-login --region us-west-2 --no-include-email)
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
IMAGE_TAG={{TEST_ID}}
IMAGE_NAME=$AWS_ACCOUNT_ID.dkr.ecr.us-west-2.amazonaws.com/aws-fsx-csi-driver
docker build -t $IMAGE_NAME:$IMAGE_TAG .
docker push $IMAGE_NAME:$IMAGE_TAG
install: |
echo "Deploying driver"
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
IMAGE_TAG={{TEST_ID}}
IMAGE_NAME=$AWS_ACCOUNT_ID.dkr.ecr.us-west-2.amazonaws.com/aws-fsx-csi-driver
sed -i'' "s,amazon/aws-fsx-csi-driver:latest,$IMAGE_NAME:$IMAGE_TAG," deploy/kubernetes/manifest.yaml
kubectl apply -f deploy/kubernetes/manifest.yaml
uninstall: |
echo "Removing driver"
kubectl delete -f deploy/kubernetes/manifest.yaml
test: |
export KUBECONFIG=$HOME/.kube/config
cluster_name=test-cluster-{{TEST_ID}}.k8s.local
cd tests/e2e
go test ./ -v -timeout 0 --cluster-name=$cluster_name --region=us-west-2 --report-dir=$ARTIFACTS
58 changes: 58 additions & 0 deletions tests/e2e/cloud.go
@@ -0,0 +1,58 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License 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 e2e

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
)

func getNodeInstance(clusterName string) (*ec2.Instance, error) {
config := &aws.Config{
Region: region,
}
nodeName := fmt.Sprintf("nodes.%s", clusterName)
svc := ec2.New(session.Must(session.NewSession(config)))
request := &ec2.DescribeInstancesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag:Name"),
Values: []*string{aws.String(nodeName)},
},
},
}

instances := []*ec2.Instance{}
response, err := svc.DescribeInstances(request)
if err != nil {
return nil, err
}
for _, reservation := range response.Reservations {
instances = append(instances, reservation.Instances...)
}

return instances[0], nil
}

func getSecurityGroupIds(node *ec2.Instance) []string {
groups := []string{}
for _, sg := range node.SecurityGroups {
groups = append(groups, *sg.GroupId)
}
return groups
}
61 changes: 61 additions & 0 deletions tests/e2e/driver/driver.go
@@ -0,0 +1,61 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License 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 driver

import (
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type PVTestDriver interface {
DynamicPVTestDriver
}

// DynamicPVTestDriver represents an interface for a CSI driver that supports DynamicPV
type DynamicPVTestDriver interface {
// GetDynamicProvisionStorageClass returns a StorageClass dynamic provision Persistent Volume
GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass
}

func getStorageClass(
generateName string,
provisioner string,
parameters map[string]string,
mountOptions []string,
reclaimPolicy *v1.PersistentVolumeReclaimPolicy,
bindingMode *storagev1.VolumeBindingMode,
allowedTopologies []v1.TopologySelectorTerm,
) *storagev1.StorageClass {
if reclaimPolicy == nil {
defaultReclaimPolicy := v1.PersistentVolumeReclaimDelete
reclaimPolicy = &defaultReclaimPolicy
}
if bindingMode == nil {
defaultBindingMode := storagev1.VolumeBindingImmediate
bindingMode = &defaultBindingMode
}
return &storagev1.StorageClass{
ObjectMeta: metav1.ObjectMeta{
GenerateName: generateName,
},
Provisioner: provisioner,
Parameters: parameters,
MountOptions: mountOptions,
ReclaimPolicy: reclaimPolicy,
VolumeBindingMode: bindingMode,
AllowedTopologies: allowedTopologies,
}
}
42 changes: 42 additions & 0 deletions tests/e2e/driver/fsx_csi_driver.go
@@ -0,0 +1,42 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License 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 driver

import (
"fmt"

fsxcsidriver "github.com/kubernetes-sigs/aws-fsx-csi-driver/pkg/driver"
"k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
)

// Implement PVTestDriver interface
type fsxCSIDriver struct {
driverName string
}

// InitFSxCSIDriver returns fsxCSIDriver that implements DynamicPVTestDriver interface
func InitFSxCSIDriver() PVTestDriver {
return &fsxCSIDriver{
driverName: fsxcsidriver.DriverName,
}
}

func (d *fsxCSIDriver) GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass {
provisioner := d.driverName
generateName := fmt.Sprintf("%s-%s-dynamic-sc-", namespace, provisioner)
allowedTopologies := []v1.TopologySelectorTerm{}
return getStorageClass(generateName, provisioner, parameters, mountOptions, reclaimPolicy, bindingMode, allowedTopologies)
}

0 comments on commit d556721

Please sign in to comment.