-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement test framework to test orchestration
- Loading branch information
Cheng Pan
committed
Aug 29, 2019
1 parent
294afe3
commit d37d640
Showing
10 changed files
with
590 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tester" | ||
) | ||
|
||
func main() { | ||
test := tester.NewTester("") | ||
err := test.Start() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package tester | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tester/pkg" | ||
yaml "gopkg.in/yaml.v2" | ||
"k8s.io/apimachinery/pkg/util/rand" | ||
) | ||
|
||
type Tester struct { | ||
init pkg.Step | ||
build pkg.Step | ||
up pkg.Step | ||
install pkg.Step | ||
test pkg.Step | ||
uninstall pkg.Step | ||
tearDown pkg.Step | ||
} | ||
|
||
func NewTester(configPath string) *Tester { | ||
if configPath == "" { | ||
configPath = readTestConfigPath() | ||
} | ||
testConfig, err := os.Open(configPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
var config *pkg.TestConfig | ||
err = yaml.NewDecoder(testConfig).Decode(&config) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
testId := fmt.Sprintf("%d", rand.Int()) | ||
clusterCreator, err := pkg.NewClusterCreator(config, "/tmp/ebs-e2e-test", testId) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return &Tester{ | ||
init: createStepOrPanic(clusterCreator.Init), | ||
build: scriptStep(config.BuildScript, testId), | ||
up: createStepOrPanic(clusterCreator.Up), | ||
install: scriptStep(config.InstallScript, testId), | ||
uninstall: scriptStep(config.UninstallScript, testId), | ||
tearDown: createStepOrPanic(clusterCreator.TearDown), | ||
} | ||
} | ||
|
||
func (t *Tester) Start() error { | ||
var err error | ||
err = t.init.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = t.build.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = t.up.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = t.install.Run() | ||
if err != nil { | ||
tErr := t.tearDown.Run() | ||
if tErr != nil { | ||
fmt.Printf("failed to tear down cluster: %v", tErr) | ||
} | ||
return err | ||
} | ||
|
||
err = t.test.Run() | ||
t.uninstall.Run() | ||
t.tearDown.Run() | ||
|
||
return err | ||
} | ||
|
||
func readTestConfigPath() string { | ||
path := os.Getenv("TESTCONFIG") | ||
if len(path) == 0 { | ||
return "test-config.yaml" | ||
} | ||
|
||
return path | ||
} | ||
|
||
func createStepOrPanic(f func() (pkg.Step, error)) pkg.Step { | ||
step, err := f() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return step | ||
} | ||
|
||
func scriptStep(script string, testId string) pkg.Step { | ||
return &pkg.TestStep{Script: script, TestId: testId} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/kubernetes-sigs/aws-ebs-csi-driver/tester | ||
|
||
go 1.12 | ||
|
||
require gopkg.in/yaml.v2 v2.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/kubernetes-sigs/aws-ebs-csi-driver v0.3.0 h1:i4uN/kDLuNZBLOL3JOFl6Gb/QBJBCMrO+28W97vIlvk= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type ClusterCreator interface { | ||
// Initialize the creator such as downloading dependencies | ||
Init() (Step, error) | ||
|
||
// Create and wait for cluster creation | ||
Up() (Step, error) | ||
|
||
// Teardown the cluster | ||
TearDown() (Step, error) | ||
} | ||
|
||
func NewClusterCreator(config *TestConfig, testDir string, testId string) (ClusterCreator, error) { | ||
cluster := config.Cluster | ||
|
||
if cluster.Kops == nil && cluster.Eks == nil { | ||
return nil, fmt.Errorf("TestConfig.Cluster is not set") | ||
} | ||
|
||
if cluster.Kops != nil && cluster.Eks != nil { | ||
return nil, fmt.Errorf("Both Kops and Eks cluster is set") | ||
} | ||
|
||
if cluster.Kops != nil { | ||
return NewKopsClusterCreator(cluster.Kops, testDir, testId), nil | ||
} | ||
|
||
// TODO: add for EKS cluster | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package pkg | ||
|
||
type TestConfig struct { | ||
Cluster *Cluster `yaml:"cluster"` | ||
Region string `yaml:"region"` | ||
BuildScript string `yaml:"build"` | ||
InstallScript string `yaml:"install"` | ||
UninstallScript string `yaml:"uninstall"` | ||
TestScript string `yaml:"test"` | ||
} | ||
|
||
type Cluster struct { | ||
Kops *KopsCluster `yaml:"kops"` | ||
Eks *EksCluster `yaml:"eks"` | ||
} | ||
|
||
type KopsCluster struct { | ||
Region string `yaml:"region"` | ||
Zones string `yaml:"zones"` | ||
NodeCount int `yaml:"nodeCount"` | ||
NodeSize string `yaml:"nodeSize"` | ||
KubernetesVersion string `yaml:"kubernetesVersion"` | ||
FeatureGates string `yaml:"featureGates"` | ||
IamPolicies string `yaml:"iamPolicies"` | ||
//KubeApiServer KubeApiServer `yaml:"kubeApiServer"` | ||
//Kubelet Kubelet `yaml:"kubelet"` | ||
} | ||
|
||
type KubeApiServer struct { | ||
FeatureGates FeatureGates `yaml:"featureGates"` | ||
} | ||
|
||
type FeatureGates struct { | ||
CSIDriverRegistry bool `yaml:"CSIDriverRegistry"` | ||
CSINodeInfo bool `yaml:"CSINodeInfo"` | ||
CSIBlockVolume bool `yaml:"CSIBlockVolume"` | ||
VolumeSnapshotDataSource bool `yaml:"VolumeSnapshotDataSource"` | ||
} | ||
|
||
type Kubelet struct { | ||
FeatureGates FeatureGates | ||
} | ||
|
||
type EksCluster struct { | ||
} |
Oops, something went wrong.