This is an automated email from the ASF dual-hosted git repository.

pingsutw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git


The following commit(s) were added to refs/heads/master by this push:
     new 602739f  SUBMARINE-893. Add submarine-operator e2e test case for 
create/delete submarine
602739f is described below

commit 602739f4a19184cb6bae32a2aaa1cb76140b01df
Author: Kenchu123 <k889...@gmail.com>
AuthorDate: Sat Aug 28 19:31:26 2021 +0800

    SUBMARINE-893. Add submarine-operator e2e test case for create/delete 
submarine
    
    ### What is this PR for?
    <!-- A few sentences describing the overall goals of the pull request's 
commits.
    First time? Check out the contributing guide - 
https://submarine.apache.org/contribution/contributions.html
    -->
    
    Add submarine-operator e2e test case 
`TestSubmitSubmarineCustomResourceYaml`:
    
    1. Create a test namespace
    2. Create a submarine custom resource
    2. Wait for the submarine to be in `RUNNING` state
    3. Delete the submarine custom resource
    4. Delete the test namespace
    
    ### What type of PR is it?
    [Feature]
    
    ### Todos
    
    None
    
    ### What is the Jira issue?
    <!-- * Open an issue on Jira 
https://issues.apache.org/jira/browse/SUBMARINE/
    * Put link here, and add [SUBMARINE-*Jira number*] in PR title, eg. 
`SUBMARINE-23. PR title`
    -->
    
    https://issues.apache.org/jira/browse/SUBMARINE-893
    
    ### How should this be tested?
    <!--
    * First time? Setup Travis CI as described on 
https://submarine.apache.org/contribution/contributions.html#continuous-integration
    * Strongly recommended: add automated unit tests for any new or changed 
behavior
    * Outline any manual steps to test the PR here.
    -->
    
    ```bash
    # Add -v to see additional log
    # Add -count=1 to run the next time, otherwise, go will use the cache 
result.
    go test ./test/e2e
    ```
    
    ### Screenshots (if appropriate)
    
    
https://user-images.githubusercontent.com/17617373/131078695-a00b936c-b81a-4ced-a784-961d9ecdbf0d.mov
    
    ### Questions:
    * Do the license files need updating? No
    * Are there breaking changes for older versions? No
    * Does this need new documentation? No
    
    Author: Kenchu123 <k889...@gmail.com>
    
    Signed-off-by: Kevin <pings...@apache.org>
    
    Closes #724 from Kenchu123/SUBMARINE-893 and squashes the following commits:
    
    aa26c74f [Kenchu123] SUBMARINE-893. Make storage class from four to one only
    b14ac667 [Kenchu123] SUBMARINE-893. Format the code with gofmt
    e18e9c96 [Kenchu123] SUBMARINE-893. Check failed state on creating
    f9336ad9 [Kenchu123] SUBMARINE-893. Extend TIMEOUT to 300 seconds. Add more 
logs
    a0930c28 [Kenchu123] SUBMARINE-893. Add storageclass to test
    9413c016 [Kenchu123] SUBMARINE-893. Add create and delete e2e test
---
 submarine-cloud-v2/docs/developer-guide.md         |  6 +-
 submarine-cloud-v2/go.mod                          |  1 +
 submarine-cloud-v2/test/e2e/basic_test.go          | 94 ++++++++++++++++++++++
 .../test/e2e/framework/cluster_role.go             |  2 +-
 .../test/e2e/framework/cluster_role_binding.go     |  2 +-
 submarine-cloud-v2/test/e2e/framework/context.go   |  2 +-
 .../test/e2e/framework/deployment.go               | 43 +++++++++-
 submarine-cloud-v2/test/e2e/framework/framework.go | 72 +++++++++--------
 submarine-cloud-v2/test/e2e/framework/operator.go  |  2 +-
 .../test/e2e/framework/service_account.go          |  2 +-
 .../test/e2e/framework/storageclass.go             | 50 ++++++++++++
 submarine-cloud-v2/test/e2e/framework/submarine.go |  5 +-
 submarine-cloud-v2/test/e2e/main_test.go           | 26 +++++-
 13 files changed, 259 insertions(+), 48 deletions(-)

diff --git a/submarine-cloud-v2/docs/developer-guide.md 
b/submarine-cloud-v2/docs/developer-guide.md
index ea5e41b..f01a21d 100644
--- a/submarine-cloud-v2/docs/developer-guide.md
+++ b/submarine-cloud-v2/docs/developer-guide.md
@@ -50,10 +50,8 @@ Reference: [spark-on-k8s-operator e2e 
test](https://github.com/GoogleCloudPlatfo
 eval $(minikube docker-env)
 make image
 
-# Step2: Register Custom Resource Definition
-kubectl apply -f artifacts/examples/crd.yaml
-
-# Step3: Run Tests
+# Step2: Run Tests
+## one can add -v to see additional logs
 go test ./test/e2e
 ```
 
diff --git a/submarine-cloud-v2/go.mod b/submarine-cloud-v2/go.mod
index 98371ae..7b2e070 100644
--- a/submarine-cloud-v2/go.mod
+++ b/submarine-cloud-v2/go.mod
@@ -5,6 +5,7 @@ go 1.16
 require (
        github.com/imdario/mergo v0.3.11 // indirect
        github.com/pkg/errors v0.9.1
+       github.com/stretchr/testify v1.7.0
        github.com/traefik/traefik/v2 v2.4.8
        golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
        k8s.io/api v0.20.4
diff --git a/submarine-cloud-v2/test/e2e/basic_test.go 
b/submarine-cloud-v2/test/e2e/basic_test.go
new file mode 100644
index 0000000..4d5ed2b
--- /dev/null
+++ b/submarine-cloud-v2/test/e2e/basic_test.go
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 (
+       "context"
+       "fmt"
+       "testing"
+
+       
"github.com/apache/submarine/submarine-cloud-v2/pkg/apis/submarine/v1alpha1"
+       operatorFramework 
"github.com/apache/submarine/submarine-cloud-v2/test/e2e/framework"
+       corev1 "k8s.io/api/core/v1"
+       apierrors "k8s.io/apimachinery/pkg/api/errors"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/apimachinery/pkg/util/wait"
+
+       "github.com/stretchr/testify/assert"
+)
+
+// create & delete submarine custom resource with yaml
+func TestSubmitSubmarineCustomResourceYaml(t *testing.T) {
+       t.Log("[TestSubmitSubmarineCustomResourceYaml]")
+
+       // create a test namespace
+       submarineNs := "submarine-test-submit-custom-resource"
+       t.Logf("[Creating] Namespace %s", submarineNs)
+       _, err := 
framework.KubeClient.CoreV1().Namespaces().Create(context.TODO(), 
&corev1.Namespace{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name: submarineNs,
+               },
+       }, metav1.CreateOptions{})
+       assert.Equal(t, nil, err)
+
+       submarine, err := 
operatorFramework.MakeSubmarineFromYaml("../../artifacts/examples/example-submarine.yaml")
+       assert.Equal(t, nil, err)
+
+       // create submarine
+       submarineName := submarine.Name
+       t.Logf("[Creating] Submarine %s/%s", submarineNs, submarineName)
+       err = operatorFramework.CreateSubmarine(framework.SubmarineClient, 
submarineNs, submarine)
+       assert.Equal(t, nil, err)
+
+       // wait for submarine to be in RUNNING state
+       status := GetJobStatus(t, submarineNs, submarineName)
+       err = wait.Poll(INTERVAL, TIMEOUT, func() (done bool, err error) {
+               if status == v1alpha1.RunningState {
+                       return true, nil
+               }
+               if status == v1alpha1.FailedState {
+                       return true, fmt.Errorf("fail to create submarine 
%s/%s", submarineNs, submarineName)
+               }
+
+               status = GetJobStatus(t, submarineNs, submarineName)
+
+               return false, nil
+       })
+       assert.Equal(t, nil, err)
+
+       // delete submarine
+       t.Logf("[Deleting] Submarine %s/%s", submarineNs, submarineName)
+       err = operatorFramework.DeleteSubmarine(framework.SubmarineClient, 
submarineNs, submarineName)
+       assert.Equal(t, nil, err)
+
+       // wait for submarine to be deleted entirely
+       _, getError := 
operatorFramework.GetSubmarine(framework.SubmarineClient, submarineNs, 
submarineName)
+       err = wait.Poll(INTERVAL, TIMEOUT, func() (done bool, err error) {
+               if apierrors.IsNotFound(getError) {
+                       return true, nil
+               }
+               _, getError = 
operatorFramework.GetSubmarine(framework.SubmarineClient, submarineNs, 
submarineName)
+               return false, nil
+       })
+       assert.Equal(t, nil, err)
+
+       // delete the test namespace
+       t.Logf("[Deleting] Namespace %s", submarineNs)
+       err = framework.KubeClient.CoreV1().Namespaces().Delete(context.TODO(), 
submarineNs, metav1.DeleteOptions{})
+       assert.Equal(t, nil, err)
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/cluster_role.go 
b/submarine-cloud-v2/test/e2e/framework/cluster_role.go
index 3348519..eae5612 100644
--- a/submarine-cloud-v2/test/e2e/framework/cluster_role.go
+++ b/submarine-cloud-v2/test/e2e/framework/cluster_role.go
@@ -99,4 +99,4 @@ func parseClusterRoleYaml(relativePath string) 
(*rbacv1.ClusterRole, error) {
                return nil, err
        }
        return &clusterRole, nil
-}
\ No newline at end of file
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/cluster_role_binding.go 
b/submarine-cloud-v2/test/e2e/framework/cluster_role_binding.go
index 309c3ed..cb16ed2 100644
--- a/submarine-cloud-v2/test/e2e/framework/cluster_role_binding.go
+++ b/submarine-cloud-v2/test/e2e/framework/cluster_role_binding.go
@@ -101,4 +101,4 @@ func parseClusterRoleBindingYaml(relativePath string) 
(*rbacv1.ClusterRoleBindin
                return nil, err
        }
        return &clusterRoleBinding, nil
-}
\ No newline at end of file
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/context.go 
b/submarine-cloud-v2/test/e2e/framework/context.go
index 8e25db5..b56e83c 100644
--- a/submarine-cloud-v2/test/e2e/framework/context.go
+++ b/submarine-cloud-v2/test/e2e/framework/context.go
@@ -73,4 +73,4 @@ func (ctx *TestCtx) Cleanup(t *testing.T) {
 
 func (ctx *TestCtx) AddFinalizerFn(fn finalizerFn) {
        ctx.cleanUpFns = append(ctx.cleanUpFns, fn)
-}
\ No newline at end of file
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/deployment.go 
b/submarine-cloud-v2/test/e2e/framework/deployment.go
index 8f21698..1421b0f 100644
--- a/submarine-cloud-v2/test/e2e/framework/deployment.go
+++ b/submarine-cloud-v2/test/e2e/framework/deployment.go
@@ -24,6 +24,8 @@ import (
 
        "github.com/pkg/errors"
        appsv1 "k8s.io/api/apps/v1"
+       corev1 "k8s.io/api/core/v1"
+
        apierrors "k8s.io/apimachinery/pkg/api/errors"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/apimachinery/pkg/util/wait"
@@ -44,6 +46,45 @@ func MakeDeployment(pathToYaml string) (*appsv1.Deployment, 
error) {
        return &deployment, nil
 }
 
+func MakeOperatorDeployment() *appsv1.Deployment {
+       name := "submarine-operator-demo"
+       var replicas int32 = 1
+       image := "apache/submarine:operator-0.6.0-SNAPSHOT"
+       return &appsv1.Deployment{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name: name,
+                       Labels: map[string]string{
+                               "app": name,
+                       },
+               },
+               Spec: appsv1.DeploymentSpec{
+                       Replicas: &replicas,
+                       Selector: &metav1.LabelSelector{
+                               MatchLabels: map[string]string{
+                                       "app": name,
+                               },
+                       },
+                       Template: corev1.PodTemplateSpec{
+                               ObjectMeta: metav1.ObjectMeta{
+                                       Labels: map[string]string{
+                                               "app": name,
+                                       },
+                               },
+                               Spec: corev1.PodSpec{
+                                       ServiceAccountName: 
"submarine-operator",
+                                       Containers: []corev1.Container{
+                                               {
+                                                       Name:            name,
+                                                       Image:           image,
+                                                       ImagePullPolicy: 
"IfNotPresent",
+                                               },
+                                       },
+                               },
+                       },
+               },
+       }
+}
+
 func CreateDeployment(kubeClient kubernetes.Interface, namespace string, d 
*appsv1.Deployment) error {
        _, err := 
kubeClient.AppsV1().Deployments(namespace).Create(context.TODO(), d, 
metav1.CreateOptions{})
        if err != nil {
@@ -84,4 +125,4 @@ func WaitUntilDeploymentGone(kubeClient 
kubernetes.Interface, namespace, name st
 
                return false, nil
        })
-}
\ No newline at end of file
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/framework.go 
b/submarine-cloud-v2/test/e2e/framework/framework.go
index 94fa383..1f1fd8a 100644
--- a/submarine-cloud-v2/test/e2e/framework/framework.go
+++ b/submarine-cloud-v2/test/e2e/framework/framework.go
@@ -33,19 +33,16 @@ import (
 )
 
 type Framework struct {
-       KubeClient      kubernetes.Interface
+       KubeClient      kubernetes.Interface
        SubmarineClient clientset.Interface
-       Namespace *corev1.Namespace
-       OperatorPod *corev1.Pod
-       MasterHost string
-       DefaultTimeout time.Duration
+       Namespace       *corev1.Namespace
+       OperatorPod     *corev1.Pod
+       MasterHost      string
+       DefaultTimeout  time.Duration
 }
 
-var SubmarineTestNamespace = "submarine-user-test"
+func New(ns, kubeconfig, opImage, opImagePullPolicy string) (*Framework, 
error) {
 
-
-func New(ns, submarineNs, kubeconfig, opImage, opImagePullPolicy string) 
(*Framework, error) {
-       
        cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
        if err != nil {
                return nil, errors.Wrap(err, "build config failed")
@@ -55,14 +52,14 @@ func New(ns, submarineNs, kubeconfig, opImage, 
opImagePullPolicy string) (*Frame
        if err != nil {
                return nil, errors.Wrap(err, "creating new kube-client fail")
        }
-       
+
        // create submarine-operator namespace
        namespace, err := 
kubeClient.CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{
                ObjectMeta: metav1.ObjectMeta{
                        Name: ns,
                },
        },
-       metav1.CreateOptions{})
+               metav1.CreateOptions{})
        if apierrors.IsAlreadyExists(err) {
                namespace, err = 
kubeClient.CoreV1().Namespaces().Get(context.TODO(), ns, metav1.GetOptions{})
        } else {
@@ -74,14 +71,14 @@ func New(ns, submarineNs, kubeconfig, opImage, 
opImagePullPolicy string) (*Frame
                return nil, errors.Wrap(err, "creating new submarine-client 
fail")
        }
 
-       f := &Framework {
-               MasterHost: cfg.Host,
-               KubeClient: kubeClient,
+       f := &Framework{
+               MasterHost:      cfg.Host,
+               KubeClient:      kubeClient,
                SubmarineClient: submarineClient,
-               Namespace: namespace,
-               DefaultTimeout: time.Minute,
+               Namespace:       namespace,
+               DefaultTimeout:  time.Minute,
        }
-       err = f.Setup(submarineNs, opImage, opImagePullPolicy)
+       err = f.Setup(opImage, opImagePullPolicy)
        if err != nil {
                return nil, errors.Wrap(err, "setup test environment failed")
        }
@@ -89,33 +86,36 @@ func New(ns, submarineNs, kubeconfig, opImage, 
opImagePullPolicy string) (*Frame
        return f, nil
 }
 
-func (f *Framework) Setup(submarineNs, opImage, opImagePullPolicy string) 
error {
-       if err := f.setupOperator(submarineNs, opImage, opImagePullPolicy); err 
!= nil {
+func (f *Framework) Setup(opImage, opImagePullPolicy string) error {
+       if err := f.setupOperator(opImage, opImagePullPolicy); err != nil {
                return errors.Wrap(err, "setup operator failed")
        }
        return nil
 }
 
-func (f* Framework) setupOperator(submarineNs, opImage, opImagePullPolicy 
string) error {
+func (f *Framework) setupOperator(opImage, opImagePullPolicy string) error {
 
        // setup RBAC (ClusterRole, ClusterRoleBinding, and ServiceAccount)
-       if _, err := CreateServiceAccount(f.KubeClient, f.Namespace.Name, 
"../../artifacts/examples/submarine-operator-service-account.yaml"); err != nil 
&& !apierrors.IsAlreadyExists(err) {
+       if _, err := CreateServiceAccount(f.KubeClient, f.Namespace.Name, 
"../../helm-charts/submarine-operator/templates/rbac.yaml"); err != nil && 
!apierrors.IsAlreadyExists(err) {
                return errors.Wrap(err, "failed to create operator service 
account")
        }
 
-       if err := CreateClusterRole(f.KubeClient, 
"../../artifacts/examples/submarine-operator-service-account.yaml"); err != nil 
&& !apierrors.IsAlreadyExists(err) {
+       if err := CreateClusterRole(f.KubeClient, 
"../../helm-charts/submarine-operator/templates/rbac.yaml"); err != nil && 
!apierrors.IsAlreadyExists(err) {
                return errors.Wrap(err, "failed to create cluster role")
        }
 
-       if _, err := CreateClusterRoleBinding(f.KubeClient, 
"../../artifacts/examples/submarine-operator-service-account.yaml"); err != nil 
&& !apierrors.IsAlreadyExists(err) {
+       if _, err := CreateClusterRoleBinding(f.KubeClient, 
"../../helm-charts/submarine-operator/templates/rbac.yaml"); err != nil && 
!apierrors.IsAlreadyExists(err) {
                return errors.Wrap(err, "failed to create cluster role binding")
        }
-       // Deploy a submarine-operator
-       deploy, err := 
MakeDeployment("../../artifacts/examples/submarine-operator.yaml")
-       if err != nil {
-               return err
+
+       // setup storage class
+       if _, err := CreateStorageClass(f.KubeClient, 
"submarine-storageclass"); err != nil && !apierrors.IsAlreadyExists(err) {
+               return errors.Wrap(err, "failed to create storageclass 
submarine-storageclass")
        }
 
+       // Deploy a submarine-operator
+       deploy := MakeOperatorDeployment()
+
        if opImage != "" {
                // Override operator image used, if specified when running 
tests.
                deploy.Spec.Template.Spec.Containers[0].Image = opImage
@@ -125,7 +125,7 @@ func (f* Framework) setupOperator(submarineNs, opImage, 
opImagePullPolicy string
                container.ImagePullPolicy = corev1.PullPolicy(opImagePullPolicy)
        }
 
-       err = CreateDeployment(f.KubeClient, f.Namespace.Name, deploy)
+       err := CreateDeployment(f.KubeClient, f.Namespace.Name, deploy)
        if err != nil {
                return err
        }
@@ -147,21 +147,27 @@ func (f* Framework) setupOperator(submarineNs, opImage, 
opImagePullPolicy string
 
 // Teardown ters down a previously initialized test environment
 func (f *Framework) Teardown() error {
-       if err := DeleteClusterRole(f.KubeClient, 
"../../artifacts/examples/submarine-operator-service-account.yaml"); err != nil 
&& !apierrors.IsAlreadyExists(err) {
+       // delete rbac
+       if err := DeleteClusterRole(f.KubeClient, 
"../../helm-charts/submarine-operator/templates/rbac.yaml"); err != nil {
                return errors.Wrap(err, "failed to delete operator cluster 
role")
        }
 
-       if err := DeleteClusterRoleBinding(f.KubeClient, 
"../../artifacts/examples/submarine-operator-service-account.yaml"); err != nil 
&& !apierrors.IsAlreadyExists(err) {
+       if err := DeleteClusterRoleBinding(f.KubeClient, 
"../../helm-charts/submarine-operator/templates/rbac.yaml"); err != nil {
                return errors.Wrap(err, "failed to delete operator cluster role 
binding")
        }
 
+       // delete storage class
+       if err := DeleteStorageClass(f.KubeClient, "submarine-storageclass"); 
err != nil {
+               return errors.Wrap(err, "failed to delete storageclass 
submarine-storageclass")
+       }
+
        if err := 
f.KubeClient.AppsV1().Deployments(f.Namespace.Name).Delete(context.TODO(), 
"submarine-operator-demo", metav1.DeleteOptions{}); err != nil {
-               return err
+               return errors.Wrap(err, "failed to delete deployment 
submarine-operator-demo")
        }
 
        if err := DeleteNamespace(f.KubeClient, f.Namespace.Name); err != nil 
&& !apierrors.IsForbidden(err) {
-               return err
+               return errors.Wrap(err, "failed to delete namespace")
        }
 
        return nil
-}
\ No newline at end of file
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/operator.go 
b/submarine-cloud-v2/test/e2e/framework/operator.go
index d56765a..5fc7a7a 100644
--- a/submarine-cloud-v2/test/e2e/framework/operator.go
+++ b/submarine-cloud-v2/test/e2e/framework/operator.go
@@ -39,4 +39,4 @@ func PodRunningAndReady(pod corev1.Pod) (bool, error) {
                return false, fmt.Errorf("pod ready condition not found")
        }
        return false, nil
-}
\ No newline at end of file
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/service_account.go 
b/submarine-cloud-v2/test/e2e/framework/service_account.go
index b118ff7..c56923b 100644
--- a/submarine-cloud-v2/test/e2e/framework/service_account.go
+++ b/submarine-cloud-v2/test/e2e/framework/service_account.go
@@ -87,4 +87,4 @@ func DeleteServiceAccount(kubeClient kubernetes.Interface, 
namespace string, rel
        }
 
        return 
kubeClient.CoreV1().ServiceAccounts(namespace).Delete(context.TODO(), 
serviceAccount.Name, metav1.DeleteOptions{})
-}
\ No newline at end of file
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/storageclass.go 
b/submarine-cloud-v2/test/e2e/framework/storageclass.go
new file mode 100644
index 0000000..1863c6e
--- /dev/null
+++ b/submarine-cloud-v2/test/e2e/framework/storageclass.go
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 framework
+
+import (
+       "context"
+       "fmt"
+
+       "github.com/pkg/errors"
+       corev1 "k8s.io/api/core/v1"
+       storagev1 "k8s.io/api/storage/v1"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/client-go/kubernetes"
+)
+
+func CreateStorageClass(kubeClient kubernetes.Interface, name string) 
(*storagev1.StorageClass, error) {
+       provisioner := "k8s.io/minikube-hostpath"
+       recalimPolicy := corev1.PersistentVolumeReclaimDelete
+       storageclass, err := 
kubeClient.StorageV1().StorageClasses().Create(context.TODO(), 
&storagev1.StorageClass{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name: name,
+               },
+               Provisioner:   provisioner,
+               ReclaimPolicy: &recalimPolicy,
+       }, metav1.CreateOptions{})
+
+       if err != nil {
+               return nil, errors.Wrap(err, fmt.Sprintf("failed to create 
namespace with name %v", name))
+       }
+       return storageclass, nil
+}
+
+func DeleteStorageClass(kubeClient kubernetes.Interface, name string) error {
+       return kubeClient.StorageV1().StorageClasses().Delete(context.TODO(), 
name, metav1.DeleteOptions{})
+}
diff --git a/submarine-cloud-v2/test/e2e/framework/submarine.go 
b/submarine-cloud-v2/test/e2e/framework/submarine.go
index 386105f..fb4a712 100644
--- a/submarine-cloud-v2/test/e2e/framework/submarine.go
+++ b/submarine-cloud-v2/test/e2e/framework/submarine.go
@@ -66,7 +66,10 @@ func GetSubmarine(clientset clientset.Interface, namespace 
string, name string)
 }
 
 func DeleteSubmarine(clientset clientset.Interface, namespace string, name 
string) error {
-       err := 
clientset.SubmarineV1alpha1().Submarines(namespace).Delete(context.TODO(), 
name, metav1.DeleteOptions{})
+       foreground := metav1.DeletePropagationForeground
+       err := 
clientset.SubmarineV1alpha1().Submarines(namespace).Delete(context.TODO(), 
name, metav1.DeleteOptions{
+               PropagationPolicy: &foreground,
+       })
        if err != nil {
                return err
        }
diff --git a/submarine-cloud-v2/test/e2e/main_test.go 
b/submarine-cloud-v2/test/e2e/main_test.go
index 40697af..72b54e8 100644
--- a/submarine-cloud-v2/test/e2e/main_test.go
+++ b/submarine-cloud-v2/test/e2e/main_test.go
@@ -22,20 +22,40 @@ import (
        "log"
        "os"
        "testing"
+       "time"
+
+       v1alpha1 
"github.com/apache/submarine/submarine-cloud-v2/pkg/apis/submarine/v1alpha1"
 
        operatorFramework 
"github.com/apache/submarine/submarine-cloud-v2/test/e2e/framework"
+       "github.com/stretchr/testify/assert"
 )
 
 var (
        framework *operatorFramework.Framework
 )
 
+// Wait for test job to finish. Poll for updates once a second. Time out after 
240 seconds.
+var TIMEOUT = 300 * time.Second
+var INTERVAL = 1 * time.Second
+
+var STATES = [4]string{
+       "",
+       "CREATING",
+       "RUNNING",
+       "FAILED",
+}
+
+func GetJobStatus(t *testing.T, submarineNs, submarineName string) 
v1alpha1.SubmarineStateType {
+       submarine, err := 
operatorFramework.GetSubmarine(framework.SubmarineClient, submarineNs, 
submarineName)
+       assert.Equal(t, nil, err)
+       return submarine.Status.SubmarineState.State
+}
+
 func TestMain(m *testing.M) {
        kubeconfig := flag.String("kubeconfig", 
os.Getenv("HOME")+"/.kube/config", "Path to a kubeconfig. Only required if 
out-of-cluster.")
        opImage := flag.String("operator-image", "", "operator image, e.g. 
image:tag")
        opImagePullPolicy := flag.String("operator-image-pullPolicy", "Never", 
"pull policy, e.g. Always")
        ns := flag.String("namespace", "default", "e2e test operator namespace")
-       submarineTestNamespace := flag.String("submarine-test-namespace", 
"submarine-user-test", "e2e test submarine namespace")
        flag.Parse()
 
        var (
@@ -43,12 +63,10 @@ func TestMain(m *testing.M) {
                exitCode int
        )
 
-       if framework, err = operatorFramework.New(*ns, *submarineTestNamespace, 
*kubeconfig, *opImage, *opImagePullPolicy); err != nil {
+       if framework, err = operatorFramework.New(*ns, *kubeconfig, *opImage, 
*opImagePullPolicy); err != nil {
                log.Fatalf("Error setting up framework: %+v", err)
        }
 
-       operatorFramework.SubmarineTestNamespace = *submarineTestNamespace
-
        exitCode = m.Run()
 
        if err := framework.Teardown(); err != nil {

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@submarine.apache.org
For additional commands, e-mail: dev-h...@submarine.apache.org

Reply via email to