You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by mi...@apache.org on 2023/05/17 10:58:37 UTC

[shardingsphere-on-cloud] branch main updated: chore: update aws instance status code

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

miaoliyao 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 7105e06  chore: update aws instance status code
     new 317eec7  Merge pull request #369 from yikuaibro/aws_instance_code
7105e06 is described below

commit 7105e06270261a948f3fc827814e2e0b0f5d7909
Author: li <13...@qq.com>
AuthorDate: Wed May 17 17:27:34 2023 +0800

    chore: update aws instance status code
---
 .../api/v1alpha1/storage_node_types.go                 | 16 ----------------
 .../pkg/controllers/storage_ndoe_controller_test.go    | 18 +++++++++---------
 .../pkg/controllers/storage_node_controller.go         |  8 ++++----
 .../pkg/reconcile/storagenode/aws/rdsinstance.go       |  2 +-
 .../test/e2e/storage_node_controller_test.go           |  4 ++--
 5 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/shardingsphere-operator/api/v1alpha1/storage_node_types.go b/shardingsphere-operator/api/v1alpha1/storage_node_types.go
index 8f35a33..f3bc6df 100644
--- a/shardingsphere-operator/api/v1alpha1/storage_node_types.go
+++ b/shardingsphere-operator/api/v1alpha1/storage_node_types.go
@@ -149,22 +149,6 @@ type StorageNodeStatus struct {
 	Registered bool `json:"registered,omitempty"`
 }
 
-const (
-	StorageNodeInstanceStatusAvailable = "available"
-	StorageNodeInstanceStatusBackingUp = "backing-up"
-	StorageNodeInstanceStatusCreating  = "creating"
-	StorageNodeInstanceStatusDeleting  = "deleting"
-	StorageNodeInstanceStatusFailed    = "failed"
-	StorageNodeInstanceStatusModifying = "modifying"
-	StorageNodeInstanceStatusRebooting = "rebooting"
-	StorageNodeInstanceStatusRenaming  = "renaming"
-	StorageNodeInstanceStatusStarting  = "starting"
-	StorageNodeInstanceStatusStopped   = "stopped"
-	StorageNodeInstanceStatusStopping  = "stopping"
-
-	StorageNodeInstanceStatusReady = "Ready"
-)
-
 // AddCondition adds the given condition to the StorageNodeConditions.
 func (c *StorageNodeConditions) AddCondition(condition *StorageNodeCondition) {
 	*c = append(*c, condition)
diff --git a/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go b/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go
index 245facf..e97255e 100644
--- a/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go
+++ b/shardingsphere-operator/pkg/controllers/storage_ndoe_controller_test.go
@@ -194,7 +194,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 			}
 
 			rdsInstance := &dbmesh_rds.DescInstance{
-				DBInstanceStatus: v1alpha1.StorageNodeInstanceStatusCreating,
+				DBInstanceStatus: dbmesh_rds.DBInstanceStatusCreating,
 				Endpoint: dbmesh_rds.Endpoint{
 					Address: "127.0.0.1",
 					Port:    3306,
@@ -211,7 +211,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 			Expect(fakeClient.Get(ctx, client.ObjectKey{Name: "test-storage-node", Namespace: "test-namespace"}, newSN)).Should(Succeed())
 			Expect(newSN.Status.Phase).To(Equal(v1alpha1.StorageNodePhaseNotReady))
 			Expect(newSN.Status.Instances).To(HaveLen(1))
-			Expect(newSN.Status.Instances[0].Status).To(Equal(v1alpha1.StorageNodeInstanceStatusCreating))
+			Expect(newSN.Status.Instances[0].Status).To(Equal(string(dbmesh_rds.DBInstanceStatusCreating)))
 		})
 
 		It("should reconcile successfully with Available Instance", func() {
@@ -223,7 +223,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 			}
 
 			rdsInstance := &dbmesh_rds.DescInstance{
-				DBInstanceStatus: v1alpha1.StorageNodeInstanceStatusAvailable,
+				DBInstanceStatus: dbmesh_rds.DBInstanceStatusAvailable,
 				Endpoint: dbmesh_rds.Endpoint{
 					Address: "127.0.0.1",
 					Port:    3306,
@@ -240,7 +240,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 
 			Expect(newSN.Status.Phase).To(Equal(v1alpha1.StorageNodePhaseReady))
 			Expect(newSN.Status.Instances).To(HaveLen(1))
-			Expect(newSN.Status.Instances[0].Status).To(Equal(v1alpha1.StorageNodeInstanceStatusReady))
+			Expect(newSN.Status.Instances[0].Status).To(Equal(string(dbmesh_rds.DBInstanceStatusReady)))
 		})
 	})
 
@@ -248,7 +248,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 		var (
 			rdsInstanceAvailable = dbmesh_rds.DescInstance{
 				DBInstanceIdentifier: defaultTestInstanceIdentifier,
-				DBInstanceStatus:     v1alpha1.StorageNodeInstanceStatusAvailable,
+				DBInstanceStatus:     dbmesh_rds.DBInstanceStatusAvailable,
 				Endpoint: dbmesh_rds.Endpoint{
 					Address: "127.0.0.1",
 					Port:    3306,
@@ -256,7 +256,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 			}
 			instanceInDeleting = dbmesh_rds.DescInstance{
 				DBInstanceIdentifier: defaultTestInstanceIdentifier,
-				DBInstanceStatus:     v1alpha1.StorageNodeInstanceStatusDeleting,
+				DBInstanceStatus:     dbmesh_rds.DBInstanceStatusDeleting,
 				Endpoint: dbmesh_rds.Endpoint{
 					Address: "127.0.0.1",
 					Port:    3306,
@@ -333,7 +333,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 					Phase: v1alpha1.StorageNodePhaseDeleting,
 					Instances: []v1alpha1.InstanceStatus{
 						{
-							Status: v1alpha1.StorageNodeInstanceStatusDeleting,
+							Status: string(dbmesh_rds.DBInstanceStatusDeleting),
 							Endpoint: v1alpha1.Endpoint{
 								Address: "127.0.0.1",
 								Port:    3306,
@@ -426,7 +426,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 			}
 			ins := &dbmesh_rds.DescInstance{
 				DBInstanceIdentifier: "ins-test-register-storage-node",
-				DBInstanceStatus:     v1alpha1.StorageNodeInstanceStatusAvailable,
+				DBInstanceStatus:     dbmesh_rds.DBInstanceStatusAvailable,
 				Endpoint: dbmesh_rds.Endpoint{
 					Address: "127.0.0.1",
 					Port:    3306,
@@ -638,7 +638,7 @@ var _ = Describe("StorageNode Controller Mock Test", func() {
 					Phase: v1alpha1.StorageNodePhaseReady,
 					Instances: []v1alpha1.InstanceStatus{
 						{
-							Status:   v1alpha1.StorageNodeInstanceStatusAvailable,
+							Status:   string(dbmesh_rds.DBInstanceStatusAvailable),
 							Endpoint: v1alpha1.Endpoint{},
 						},
 					},
diff --git a/shardingsphere-operator/pkg/controllers/storage_node_controller.go b/shardingsphere-operator/pkg/controllers/storage_node_controller.go
index a4d9ecf..eeb0c89 100644
--- a/shardingsphere-operator/pkg/controllers/storage_node_controller.go
+++ b/shardingsphere-operator/pkg/controllers/storage_node_controller.go
@@ -226,7 +226,7 @@ func computeDesiredState(status v1alpha1.StorageNodeStatus) v1alpha1.StorageNode
 
 	for idx := range status.Instances {
 		ins := &status.Instances[idx]
-		if ins.Status == v1alpha1.StorageNodeInstanceStatusDeleting {
+		if ins.Status == string(rds.DBInstanceStatusDeleting) {
 			desiredState.Phase = v1alpha1.StorageNodePhaseDeleting
 		}
 	}
@@ -350,8 +350,8 @@ func updateAWSRDSInstanceStatus(node *v1alpha1.StorageNode, instance *rds.DescIn
 	instances := make([]v1alpha1.InstanceStatus, 0)
 
 	status := instance.DBInstanceStatus
-	if status == v1alpha1.StorageNodeInstanceStatusAvailable {
-		status = v1alpha1.StorageNodeInstanceStatusReady
+	if status == rds.DBInstanceStatusAvailable {
+		status = rds.DBInstanceStatusReady
 	}
 
 	instances = append(instances, v1alpha1.InstanceStatus{
@@ -454,7 +454,7 @@ func (r *StorageNodeReconciler) deleteAWSRDSInstance(ctx context.Context, client
 		return nil
 	}
 
-	if instance.DBInstanceStatus == v1alpha1.StorageNodeInstanceStatusDeleting {
+	if instance.DBInstanceStatus == rds.DBInstanceStatusDeleting {
 		r.Log.Info(fmt.Sprintf("instance %s is deleting", node.Annotations[dbmeshv1alpha1.AnnotationsInstanceIdentifier]))
 		return nil
 	}
diff --git a/shardingsphere-operator/pkg/reconcile/storagenode/aws/rdsinstance.go b/shardingsphere-operator/pkg/reconcile/storagenode/aws/rdsinstance.go
index bd5c27d..0907fd9 100644
--- a/shardingsphere-operator/pkg/reconcile/storagenode/aws/rdsinstance.go
+++ b/shardingsphere-operator/pkg/reconcile/storagenode/aws/rdsinstance.go
@@ -189,7 +189,7 @@ func (c *RdsClient) DeleteInstance(ctx context.Context, node *v1alpha1.StorageNo
 		return err
 	}
 
-	if ins == nil || ins.DBInstanceStatus == v1alpha1.StorageNodeInstanceStatusDeleting {
+	if ins == nil || ins.DBInstanceStatus == rds.DBInstanceStatusDeleting {
 		return nil
 	}
 
diff --git a/shardingsphere-operator/test/e2e/storage_node_controller_test.go b/shardingsphere-operator/test/e2e/storage_node_controller_test.go
index 68264ed..255ec71 100644
--- a/shardingsphere-operator/test/e2e/storage_node_controller_test.go
+++ b/shardingsphere-operator/test/e2e/storage_node_controller_test.go
@@ -77,7 +77,7 @@ var _ = Describe("StorageNode Controller Suite Test", func() {
 			// mock get instance func returns success
 			monkey.PatchInstanceMethod(reflect.TypeOf(&aws.RdsClient{}), "GetInstance", func(_ *aws.RdsClient, _ context.Context, _ *v1alpha1.StorageNode) (*dbmesh_rds.DescInstance, error) {
 				return &dbmesh_rds.DescInstance{
-					DBInstanceStatus: v1alpha1.StorageNodeInstanceStatusAvailable,
+					DBInstanceStatus: dbmesh_rds.DBInstanceStatusAvailable,
 					Endpoint: dbmesh_rds.Endpoint{
 						Address: "127.0.0.1",
 						Port:    3306,
@@ -155,7 +155,7 @@ var _ = Describe("StorageNode Controller Suite Test", func() {
 			// mock rds DescribeDBInstances func returns success
 			monkey.PatchInstanceMethod(reflect.TypeOf(&aws.RdsClient{}), "GetInstance", func(_ *aws.RdsClient, _ context.Context, _ *v1alpha1.StorageNode) (*dbmesh_rds.DescInstance, error) {
 				return &dbmesh_rds.DescInstance{
-					DBInstanceStatus: v1alpha1.StorageNodeInstanceStatusAvailable,
+					DBInstanceStatus: dbmesh_rds.DBInstanceStatusAvailable,
 					Endpoint: dbmesh_rds.Endpoint{
 						Address: "127.0.0.1",
 						Port:    3306,