Skip to content

Commit

Permalink
auto-pause checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancon committed Jun 25, 2024
1 parent 81861cf commit 57bb762
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
23 changes: 21 additions & 2 deletions internal/controller/bucket/bucket_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ func (b *bucketBackends) isLifecycleConfigRemovedFromBackends(bucket *v1alpha1.B

// isVersioningConfigAvailableOnBackends checks the backends listed in providerNames against
// bucketBackends to ensure versioning configurations are considered Available on all desired backends.
func (b *bucketBackends) isVersioningConfigAvailableOnBackends(bucket *v1alpha1.Bucket, providerNames []string, c map[string]backendstore.S3Client) bool {
func (b *bucketBackends) isVersioningConfigAvailableOnBackends(bucketName string, providerNames []string, c map[string]backendstore.S3Client) bool {
for _, backendName := range providerNames {
if _, ok := c[backendName]; !ok {
// This backend does not exist in the list of available backends.
// The backend may be offline, so it is skipped.
continue
}

vCondition := b.getVersioningConfigCondition(bucket.Name, backendName)
vCondition := b.getVersioningConfigCondition(bucketName, backendName)
if vCondition == nil {
// The versioningconfig has not been created on this backend.
return false
Expand All @@ -242,3 +242,22 @@ func (b *bucketBackends) isVersioningConfigAvailableOnBackends(bucket *v1alpha1.

return true
}

// isVersioningConfigRemovedFromBackends checks the backends listed in providerNames against
// bucketBackends to verify a versioning configuration does not exist on any backend.
func (b *bucketBackends) isVersioningConfigRemovedFromBackends(bucketName string, providerNames []string, c map[string]backendstore.S3Client) bool {
for _, backendName := range providerNames {
if _, ok := c[backendName]; !ok {
// This backend does not exist in the list of available backends.
// The backend may be offline, so it is skipped.
continue
}

vCondition := b.getVersioningConfigCondition(bucketName, backendName)
if vCondition != nil {
return false
}
}

return true
}
7 changes: 4 additions & 3 deletions internal/controller/bucket/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func isPauseRequired(bucket *v1alpha1.Bucket, providerNames []string, minReplica
return false
}

// If versioning config is specified in the spec, we should only pause once the
// versioning config is available on all backends.
if bucket.Spec.ForProvider.VersioningConfiguration != nil && !bb.isVersioningConfigAvailableOnBackends(bucket, providerNames, c) {
// We should avoid pausing when versioning configurations exist on backends, but not all
// versioning configs are available.
if !bb.isVersioningConfigRemovedFromBackends(bucket.Name, providerNames, c) && !bb.isVersioningConfigAvailableOnBackends(bucket.Name, providerNames, c) {

return false
}

Expand Down

0 comments on commit 57bb762

Please sign in to comment.