Skip to content

Commit

Permalink
Fix issue with snapshot metadata configmap
Browse files Browse the repository at this point in the history
Omit snapshot list configmap entries for snapshots without extra metadata; reduce log level of warnings about missing s3 metadata files.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Nov 14, 2023
1 parent f5920d7 commit f01765b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 10 additions & 2 deletions pkg/etcd/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,18 @@ func (s *S3) listSnapshots(ctx context.Context) (map[string]snapshotFile, error)
if sf, ok := snapshots[sfKey]; ok {
logrus.Debugf("Loading snapshot metadata from s3://%s/%s", s.config.EtcdS3BucketName, metadataKey)
if obj, err := s.client.GetObject(ctx, s.config.EtcdS3BucketName, metadataKey, minio.GetObjectOptions{}); err != nil {
logrus.Warnf("Failed to get snapshot metadata: %v", err)
if isNotExist(err) {
logrus.Debugf("Failed to get snapshot metadata: %v", err)
} else {
logrus.Warnf("Failed to get snapshot metadata for %s: %v", filename, err)
}
} else {
if m, err := ioutil.ReadAll(obj); err != nil {
logrus.Warnf("Failed to read snapshot metadata: %v", err)
if isNotExist(err) {
logrus.Debugf("Failed to read snapshot metadata: %v", err)
} else {
logrus.Warnf("Failed to read snapshot metadata for %s: %v", filename, err)
}
} else {
sf.Metadata = base64.StdEncoding.EncodeToString(m)
snapshots[sfKey] = sf
Expand Down
12 changes: 8 additions & 4 deletions pkg/etcd/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func (e *etcdSnapshotHandler) sync(key string, esf *apisv1.ETCDSnapshotFile) (*a
}
return nil, err
}
if esf == nil || !esf.DeletionTimestamp.IsZero() {

// Do not create entries for snapshots that have been deleted or do not have extra metadata
if esf == nil || !esf.DeletionTimestamp.IsZero() || len(esf.Spec.Metadata) == 0 {
return nil, nil
}

Expand Down Expand Up @@ -209,10 +211,12 @@ func (e *etcdSnapshotHandler) reconcile() error {
snapshots := map[string]*apisv1.ETCDSnapshotFile{}
for i := range snapshotList.Items {
esf := &snapshotList.Items[i]
if esf.DeletionTimestamp.IsZero() {
sfKey := generateETCDSnapshotFileConfigMapKey(*esf)
snapshots[sfKey] = esf
// Do not create entries for snapshots that have been deleted or do not have extra metadata
if !esf.DeletionTimestamp.IsZero() || len(esf.Spec.Metadata) == 0 {
continue
}
sfKey := generateETCDSnapshotFileConfigMapKey(*esf)
snapshots[sfKey] = esf
}

// Make a copy of the configmap for change detection
Expand Down

0 comments on commit f01765b

Please sign in to comment.