Skip to content

Commit

Permalink
chore: abstract e2e test configuration related (#5752)
Browse files Browse the repository at this point in the history
  • Loading branch information
linghan-hub authored Nov 6, 2023
1 parent 9828c9a commit 7563d06
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 41 deletions.
File renamed without changes.
File renamed without changes.
69 changes: 58 additions & 11 deletions test/e2e/testdata/smoketest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func Config() {

Context("Configure running e2e information", func() {
It("create a secret to save the access key and ", func() {
secret := "k get secret " + ConfigType + "-credential-for-backuprepo -n kb-system | grep " +
secret := "kubectl get secret " + ConfigType + "-credential-for-backuprepo -n kb-system | grep " +
ConfigType + "-credential-for-backuprepo | awk '{print $1}'"
if len(e2eutil.ExecCommand(secret)) > 0 {
if checkResourceExists(secret) {
log.Println("secret " + ConfigType + "-credential-for-backuprepo already exists")
} else {
var accessKey, secretKey string
Expand All @@ -67,7 +67,7 @@ func Config() {
})
It(" configure backup-repo", func() {
repo := "kubectl get BackupRepo | grep my-repo | awk '{print $1}'"
if len(e2eutil.ExecCommand(repo)) > 0 {
if checkResourceExists(repo) {
log.Println("BackupRepo already exists")
} else {
var yaml string
Expand All @@ -79,7 +79,33 @@ func Config() {
b := e2eutil.OpsYaml(yaml, "create")
Expect(b).Should(BeTrue())
}

})
It(" configure componentresourceconstraint custom", func() {
componentResourceConstraint := "kubectl get ComponentResourceConstraint | grep kb-resource-constraint-e2e | awk '{print $1}'"
if checkResourceExists(componentResourceConstraint) {
log.Println("ComponentResourceConstraint already exists")
} else {
b := e2eutil.OpsYaml(dir+"/testdata/config/componentresourceconstraint_custom.yaml", "create")
Expect(b).Should(BeTrue())
}
})
It(" configure custom class", func() {
componentClassDefinition := "kubectl get ComponentClassDefinition | grep custom-class | awk '{print $1}'"
if checkResourceExists(componentClassDefinition) {
log.Println("ComponentClassDefinition already exists")
} else {
b := e2eutil.OpsYaml(dir+"/testdata/config/custom_class.yaml", "create")
Expect(b).Should(BeTrue())
}
})
It(" configure pg cluster version", func() {
clusterVersion := "kubectl get ClusterVersion | grep postgresql-14.7.2-latest | awk '{print $1}'"
if checkResourceExists(clusterVersion) {
log.Println("postgresql-14.7.2-latest clusterVersion already exists")
} else {
b := e2eutil.OpsYaml(dir+"/testdata/config/postgresql_cv.yaml", "create")
Expect(b).Should(BeTrue())
}
})
})
}
Expand All @@ -91,20 +117,41 @@ func DeleteConfig() {
AfterEach(func() {
})

Context("delete e2e config resources", func() {
Context("delete e2e test resources", func() {
It("Check backup exists ", func() {
backupArr := e2eutil.ExecCommandReadline("kubectl get backup | awk '{print $1}'")
if len(backupArr) > 0 {
deleteBackups := e2eutil.ExecuteCommand("kubectl delete backup --all")
Expect(deleteBackups).Should(BeTrue())
deleteResource("kubectl delete backup --all")
}
})
It("delete secret and backuprepo", func() {
deleteSecret := e2eutil.ExecuteCommand("kubectl delete secret " + ConfigType + "-credential-for-backuprepo -n kb-system")
Expect(deleteSecret).Should(BeTrue())
deleteBr := e2eutil.ExecuteCommand("kubectl delete backuprepo my-repo")
Expect(deleteBr).Should(BeTrue())
deleteResource("kubectl delete secret " + ConfigType + "-credential-for-backuprepo -n kb-system")
deleteResource("kubectl delete backuprepo my-repo")
})

It("delete resources", func() {
deleteResource("kubectl delete ComponentResourceConstraint kb-resource-constraint-e2e")
deleteResource("kubectl delete ComponentClassDefinition custom-class")
})

It("delete cv", func() {
deleteResource("kubectl delete ClusterVersion postgresql-14.7.2-latest")
})

It("delete clusters", func() {
deleteResource("kubectl delete cluster --all")
})
})
}

func checkResourceExists(command string) bool {
if len(e2eutil.ExecCommand(command)) > 0 {
return true
}
return false
}

func deleteResource(cmd string) {
deleteCv := e2eutil.ExecuteCommand(cmd)
Expect(deleteCv).Should(BeTrue())
}
16 changes: 8 additions & 8 deletions test/e2e/testdata/smoketest/mariadb/00_mariadbcluster.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
# Source: mariadb/templates/rbac.yaml
# Source: mariadb-cluster/templates/rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: kb-mariadb-cluster
namespace: default
labels:
helm.sh/chart: mariadb-0.7.0-alpha.0
helm.sh/chart: mariadb-cluster-0.7.0-alpha.0
app.kubernetes.io/version: "10.6.15"
app.kubernetes.io/instance: mariadb-cluster
---
# Source: mariadb/templates/rbac.yaml
# Source: mariadb-cluster/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kb-mariadb-cluster
labels:
helm.sh/chart: mariadb-0.7.0-alpha.0
helm.sh/chart: mariadb-cluster-0.7.0-alpha.0
app.kubernetes.io/version: "10.6.15"
app.kubernetes.io/instance: mariadb-cluster
roleRef:
Expand All @@ -28,13 +28,13 @@ subjects:
name: kb-mariadb-cluster
namespace: default
---
# Source: mariadb/templates/rbac.yaml
# Source: mariadb-cluster/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: kb-mariadb-cluster
labels:
helm.sh/chart: mariadb-0.7.0-alpha.0
helm.sh/chart: mariadb-cluster-0.7.0-alpha.0
app.kubernetes.io/version: "10.6.15"
app.kubernetes.io/instance: mariadb-cluster
roleRef:
Expand All @@ -46,13 +46,13 @@ subjects:
name: kb-mariadb-cluster
namespace: default
---
# Source: mariadb/templates/cluster.yaml
# Source: mariadb-cluster/templates/cluster.yaml
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mariadb-cluster
labels:
helm.sh/chart: mariadb-0.7.0-alpha.0
helm.sh/chart: mariadb-cluster-0.7.0-alpha.0
app.kubernetes.io/version: "10.6.15"
app.kubernetes.io/instance: mariadb-cluster
spec:
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/testdata/smoketest/milvus/01_vscale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ spec:
type: VerticalScaling
verticalScaling:
- componentName: milvus
requests:
cpu: "500m"
memory: 500Mi
requests:
cpu: "500m"
memory: 500Mi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: pg-cluster-snapshot
name: pg-cluster-restore
annotations:
kubeblocks.io/restore-from-backup: '{"postgresql":{"name":"backup-postgresql-cluster","namespace":"default","volumeRestorePolicy":"Parallel"}}'
spec:
Expand Down
29 changes: 14 additions & 15 deletions test/e2e/testdata/smoketest/smoketestrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ type Options struct {
Dynamic dynamic.Interface
}

var arr = []string{"00", "componentresourceconstraint", "restore", "class", "cv", "backup"}

func SmokeTest() {
BeforeEach(func() {
})
Expand Down Expand Up @@ -159,6 +157,20 @@ func runTestCases(files []string) {
}
}
}
if strings.Contains(file, "restore") {
backups := "kubectl get backup | awk '{print $1}' | tail -n +2"
log.Println(backups)
backupList := e2eutil.ExecCommandReadline(backups)
log.Println(backupList)
Eventually(func(g Gomega) {
for _, backup := range backupList {
cmd := "kubectl get backup " + backup + " -o=jsonpath='{.status.phase}'"
log.Println(cmd)
log.Println(e2eutil.ExecCommand(cmd))
g.Expect(e2eutil.ExecCommand(cmd)).Should(Equal("Completed"))
}
}, timeout, interval).Should(Succeed())
}
b := e2eutil.OpsYaml(file, "create")
if strings.Contains(file, "00") || strings.Contains(file, "restore") {
clusterName, nameSpace = e2eutil.GetName(file)
Expand Down Expand Up @@ -197,11 +209,6 @@ func runTestCases(files []string) {
TestResults = append(TestResults, e2eResult)
}
}
if len(files) > 0 {
for _, file := range files {
deleteResource(file)
}
}
}

func troubleShooting(clusterName string) string {
Expand All @@ -211,11 +218,3 @@ func troubleShooting(clusterName string) string {
clusterEvents := e2eutil.ExecCommand(commond)
return allResourceStatus + clusterEvents
}

func deleteResource(file string) {
for _, s := range arr {
if strings.Contains(file, s) {
e2eutil.OpsYaml(file, "delete")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storage: 21Gi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: mysql-cluster-restore
name: mysql-cluster-restore-snapshot
annotations:
kubeblocks.io/restore-from-backup: '{"mysql":{"name":"backup-mysql-cluster-snapshot","namespace":"default","volumeRestorePolicy":"Parallel"}}'
spec:
Expand All @@ -23,4 +23,4 @@ spec:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storage: 25Gi

0 comments on commit 7563d06

Please sign in to comment.