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

kaihsun 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 7430d03  SUBMARINE-848. Make submarine CR and resources created in the 
same namespace
7430d03 is described below

commit 7430d03c29018ac22c09cf4fd64e0b0b269c3eaf
Author: MortalHappiness <[email protected]>
AuthorDate: Mon Jun 14 02:39:42 2021 +0800

    SUBMARINE-848. Make submarine CR and resources created in the same namespace
    
    ### What is this PR for?
    
    
https://pkg.go.dev/k8s.io/apimachineryv0.20.4/pkg/apis/meta/v1#OwnerReference
    
    The documentation above says that we should not create cross-namespace 
ownerReferences but our submarine CR and the resources created by operator are 
in different namespaces. After discussion with others, we decided to put them 
in the same namespace temporarily.
    
    ### What type of PR is it?
    [Bug Fix]
    
    ### Todos
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/projects/SUBMARINE/issues/SUBMARINE-848
    
    ### How should this be tested?
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Do the license files need updating? No
    * Are there breaking changes for older versions? No
    * Does this need new documentation? No
    
    Author: MortalHappiness <[email protected]>
    
    Signed-off-by: Kai-Hsun Chen <[email protected]>
    
    Closes #606 from MortalHappiness/SUBMARINE-848 and squashes the following 
commits:
    
    91c2f955 [MortalHappiness] SUBMARINE-848. Make submarine CR and resources 
created in the same namespace
---
 submarine-cloud-v2/README.md     | 18 ++++++++++--------
 submarine-cloud-v2/controller.go | 41 ++++++++--------------------------------
 2 files changed, 18 insertions(+), 41 deletions(-)

diff --git a/submarine-cloud-v2/README.md b/submarine-cloud-v2/README.md
index 1d5e7b0..00f3a31 100644
--- a/submarine-cloud-v2/README.md
+++ b/submarine-cloud-v2/README.md
@@ -61,8 +61,9 @@ go build -o submarine-operator
 ./submarine-operator
 
 # Step2: Deploy a submarine
-kubectl create ns submarine-admin
-kubectl apply -n submarine-admin -f artifacts/examples/example-submarine.yaml
+kubectl apply -f artifacts/examples/crd.yaml
+kubectl create ns submarine-user-test
+kubectl apply -n submarine-user-test -f 
artifacts/examples/example-submarine.yaml
 
 # Step3: Exposing Service
 # Method1 -- using minikube ip + NodePort
@@ -79,8 +80,8 @@ $ kubectl port-forward --address 0.0.0.0 -n 
submarine-user-test service/traefik
 #   (1) Remove all relevant Helm chart releases
 #   (2) Remove all resources in the namespace "submariner-user-test"
 #   (3) Remove all non-namespaced resources (Ex: PersistentVolume) created by 
client-go API
-#   (4) **Note:** The namespace "submarine-admin" will not be deleted
-kubectl delete submarine example-submarine -n submarine-admin
+#   (4) **Note:** The namespace "submarine-user-test" will not be deleted
+kubectl delete submarine example-submarine -n submarine-user-test
 ```
 
 # Run operator in-cluster
@@ -97,8 +98,9 @@ kubectl apply -f 
artifacts/examples/submarine-operator-service-account.yaml
 kubectl apply -f artifacts/examples/submarine-operator.yaml
 
 # Step4: Deploy a submarine
-kubectl create ns submarine-admin
-kubectl apply -n submarine-admin -f artifacts/examples/example-submarine.yaml
+kubectl apply -f artifacts/examples/crd.yaml
+kubectl create ns submarine-user-test
+kubectl apply -n submarine-user-test -f 
artifacts/examples/example-submarine.yaml
 
 # Step5: Inspect submarine-operator POD logs
 kubectl logs -f ${submarine-operator POD}
@@ -121,8 +123,8 @@ $ kubectl port-forward --address 0.0.0.0 -n 
submarine-user-test service/traefik
 #   (1) Remove all relevant Helm chart releases
 #   (2) Remove all resources in the namespace "submariner-user-test"
 #   (3) Remove all non-namespaced resources (Ex: PersistentVolume) created by 
client-go API
-#   (4) **Note:** The namespace "submarine-admin" will not be deleted
-kubectl delete submarine example-submarine -n submarine-admin
+#   (4) **Note:** The namespace "submarine-user-test" will not be deleted
+kubectl delete submarine example-submarine -n submarine-user-test
 
 # Step10: Delete "submarine-operator"
 kubectl delete deployment submarine-operator-demo
diff --git a/submarine-cloud-v2/controller.go b/submarine-cloud-v2/controller.go
index 294c0e7..2b1cbcb 100644
--- a/submarine-cloud-v2/controller.go
+++ b/submarine-cloud-v2/controller.go
@@ -112,8 +112,8 @@ type Controller struct {
 
        // TODO: Need to be modified to implement multi-tenant
        // Store charts
-       charts     []helm.HelmUninstallInfo
-       incluster  bool
+       charts    []helm.HelmUninstallInfo
+       incluster bool
 }
 
 const (
@@ -1327,8 +1327,6 @@ func (c *Controller) syncHandler(workqueueItem 
WorkQueueItem) error {
                utilruntime.HandleError(fmt.Errorf("Invalid resource key: %s", 
key))
                return nil
        }
-       newNamespace := "submarine-user-test"
-
        klog.Info("syncHandler: ", key, " / ", action)
 
        if action != DELETE { // Case: ADD & UPDATE
@@ -1348,31 +1346,8 @@ func (c *Controller) syncHandler(workqueueItem 
WorkQueueItem) error {
                b, err := json.MarshalIndent(submarine.Spec, "", "  ")
                fmt.Println(string(b))
 
-               // create submarine in a new namespace
-               ns, err := c.namespaceLister.Get(newNamespace)
-               if errors.IsNotFound(err) {
-                       ns, err = 
c.kubeclientset.CoreV1().Namespaces().Create(context.TODO(),
-                               &corev1.Namespace{
-                                       ObjectMeta: metav1.ObjectMeta{
-                                               Name: newNamespace,
-                                               OwnerReferences: 
[]metav1.OwnerReference{
-                                                       
*metav1.NewControllerRef(submarine, 
v1alpha1.SchemeGroupVersion.WithKind("Submarine")),
-                                               },
-                                       },
-                               },
-                               metav1.CreateOptions{})
-               }
-               if err != nil {
-                       return err
-               }
-               if !metav1.IsControlledBy(ns, submarine) {
-                       msg := fmt.Sprintf(MessageResourceExists, ns.Name)
-                       c.recorder.Event(submarine, corev1.EventTypeWarning, 
ErrResourceExists, msg)
-                       return fmt.Errorf(msg)
-               }
-
                // Install subcharts
-               c.newSubCharts(newNamespace)
+               c.newSubCharts(namespace)
 
                // Create submarine-server
                serverImage := submarine.Spec.Server.Image
@@ -1380,31 +1355,31 @@ func (c *Controller) syncHandler(workqueueItem 
WorkQueueItem) error {
                if serverImage == "" {
                        serverImage = "apache/submarine:server-" + 
submarine.Spec.Version
                }
-               err = c.newSubmarineServer(submarine, newNamespace, 
serverImage, serverReplicas)
+               err = c.newSubmarineServer(submarine, namespace, serverImage, 
serverReplicas)
                if err != nil {
                        return err
                }
 
                // Create Submarine Database
-               err = c.newSubmarineDatabase(submarine, newNamespace, 
&submarine.Spec)
+               err = c.newSubmarineDatabase(submarine, namespace, 
&submarine.Spec)
                if err != nil {
                        return err
                }
 
                // Create ingress
-               err = c.newIngress(submarine, newNamespace)
+               err = c.newIngress(submarine, namespace)
                if err != nil {
                        return err
                }
 
                // Create RBAC
-               err = c.newSubmarineServerRBAC(submarine, newNamespace)
+               err = c.newSubmarineServerRBAC(submarine, namespace)
                if err != nil {
                        return err
                }
 
                // Create Submarine Tensorboard
-               err = c.newSubmarineTensorboard(submarine, newNamespace, 
&submarine.Spec)
+               err = c.newSubmarineTensorboard(submarine, namespace, 
&submarine.Spec)
                if err != nil {
                        return err
                }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to