func()

in shardingsphere-operator/pkg/reconcile/storagenode/aws/rdscluster.go [163:197]


func (c *RdsClient) DeleteRDSCluster(ctx context.Context, node *v1alpha1.StorageNode, storageProvider *v1alpha1.StorageProvider) error {
	identifier, ok := node.Annotations[v1alpha1.AnnotationsClusterIdentifier]
	if !ok {
		return fmt.Errorf("cluster identifier is empty")
	}

	cc := c.Cluster()
	cc.SetDBClusterIdentifier(identifier)

	cluster, err := cc.Describe(ctx)
	if err != nil {
		return fmt.Errorf("describe rds cluster failed, %v", err)
	}
	if cluster == nil || cluster.Status == string(rds.DBClusterStatusDeleting) {
		return nil
	}

	switch storageProvider.Spec.ReclaimPolicy {
	case v1alpha1.StorageReclaimPolicyDelete:
		cc.SetSkipFinalSnapshot(true)
	case v1alpha1.StorageReclaimPolicyDeleteWithFinalSnapshot:
		if v, ok := node.Annotations[v1alpha1.AnnotationsFinalSnapshotIdentifier]; !ok || v == "" {
			return fmt.Errorf("final snapshot identifier is empty")
		}
		if cluster.Status != string(rds.DBClusterStatusAvailable) {
			return fmt.Errorf("rds cluster is not available, can not delete with final snapshot")
		}
		cc.SetFinalDBSnapshotIdentifier(node.Annotations[v1alpha1.AnnotationsFinalSnapshotIdentifier])
		cc.SetSkipFinalSnapshot(false)
	case v1alpha1.StorageReclaimPolicyRetain:
		return fmt.Errorf("rds cluster does not support retain policy")
	}

	return cc.Delete(ctx)
}