Xu-Wentao commented on code in PR #345:
URL:
https://github.com/apache/shardingsphere-on-cloud/pull/345#discussion_r1188093540
##########
shardingsphere-operator/pkg/controllers/storage_node_controller.go:
##########
@@ -197,21 +218,29 @@ func computeDesiredState(status
v1alpha1.StorageNodeStatus) v1alpha1.StorageNode
desiredState.Phase = v1alpha1.StorageNodePhaseNotReady
}
+ if status.Phase == v1alpha1.StorageNodePhaseDeleting {
+ desiredState.Phase = v1alpha1.StorageNodePhaseDeleting
+ } else if status.Phase == v1alpha1.StorageNodePhaseDeleteComplete {
+ desiredState.Phase = v1alpha1.StorageNodePhaseDeleteComplete
+ }
+
Review Comment:
in deleting situation, the `desiredStatus` should synced from the instance
or cluster's status. By checking the instance or cluster is deleting status or
not.
##########
shardingsphere-operator/pkg/controllers/storage_node_controller.go:
##########
@@ -163,15 +165,34 @@ func (r *StorageNodeReconciler) finalize(ctx
context.Context, node *v1alpha1.Sto
}
}
} else if containsString(node.ObjectMeta.Finalizers, FinalizerName) {
+ switch node.Status.Phase {
+ case v1alpha1.StorageNodePhaseDeleting:
+ instance := &rds.DescInstance{}
+ ins, err := aws.NewRdsClient(r.AwsRDS).GetInstance(ctx,
node)
+ if err != nil {
+ return err
+ }
+ if reflect.DeepEqual(ins, instance) {
+ node.Status.Phase =
v1alpha1.StorageNodePhaseDeleteComplete
+ if err := r.Update(ctx, node); err != nil {
+ return err
+ }
+ r.Log.Info("RDS instance has been successfully
deleted")
+ return nil
+ }
+ r.Log.Info("RDS instance is still deleting")
+ return nil
+ case v1alpha1.StorageNodePhaseDeleteComplete:
+ // remove our finalizer from the list and update it.
+ node.ObjectMeta.Finalizers =
removeString(node.ObjectMeta.Finalizers, FinalizerName)
+ return r.Update(ctx, node)
+ case v1alpha1.StorageNodePhaseReady,
v1alpha1.StorageNodePhaseNotReady:
+ break
Review Comment:
move `deleteDatabaseCluster` to there, to make sure to delete database
cluster or instance only `StorageNode` is in `ready` or `not ready` phase.
##########
shardingsphere-operator/pkg/controllers/storage_node_controller.go:
##########
@@ -303,28 +334,80 @@ func updateInstanceStatus(node *v1alpha1.StorageNode,
instance *rds.DescInstance
func (r *StorageNodeReconciler) reconcileAwsAurora(ctx context.Context, client
aws.IRdsClient, node *v1alpha1.StorageNode, dbClass
*dbmeshv1alpha1.DatabaseClass) error {
// get instance
- instance, err := client.GetAuroraCluster(ctx, node)
+ aurora, err := client.GetAuroraCluster(ctx, node)
if err != nil {
return err
}
- if instance == nil {
+ if aurora == nil {
// create instance
err = client.CreateAuroraCluster(ctx, node,
dbClass.Spec.Parameters)
if err != nil {
return err
}
}
// TODO: update storage node status
+ newStatus, err := updateClusterStatus(ctx, node, client, aurora)
+ if err != nil {
+ return err
+ }
+ node.Status.Cluster = newStatus
+ if err := r.Status().Update(ctx, node); err != nil {
+ r.Log.Error(err, fmt.Sprintf("Failed to update cluster status
for node [%s:%s]", node.GetNamespace(), node.GetName()))
+ }
+ r.Recorder.Eventf(node, corev1.EventTypeNormal, "Reconcile",
"Reconciled Aurora cluster %s, status is %s", aurora.DBClusterIdentifier,
aurora.Status)
+
return nil
}
+func updateClusterStatus(ctx context.Context, node *v1alpha1.StorageNode,
client aws.IRdsClient, cluster *rds.DescCluster) (v1alpha1.ClusterStatus,
error) {
+ clusterStatus := v1alpha1.ClusterStatus{
+ PrimaryEndpoint: v1alpha1.Endpoint{
+ Address: cluster.PrimaryEndpoint,
+ Port: cluster.Port,
+ },
+ }
+ status := cluster.Status
+ if status == "available" {
+ status = "Ready"
+ }
+ clusterStatus.Status = status
+
+ if len(cluster.ReadReplicaIdentifiers) == 0 {
+ clusterStatus.ReaderEndpoints = []v1alpha1.Endpoint{}
+ return clusterStatus, nil
+ } else {
+
+ for _, readident := range cluster.ReadReplicaIdentifiers {
+ instance, err := client.GetInstanceByIdentifier(ctx,
readident)
+ if err != nil {
+ return clusterStatus, err
+ }
+
+ clusterStatus.ReaderEndpoints =
append(clusterStatus.ReaderEndpoints, v1alpha1.Endpoint{
+ Address: instance.Endpoint.Address,
+ Port: instance.Endpoint.Port,
+ })
+ }
+ return clusterStatus, nil
+ }
+}
+
// deleteDatabaseCluster
func (r *StorageNodeReconciler) deleteDatabaseCluster(ctx context.Context,
node *v1alpha1.StorageNode, databaseClass *dbmeshv1alpha1.DatabaseClass) error {
+ ins, err := aws.NewRdsClient(r.AwsRDS).GetInstance(ctx, node)
Review Comment:
`GetInstance` is used for getting aws rds insatnce, plz set these code in
`ase dbmeshv1alpha1.ProvisionerAWSRDSInstance:` space
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]