Xu-Wentao commented on code in PR #345:
URL:
https://github.com/apache/shardingsphere-on-cloud/pull/345#discussion_r1188235424
##########
shardingsphere-operator/pkg/controllers/storage_node_controller.go:
##########
@@ -303,28 +355,81 @@ 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 {
switch databaseClass.Spec.Provisioner {
case dbmeshv1alpha1.ProvisionerAWSRDSInstance:
+ instance := &rds.DescInstance{}
+ ins, err := aws.NewRdsClient(r.AwsRDS).GetInstance(ctx, node)
+ if err != nil {
+ return err
+ }
+ if reflect.DeepEqual(ins, instance) || ins.DBInstanceStatus ==
v1alpha1.StorageNodeInstanceStatusDeleting {
+ return nil
+ }
if err := aws.NewRdsClient(r.AwsRDS).DeleteInstance(ctx, node,
databaseClass); err != nil {
return err
}
+ node.Status.Phase = v1alpha1.StorageNodePhaseDeleting
Review Comment:
- I think this we just do update on `node.Instances.status`
- the `node.status` may should not be changed here, and can be modified in
`computeDesiredStatus`, at the same time, `computeDesiredStatus` just change
`node.status` and should not to get or check instance status.
--
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]