Commit 7e6778ef authored by Brian Downs's avatar Brian Downs

remove unnecessary code

parent 49073cd2
...@@ -979,58 +979,53 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error { ...@@ -979,58 +979,53 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error {
} }
if e.config.EtcdS3 { if e.config.EtcdS3 {
logrus.Info("Removing the given etcd snapshot from S3") logrus.Info("Removing the given etcd snapshot(s) from S3")
logrus.Debugf("Removing the given etcd snapshot from S3: %v", snapshots) logrus.Debugf("Removing the given etcd snapshot from S3: %v", snapshots)
if e.initS3IfNil(ctx); err != nil { if e.initS3IfNil(ctx); err != nil {
return err return err
} }
if len(snapshots) > 1 { objectsCh := make(chan minio.ObjectInfo)
logrus.Info("Removing the given etcd snapshot(s) from S3")
objectsCh := make(chan minio.ObjectInfo) toCtx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout)
defer cancel()
toCtx, cancel := context.WithTimeout(ctx, time.Second*30) go func(ctx context.Context) {
defer cancel() defer close(objectsCh)
go func(ctx context.Context) { for {
defer close(objectsCh) select {
case <-ctx.Done():
return
default:
opts := minio.ListObjectsOptions{
Recursive: true,
}
for { for obj := range e.s3.client.ListObjects(ctx, e.config.EtcdS3BucketName, opts) {
select { if obj.Err != nil {
case <-ctx.Done(): logrus.Error(obj.Err)
return continue
default: }
for obj := range e.s3.client.ListObjects(ctx, e.config.EtcdS3BucketName, minio.ListObjectsOptions{}) {
if obj.Err != nil {
logrus.Error(obj.Err)
continue
}
// iterate through the given snapshots and only // iterate through the given snapshots and only
// add them to the channel for remove if they're // add them to the channel for remove if they're
// actually found from the bucket listing. // actually found from the bucket listing.
for _, snapshot := range snapshots { for _, snapshot := range snapshots {
if snapshot == obj.Key { logrus.Warnf("snapshot: %s - obj.Key: %s\n", snapshot, obj.Key)
objectsCh <- obj if snapshot == obj.Key {
} objectsCh <- obj
} }
} }
} }
return
} }
}(toCtx)
for roErr := range e.s3.client.RemoveObjects(ctx, e.config.EtcdS3BucketName, objectsCh, minio.RemoveObjectsOptions{}) {
logrus.Errorf("Error detected during deletion: %v", roErr)
} }
}(toCtx)
return e.StoreSnapshotData(ctx) for roErr := range e.s3.client.RemoveObjects(ctx, e.config.EtcdS3BucketName, objectsCh, minio.RemoveObjectsOptions{}) {
} logrus.Errorf("Unable to delete snapshot: %v", roErr)
if err = e.s3.client.RemoveObject(ctx, e.config.EtcdS3BucketName, snapshots[0], minio.RemoveObjectOptions{}); err != nil {
return errors.Wrap(err, "error detected during deletion")
} }
return e.StoreSnapshotData(ctx) return e.StoreSnapshotData(ctx)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment