You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/01/20 09:00:16 UTC

[shardingsphere-on-cloud] branch main updated: feat: add nodeport write back to ComputeNode

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

panjuan 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 82db52d  feat: add nodeport write back to ComputeNode
     new 54dfc66  Merge pull request #187 from mlycore/write-back-nodeport
82db52d is described below

commit 82db52d75999fe69c8299f0b0db09843400d085a
Author: mlycore <ma...@126.com>
AuthorDate: Fri Jan 20 16:56:35 2023 +0800

    feat: add nodeport write back to ComputeNode
    
    Signed-off-by: mlycore <ma...@126.com>
---
 .../pkg/controllers/compute_node_controller.go     | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/shardingsphere-operator/pkg/controllers/compute_node_controller.go b/shardingsphere-operator/pkg/controllers/compute_node_controller.go
index 88f931d..6026a7f 100644
--- a/shardingsphere-operator/pkg/controllers/compute_node_controller.go
+++ b/shardingsphere-operator/pkg/controllers/compute_node_controller.go
@@ -55,6 +55,7 @@ func (r *ComputeNodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
 	return ctrl.NewControllerManagedBy(mgr).
 		For(&v1alpha1.ComputeNode{}).
 		Owns(&appsv1.Deployment{}).
+		Owns(&v1.Pod{}).
 		Owns(&v1.Service{}).
 		Owns(&v1.ConfigMap{}).
 		Complete(r)
@@ -166,6 +167,34 @@ func (r *ComputeNodeReconciler) reconcileService(ctx context.Context, cn *v1alph
 			return err
 		}
 	}
+
+	if cn.Spec.ServiceType == v1.ServiceTypeNodePort {
+		for _, p := range cur.Spec.Ports {
+			for idx := range cn.Spec.PortBindings {
+				if p.Name == cn.Spec.PortBindings[idx].Name {
+					if cn.Spec.PortBindings[idx].NodePort == 0 {
+						cn.Spec.PortBindings[idx].NodePort = p.NodePort
+						if err := r.Update(ctx, cn); err != nil {
+							return err
+						}
+					}
+					break
+				}
+			}
+		}
+	}
+	if cn.Spec.ServiceType == v1.ServiceTypeClusterIP {
+		for idx := range cn.Spec.PortBindings {
+			if cn.Spec.PortBindings[idx].NodePort != 0 {
+				cn.Spec.PortBindings[idx].NodePort = 0
+				if err := r.Update(ctx, cn); err != nil {
+					return err
+				}
+				break
+			}
+		}
+	}
+
 	// update
 	exp := reconcile.ComputeNodeUpdateService(cn, cur)
 	if err := r.Update(ctx, exp); err != nil {