-
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 176f832
Showing
8 changed files
with
579 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,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.