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

sunnianjun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git


The following commit(s) were added to refs/heads/main by this push:
     new 2311578  refactor(operator): separate ComputeNode and 
ShardingSphereProxy  (#182)
2311578 is described below

commit 2311578401cf799fbf6d85a93c8aa413e1af6a38
Author: liyao <[email protected]>
AuthorDate: Mon Jan 16 14:56:16 2023 +0800

    refactor(operator): separate ComputeNode and ShardingSphereProxy  (#182)
    
    * chore: update refactor package imports
    
    Signed-off-by: mlycore <[email protected]>
    
    * refactor: seperate compute_node and proxy_server
    
    Signed-off-by: mlycore <[email protected]>
    
    * refactor: update compute node controller
    
    Signed-off-by: mlycore <[email protected]>
    
    * chore: remove empty tests
    
    Signed-off-by: mlycore <[email protected]>
    
    * chore: rename proxyserver to proxy
    
    Signed-off-by: mlycore <[email protected]>
    
    * chore: separate proxyconfig reconciler
    
    Signed-off-by: mlycore <[email protected]>
    
    Signed-off-by: mlycore <[email protected]>
---
 .../pkg/controllers/compute_node_controller.go     |  10 +-
 .../pkg/controllers/proxy_controller.go            |   2 +-
 .../pkg/controllers/proxyconfig_controller.go      |   2 +-
 .../pkg/reconcile/{ => computenode}/configmap.go   |  35 +++++-
 .../pkg/reconcile/{ => computenode}/deployment.go  |   6 +-
 .../{status.go => computenode/deployment_test.go}  |  30 +-----
 .../pkg/reconcile/{ => computenode}/service.go     |  56 +---------
 .../{deployment_proxy.go => proxy/deployment.go}   |   2 +-
 .../pkg/reconcile/{ => proxy}/deployment_test.go   |  17 +--
 .../pkg/reconcile/{ => proxy}/hpa.go               |   2 +-
 .../pkg/reconcile/{ => proxy}/reconcile_test.go    | 120 +--------------------
 .../pkg/reconcile/{status.go => proxy/resource.go} |  28 +----
 .../pkg/reconcile/{ => proxy}/service.go           |  61 +----------
 .../pkg/reconcile/{ => proxy}/status.go            |   2 +-
 .../{resource.go => proxyconfig/configmap.go}      |   9 +-
 .../pkg/reconcile/proxyconfig/configmap_test.go    | 119 ++++++++++++++++++++
 16 files changed, 176 insertions(+), 325 deletions(-)

diff --git a/shardingsphere-operator/pkg/controllers/compute_node_controller.go 
b/shardingsphere-operator/pkg/controllers/compute_node_controller.go
index 4b7cea3..bcaa97f 100644
--- a/shardingsphere-operator/pkg/controllers/compute_node_controller.go
+++ b/shardingsphere-operator/pkg/controllers/compute_node_controller.go
@@ -22,7 +22,7 @@ import (
        "time"
 
        
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
-       
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/pkg/reconcile"
+       reconcile 
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/pkg/reconcile/computenode"
        appsv1 "k8s.io/api/apps/v1"
        v1 "k8s.io/api/core/v1"
        apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -202,7 +202,7 @@ func (r *ComputeNodeReconciler) reconcileStatus(ctx 
context.Context, namespace,
        return nil
 }
 
-func getReadyNodes(podlist v1.PodList) int32 {
+func getReadyInstances(podlist v1.PodList) int32 {
        var cnt int32
        for _, p := range podlist.Items {
                if p.Status.Phase == v1.PodRunning {
@@ -306,13 +306,13 @@ func clusterCondition(podlist v1.PodList) 
v1alpha1.ComputeNodeCondition {
 }
 
 func ReconcileComputeNodeStatus(podlist v1.PodList, svc v1.Service, rt 
v1alpha1.ComputeNode) v1alpha1.ComputeNodeStatus {
-       readyNodes := getReadyNodes(podlist)
+       readyInstances := getReadyInstances(podlist)
 
-       rt.Status.ReadyInstances = readyNodes
+       rt.Status.ReadyInstances = readyInstances
        if rt.Spec.Replicas == 0 {
                rt.Status.Phase = v1alpha1.ComputeNodeStatusNotReady
        } else {
-               if readyNodes < miniReadyCount {
+               if readyInstances < miniReadyCount {
                        rt.Status.Phase = v1alpha1.ComputeNodeStatusNotReady
                } else {
                        rt.Status.Phase = v1alpha1.ComputeNodeStatusReady
diff --git a/shardingsphere-operator/pkg/controllers/proxy_controller.go 
b/shardingsphere-operator/pkg/controllers/proxy_controller.go
index 0498adf..3eba598 100644
--- a/shardingsphere-operator/pkg/controllers/proxy_controller.go
+++ b/shardingsphere-operator/pkg/controllers/proxy_controller.go
@@ -22,7 +22,7 @@ import (
        "time"
 
        
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
-       
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/pkg/reconcile"
+       reconcile 
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/pkg/reconcile/proxy"
 
        appsv1 "k8s.io/api/apps/v1"
        autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
diff --git a/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go 
b/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go
index c29c576..dd376e7 100644
--- a/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go
+++ b/shardingsphere-operator/pkg/controllers/proxyconfig_controller.go
@@ -22,7 +22,7 @@ import (
 
        shardingspherev1alpha1 
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
 
-       
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/pkg/reconcile"
+       reconcile 
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/pkg/reconcile/proxyconfig"
 
        v1 "k8s.io/api/core/v1"
        "k8s.io/apimachinery/pkg/api/equality"
diff --git a/shardingsphere-operator/pkg/reconcile/configmap.go 
b/shardingsphere-operator/pkg/reconcile/computenode/configmap.go
similarity index 73%
rename from shardingsphere-operator/pkg/reconcile/configmap.go
rename to shardingsphere-operator/pkg/reconcile/computenode/configmap.go
index aea4dac..f193eaf 100644
--- a/shardingsphere-operator/pkg/reconcile/configmap.go
+++ b/shardingsphere-operator/pkg/reconcile/computenode/configmap.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package reconcile
+package computenode
 
 import (
        "encoding/json"
@@ -93,3 +93,36 @@ func ComputeNodeUpdateConfigMap(cn *v1alpha1.ComputeNode, 
cur *v1.ConfigMap) *v1
        exp.Data = ComputeNodeNewConfigMap(cn).Data
        return exp
 }
+
+const defaultLogback = `<?xml version="1.0"?>
+<configuration>
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] 
%logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+    <appender name="sqlConsole" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] 
[%X{database}] [%X{user}] [%X{host}] %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+    
+    <logger name="ShardingSphere-SQL" level="info" additivity="false">
+        <appender-ref ref="sqlConsole" />
+    </logger>
+    <logger name="org.apache.shardingsphere" level="info" additivity="false">
+        <appender-ref ref="console" />
+    </logger>
+    
+    <logger name="com.zaxxer.hikari" level="error" />
+    
+    <logger name="com.atomikos" level="error" />
+    
+    <logger name="io.netty" level="error" />
+    
+    <root>
+        <level value="info" />
+        <appender-ref ref="console" />
+    </root>
+</configuration> 
+`
diff --git a/shardingsphere-operator/pkg/reconcile/deployment.go 
b/shardingsphere-operator/pkg/reconcile/computenode/deployment.go
similarity index 97%
rename from shardingsphere-operator/pkg/reconcile/deployment.go
rename to shardingsphere-operator/pkg/reconcile/computenode/deployment.go
index 8a7e90d..5e58040 100644
--- a/shardingsphere-operator/pkg/reconcile/deployment.go
+++ b/shardingsphere-operator/pkg/reconcile/computenode/deployment.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package reconcile
+package computenode
 
 import (
        "fmt"
@@ -30,6 +30,7 @@ import (
 
 const (
        DefaultExtlibPath = "/opt/shardingsphere-proxy/ext-lib"
+       imageName         = "apache/shardingsphere-proxy"
 )
 
 func ComputeNodeNewDeployment(cn *v1alpha1.ComputeNode) *v1.Deployment {
@@ -39,13 +40,10 @@ func ComputeNodeNewDeployment(cn *v1alpha1.ComputeNode) 
*v1.Deployment {
        deploy.Name = cn.Name
        deploy.Namespace = cn.Namespace
        deploy.Labels = cn.Labels
-       // deploy.Spec.Selector.MatchLabels = cn.Labels
        deploy.Spec.Selector = cn.Spec.Selector
        deploy.Spec.Replicas = &cn.Spec.Replicas
        deploy.Spec.Template.Labels = cn.Labels
        deploy.Spec.Template.Spec.Containers[0].Image = fmt.Sprintf("%s:%s", 
imageName, cn.Spec.ServerVersion)
-       // TODO: don't use v1.Port directly
-       // deploy.Spec.Template.Spec.Containers[0].Ports = cn.Spec.Ports
        if deploy.Spec.Template.Spec.Containers[0].Ports == nil {
                deploy.Spec.Template.Spec.Containers[0].Ports = 
[]corev1.ContainerPort{}
        }
diff --git a/shardingsphere-operator/pkg/reconcile/status.go 
b/shardingsphere-operator/pkg/reconcile/computenode/deployment_test.go
similarity index 57%
copy from shardingsphere-operator/pkg/reconcile/status.go
copy to shardingsphere-operator/pkg/reconcile/computenode/deployment_test.go
index ef05dcc..e6faa09 100644
--- a/shardingsphere-operator/pkg/reconcile/status.go
+++ b/shardingsphere-operator/pkg/reconcile/computenode/deployment_test.go
@@ -15,32 +15,4 @@
  * limitations under the License.
  */
 
-package reconcile
-
-import (
-       v1 "k8s.io/api/core/v1"
-)
-
-func IsRunning(podList *v1.PodList) bool {
-       status := false
-       for _, pod := range podList.Items {
-               if pod.Status.Phase == v1.PodRunning && 
pod.ObjectMeta.DeletionTimestamp == nil {
-                       status = true
-               }
-       }
-
-       return status
-}
-
-func CountingReadyPods(podList *v1.PodList) int32 {
-       var readyPods int32 = 0
-       for _, pod := range podList.Items {
-               if len(pod.Status.ContainerStatuses) == 0 {
-                       continue
-               }
-               if pod.Status.ContainerStatuses[0].Ready && 
pod.ObjectMeta.DeletionTimestamp == nil {
-                       readyPods++
-               }
-       }
-       return readyPods
-}
+package computenode
diff --git a/shardingsphere-operator/pkg/reconcile/service.go 
b/shardingsphere-operator/pkg/reconcile/computenode/service.go
similarity index 61%
copy from shardingsphere-operator/pkg/reconcile/service.go
copy to shardingsphere-operator/pkg/reconcile/computenode/service.go
index 3ddcf51..b5680a2 100644
--- a/shardingsphere-operator/pkg/reconcile/service.go
+++ b/shardingsphere-operator/pkg/reconcile/computenode/service.go
@@ -15,11 +15,9 @@
  * limitations under the License.
  */
 
-package reconcile
+package computenode
 
 import (
-       "reflect"
-
        
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
        corev1 "k8s.io/api/core/v1"
        v1 "k8s.io/api/core/v1"
@@ -33,11 +31,8 @@ func ComputeNodeNewService(cn *v1alpha1.ComputeNode) 
*v1.Service {
        svc.Name = cn.Name
        svc.Namespace = cn.Namespace
        svc.Labels = cn.Labels
-       // svc.Spec.Selector = cn.Labels
        svc.Spec.Selector = cn.Spec.Selector.MatchLabels
-       // svc.Spec.Type = cn.Spec.Service.Type
        svc.Spec.Type = cn.Spec.ServiceType
-       // svc.Spec.Ports = cn.Spec.Service.Ports
 
        if svc.Spec.Ports == nil {
                svc.Spec.Ports = []corev1.ServicePort{}
@@ -83,52 +78,3 @@ func ComputeNodeUpdateService(cn *v1alpha1.ComputeNode, cur 
*v1.Service) *v1.Ser
        exp.Spec.ClusterIPs = cur.Spec.ClusterIPs
        return exp
 }
-
-func NewService(ssproxy *v1alpha1.ShardingSphereProxy) *v1.Service {
-       return ConstructCascadingService(ssproxy)
-}
-
-func ConstructCascadingService(proxy *v1alpha1.ShardingSphereProxy) 
*v1.Service {
-       if proxy == nil || reflect.DeepEqual(proxy, 
&v1alpha1.ShardingSphereProxy{}) {
-               return &v1.Service{}
-       }
-
-       svc := v1.Service{
-               ObjectMeta: metav1.ObjectMeta{
-                       Name:      proxy.Name,
-                       Namespace: proxy.Namespace,
-                       OwnerReferences: []metav1.OwnerReference{
-                               *metav1.NewControllerRef(proxy.GetObjectMeta(), 
proxy.GroupVersionKind()),
-                       },
-               },
-               Spec: v1.ServiceSpec{
-                       Selector: map[string]string{
-                               "apps": proxy.Name,
-                       },
-                       Type: proxy.Spec.ServiceType.Type,
-                       Ports: []v1.ServicePort{
-                               {
-                                       Name:       "proxy-port",
-                                       TargetPort: fromInt32(proxy.Spec.Port),
-                                       Port:       proxy.Spec.Port,
-                               },
-                       },
-               },
-       }
-       if proxy.Spec.ServiceType.Type == v1.ServiceTypeNodePort {
-               svc.Spec.Ports[0].NodePort = proxy.Spec.ServiceType.NodePort
-       }
-       return &svc
-}
-
-func UpdateService(proxy *v1alpha1.ShardingSphereProxy, runtimeService 
*v1.Service) *v1.Service {
-       exp := &v1.Service{}
-       runtimeService.Spec.Type = proxy.Spec.ServiceType.Type
-       runtimeService.Spec.Ports[0].Port = proxy.Spec.Port
-       runtimeService.Spec.Ports[0].TargetPort = fromInt32(proxy.Spec.Port)
-       if proxy.Spec.ServiceType.NodePort != 0 {
-               runtimeService.Spec.Ports[0].NodePort = 
proxy.Spec.ServiceType.NodePort
-       }
-       exp = runtimeService.DeepCopy()
-       return exp
-}
diff --git a/shardingsphere-operator/pkg/reconcile/deployment_proxy.go 
b/shardingsphere-operator/pkg/reconcile/proxy/deployment.go
similarity index 99%
rename from shardingsphere-operator/pkg/reconcile/deployment_proxy.go
rename to shardingsphere-operator/pkg/reconcile/proxy/deployment.go
index 29a2ea0..3dd28a9 100644
--- a/shardingsphere-operator/pkg/reconcile/deployment_proxy.go
+++ b/shardingsphere-operator/pkg/reconcile/proxy/deployment.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxy
 
 import (
        "fmt"
diff --git a/shardingsphere-operator/pkg/reconcile/deployment_test.go 
b/shardingsphere-operator/pkg/reconcile/proxy/deployment_test.go
similarity index 99%
rename from shardingsphere-operator/pkg/reconcile/deployment_test.go
rename to shardingsphere-operator/pkg/reconcile/proxy/deployment_test.go
index 96645a1..0c8b6d8 100644
--- a/shardingsphere-operator/pkg/reconcile/deployment_test.go
+++ b/shardingsphere-operator/pkg/reconcile/proxy/deployment_test.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxy
 
 import (
        "fmt"
@@ -277,21 +277,6 @@ func Test_addInitContaienr(t *testing.T) {
        }
 }
 
-func Test_processOptionalParameter(t *testing.T) {
-       /*
-          cases := []struct{
-
-          }{
-              {
-
-              },
-          }
-
-          for _, c := range cases {
-
-          }
-       */
-}
 func Test_UpdateDeployment(t *testing.T) {
        var rep int32 = 3
        cases := []struct {
diff --git a/shardingsphere-operator/pkg/reconcile/hpa.go 
b/shardingsphere-operator/pkg/reconcile/proxy/hpa.go
similarity index 99%
rename from shardingsphere-operator/pkg/reconcile/hpa.go
rename to shardingsphere-operator/pkg/reconcile/proxy/hpa.go
index 8428f7a..d9bf18b 100644
--- a/shardingsphere-operator/pkg/reconcile/hpa.go
+++ b/shardingsphere-operator/pkg/reconcile/proxy/hpa.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxy
 
 import (
        
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
diff --git a/shardingsphere-operator/pkg/reconcile/reconcile_test.go 
b/shardingsphere-operator/pkg/reconcile/proxy/reconcile_test.go
similarity index 83%
rename from shardingsphere-operator/pkg/reconcile/reconcile_test.go
rename to shardingsphere-operator/pkg/reconcile/proxy/reconcile_test.go
index 2c7a3e1..cc11b16 100644
--- a/shardingsphere-operator/pkg/reconcile/reconcile_test.go
+++ b/shardingsphere-operator/pkg/reconcile/proxy/reconcile_test.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxy
 
 import (
        "testing"
@@ -341,129 +341,11 @@ func Test_ConstructCascadingService(t *testing.T) {
 }
 
 func Test_ConstructCascadingConfigmap(t *testing.T) {
-       /*
-          cases := []struct{
 
-          }{
-              {
-
-              },
-          }
-
-          for _, c := range cases {
-
-          }
-       */
 }
 
 func Test_ConstructHPA(t *testing.T) {
-       /*
-          cases := []struct{
-
-          }{
-              {
-
-              },
-          }
-
-          for _, c := range cases {
-
-          }
-       */
-}
-
-func Test_ToYAML(t *testing.T) {
-       cases := []struct {
-               proxyCfg *v1alpha1.ShardingSphereProxyServerConfig
-               exp      string
-               message  string
-       }{
-               {
-                       proxyCfg: &v1alpha1.ShardingSphereProxyServerConfig{},
-                       exp: `mode:
-  type: ""
-  repository:
-    type: ""
-    props:
-      namespace: ""
-      server-lists: ""
-authority:
-  users: []
-  privilege: null
-`,
-                       message: "Empty proxy server config should generate 
yaml with empty value",
-               },
-               {
-                       proxyCfg: &v1alpha1.ShardingSphereProxyServerConfig{
-                               Spec: v1alpha1.ProxyConfigSpec{
-                                       ClusterConfig: v1alpha1.ClusterConfig{
-                                               Type: "Cluster",
-                                               Repository: 
v1alpha1.RepositoryConfig{
-                                                       Type: "Zookeeper",
-                                                       Props: 
v1alpha1.ClusterProps{
-                                                               Namespace:      
              "cluster-sharding-mode",
-                                                               ServerLists:    
              "host1:2181,host2:2181",
-                                                               
RetryIntervalMilliseconds:    500,
-                                                               MaxRetries:     
              3,
-                                                               
TimeToLiveSeconds:            60,
-                                                               
OperationTimeoutMilliseconds: 500,
-                                                       },
-                                               },
-                                       },
-                                       Authority: v1alpha1.Auth{
-                                               Users: []v1alpha1.User{
-                                                       {
-                                                               User:     
"John",
-                                                               Password: 
"123456",
-                                                       },
-                                               },
-                                               Privilege: &v1alpha1.Privilege{
-                                                       Type: "Admin",
-                                               },
-                                       },
-                                       Props: &v1alpha1.Props{
-                                               KernelExecutorSize:             
   16,
-                                               CheckTableMetadataEnabled:      
   false,
-                                               ProxyBackendQueryFetchSize:     
   -1,
-                                               CheckDuplicateTableEnabled:     
   false,
-                                               ProxyFrontendExecutorSize:      
   0,
-                                               ProxyBackendExecutorSuitable:   
   "OLAP",
-                                               ProxyBackendDriverType:         
   "JDBC",
-                                               
ProxyFrontendDatabaseProtocolType: "",
-                                       },
-                               },
-                       },
-                       exp: `mode:
-  type: Cluster
-  repository:
-    type: Zookeeper
-    props:
-      namespace: cluster-sharding-mode
-      server-lists: host1:2181,host2:2181
-      retryIntervalMilliseconds: 500
-      maxRetries: 3
-      timeToLiveSeconds: 60
-      operationTimeoutMilliseconds: 500
-authority:
-  users:
-  - user: John
-    password: "123456"
-  privilege:
-    type: Admin
-props:
-  kernel-executor-size: 16
-  proxy-backend-query-fetch-size: -1
-  proxy-backend-executor-suitable: OLAP
-  proxy-backend-driver-type: JDBC
-`,
-                       message: "Should generate yaml with the same value as 
ShardingSphereProxyServerConfig.Spec",
-               },
-       }
 
-       for _, c := range cases {
-               act := toYaml(c.proxyCfg)
-               assert.Equal(t, c.exp, act, c.message)
-       }
 }
 
 func Test_UpdateService(t *testing.T) {
diff --git a/shardingsphere-operator/pkg/reconcile/status.go 
b/shardingsphere-operator/pkg/reconcile/proxy/resource.go
similarity index 58%
copy from shardingsphere-operator/pkg/reconcile/status.go
copy to shardingsphere-operator/pkg/reconcile/proxy/resource.go
index ef05dcc..657ce83 100644
--- a/shardingsphere-operator/pkg/reconcile/status.go
+++ b/shardingsphere-operator/pkg/reconcile/proxy/resource.go
@@ -15,32 +15,14 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxy
 
 import (
-       v1 "k8s.io/api/core/v1"
+       "k8s.io/apimachinery/pkg/util/intstr"
 )
 
-func IsRunning(podList *v1.PodList) bool {
-       status := false
-       for _, pod := range podList.Items {
-               if pod.Status.Phase == v1.PodRunning && 
pod.ObjectMeta.DeletionTimestamp == nil {
-                       status = true
-               }
-       }
+const imageName = "apache/shardingsphere-proxy"
 
-       return status
-}
-
-func CountingReadyPods(podList *v1.PodList) int32 {
-       var readyPods int32 = 0
-       for _, pod := range podList.Items {
-               if len(pod.Status.ContainerStatuses) == 0 {
-                       continue
-               }
-               if pod.Status.ContainerStatuses[0].Ready && 
pod.ObjectMeta.DeletionTimestamp == nil {
-                       readyPods++
-               }
-       }
-       return readyPods
+func fromInt32(val int32) intstr.IntOrString {
+       return intstr.IntOrString{Type: intstr.Int, IntVal: val}
 }
diff --git a/shardingsphere-operator/pkg/reconcile/service.go 
b/shardingsphere-operator/pkg/reconcile/proxy/service.go
similarity index 58%
rename from shardingsphere-operator/pkg/reconcile/service.go
rename to shardingsphere-operator/pkg/reconcile/proxy/service.go
index 3ddcf51..63ded07 100644
--- a/shardingsphere-operator/pkg/reconcile/service.go
+++ b/shardingsphere-operator/pkg/reconcile/proxy/service.go
@@ -15,75 +15,16 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxy
 
 import (
        "reflect"
 
        
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
-       corev1 "k8s.io/api/core/v1"
        v1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-       "k8s.io/apimachinery/pkg/runtime/schema"
-       "k8s.io/apimachinery/pkg/util/intstr"
 )
 
-func ComputeNodeNewService(cn *v1alpha1.ComputeNode) *v1.Service {
-       svc := ComputeNodeDefaultService(cn.GetObjectMeta(), 
cn.GroupVersionKind())
-       svc.Name = cn.Name
-       svc.Namespace = cn.Namespace
-       svc.Labels = cn.Labels
-       // svc.Spec.Selector = cn.Labels
-       svc.Spec.Selector = cn.Spec.Selector.MatchLabels
-       // svc.Spec.Type = cn.Spec.Service.Type
-       svc.Spec.Type = cn.Spec.ServiceType
-       // svc.Spec.Ports = cn.Spec.Service.Ports
-
-       if svc.Spec.Ports == nil {
-               svc.Spec.Ports = []corev1.ServicePort{}
-       }
-       for _, pb := range cn.Spec.PortBindings {
-               svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
-                       Name:       pb.Name,
-                       TargetPort: intstr.FromInt(int(pb.ContainerPort)),
-                       Port:       pb.ServicePort,
-                       NodePort:   pb.NodePort,
-                       Protocol:   pb.Protocol,
-               })
-       }
-
-       return svc
-}
-
-func ComputeNodeDefaultService(meta metav1.Object, gvk 
schema.GroupVersionKind) *v1.Service {
-       return &v1.Service{
-               ObjectMeta: metav1.ObjectMeta{
-                       Name:      "shardingsphere-proxy",
-                       Namespace: "default",
-                       Labels:    map[string]string{},
-                       OwnerReferences: []metav1.OwnerReference{
-                               *metav1.NewControllerRef(meta, gvk),
-                       },
-               },
-               Spec: v1.ServiceSpec{
-                       Selector: map[string]string{},
-                       Type:     v1.ServiceTypeClusterIP,
-                       Ports:    []v1.ServicePort{},
-               },
-       }
-}
-
-func ComputeNodeUpdateService(cn *v1alpha1.ComputeNode, cur *v1.Service) 
*v1.Service {
-       exp := &v1.Service{}
-       exp.ObjectMeta = cur.ObjectMeta
-       exp.Labels = cur.Labels
-       exp.Annotations = cur.Annotations
-       exp.Spec = ComputeNodeNewService(cn).Spec
-       exp.Spec.ClusterIP = cur.Spec.ClusterIP
-       exp.Spec.ClusterIPs = cur.Spec.ClusterIPs
-       return exp
-}
-
 func NewService(ssproxy *v1alpha1.ShardingSphereProxy) *v1.Service {
        return ConstructCascadingService(ssproxy)
 }
diff --git a/shardingsphere-operator/pkg/reconcile/status.go 
b/shardingsphere-operator/pkg/reconcile/proxy/status.go
similarity index 98%
rename from shardingsphere-operator/pkg/reconcile/status.go
rename to shardingsphere-operator/pkg/reconcile/proxy/status.go
index ef05dcc..68af269 100644
--- a/shardingsphere-operator/pkg/reconcile/status.go
+++ b/shardingsphere-operator/pkg/reconcile/proxy/status.go
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxy
 
 import (
        v1 "k8s.io/api/core/v1"
diff --git a/shardingsphere-operator/pkg/reconcile/resource.go 
b/shardingsphere-operator/pkg/reconcile/proxyconfig/configmap.go
similarity index 93%
rename from shardingsphere-operator/pkg/reconcile/resource.go
rename to shardingsphere-operator/pkg/reconcile/proxyconfig/configmap.go
index d6bd6e5..d9f70cd 100644
--- a/shardingsphere-operator/pkg/reconcile/resource.go
+++ b/shardingsphere-operator/pkg/reconcile/proxyconfig/configmap.go
@@ -15,18 +15,15 @@
  * limitations under the License.
  */
 
-package reconcile
+package proxyconfig
 
 import (
        
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
        "gopkg.in/yaml.v2"
        v1 "k8s.io/api/core/v1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-       "k8s.io/apimachinery/pkg/util/intstr"
 )
 
-const imageName = "apache/shardingsphere-proxy"
-
 const defaultLogback = `<?xml version="1.0"?>
 <configuration>
     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
@@ -83,7 +80,3 @@ func toYaml(proxyConfig 
*v1alpha1.ShardingSphereProxyServerConfig) string {
        y, _ := yaml.Marshal(proxyConfig.Spec)
        return string(y)
 }
-
-func fromInt32(val int32) intstr.IntOrString {
-       return intstr.IntOrString{Type: intstr.Int, IntVal: val}
-}
diff --git 
a/shardingsphere-operator/pkg/reconcile/proxyconfig/configmap_test.go 
b/shardingsphere-operator/pkg/reconcile/proxyconfig/configmap_test.go
new file mode 100644
index 0000000..c50f381
--- /dev/null
+++ b/shardingsphere-operator/pkg/reconcile/proxyconfig/configmap_test.go
@@ -0,0 +1,119 @@
+/*
+ * 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 proxyconfig
+
+import (
+       "testing"
+
+       
"github.com/apache/shardingsphere-on-cloud/shardingsphere-operator/api/v1alpha1"
+       "github.com/stretchr/testify/assert"
+)
+
+func Test_ToYAML(t *testing.T) {
+       cases := []struct {
+               proxyCfg *v1alpha1.ShardingSphereProxyServerConfig
+               exp      string
+               message  string
+       }{
+               {
+                       proxyCfg: &v1alpha1.ShardingSphereProxyServerConfig{},
+                       exp: `mode:
+  type: ""
+  repository:
+    type: ""
+    props:
+      namespace: ""
+      server-lists: ""
+authority:
+  users: []
+  privilege: null
+`,
+                       message: "Empty proxy server config should generate 
yaml with empty value",
+               },
+               {
+                       proxyCfg: &v1alpha1.ShardingSphereProxyServerConfig{
+                               Spec: v1alpha1.ProxyConfigSpec{
+                                       ClusterConfig: v1alpha1.ClusterConfig{
+                                               Type: "Cluster",
+                                               Repository: 
v1alpha1.RepositoryConfig{
+                                                       Type: "Zookeeper",
+                                                       Props: 
v1alpha1.ClusterProps{
+                                                               Namespace:      
              "cluster-sharding-mode",
+                                                               ServerLists:    
              "host1:2181,host2:2181",
+                                                               
RetryIntervalMilliseconds:    500,
+                                                               MaxRetries:     
              3,
+                                                               
TimeToLiveSeconds:            60,
+                                                               
OperationTimeoutMilliseconds: 500,
+                                                       },
+                                               },
+                                       },
+                                       Authority: v1alpha1.Auth{
+                                               Users: []v1alpha1.User{
+                                                       {
+                                                               User:     
"John",
+                                                               Password: 
"123456",
+                                                       },
+                                               },
+                                               Privilege: &v1alpha1.Privilege{
+                                                       Type: "Admin",
+                                               },
+                                       },
+                                       Props: &v1alpha1.Props{
+                                               KernelExecutorSize:             
   16,
+                                               CheckTableMetadataEnabled:      
   false,
+                                               ProxyBackendQueryFetchSize:     
   -1,
+                                               CheckDuplicateTableEnabled:     
   false,
+                                               ProxyFrontendExecutorSize:      
   0,
+                                               ProxyBackendExecutorSuitable:   
   "OLAP",
+                                               ProxyBackendDriverType:         
   "JDBC",
+                                               
ProxyFrontendDatabaseProtocolType: "",
+                                       },
+                               },
+                       },
+                       exp: `mode:
+  type: Cluster
+  repository:
+    type: Zookeeper
+    props:
+      namespace: cluster-sharding-mode
+      server-lists: host1:2181,host2:2181
+      retryIntervalMilliseconds: 500
+      maxRetries: 3
+      timeToLiveSeconds: 60
+      operationTimeoutMilliseconds: 500
+authority:
+  users:
+  - user: John
+    password: "123456"
+  privilege:
+    type: Admin
+props:
+  kernel-executor-size: 16
+  proxy-backend-query-fetch-size: -1
+  proxy-backend-executor-suitable: OLAP
+  proxy-backend-driver-type: JDBC
+`,
+                       message: "Should generate yaml with the same value as 
ShardingSphereProxyServerConfig.Spec",
+               },
+       }
+
+       for _, c := range cases {
+               act := toYaml(c.proxyCfg)
+               assert.Equal(t, c.exp, act, c.message)
+       }
+}

Reply via email to