Skip to content

Commit

Permalink
Wait for MinIO to be ready before proceeding with any further tasks. (m…
Browse files Browse the repository at this point in the history
…inio#2172)

Wait for MinIO to be ready before proceeding with any further tasks

Apply suggestions from code review



Update pkg/controller/main-controller.go

Co-authored-by: Shubhendu <[email protected]>
  • Loading branch information
cniackz and shtripat authored Jun 26, 2024
1 parent 52137a2 commit d78c5e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ examples/**/obj/
public.crt
go_build_operator_
operator.iml
.run/
17 changes: 16 additions & 1 deletion pkg/controller/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ const (
MessageResourceExists = "Resource %q already exists and is not managed by MinIO Operator"
)

// Standard Events for Tenant
const (
UsersCreationFailedReason = "UsersCreationFailed"
WaitingMinIOIsHealthyReason = "WaitingMinIOIsHealthy"
)

// Standard Status messages for Tenant
const (
StatusInitialized = "Initialized"
Expand All @@ -98,6 +104,7 @@ const (
StatusProvisioningConsoleService = "Provisioning Console Service"
StatusProvisioningKESStatefulSet = "Provisioning KES StatefulSet"
StatusProvisioningInitialUsers = "Provisioning initial users"
StatusWaitingMinIOIsHealthy = "Waiting for Tenant to be healthy"
StatusProvisioningDefaultBuckets = "Provisioning default buckets"
StatusWaitingMinIOCert = "Waiting for MinIO TLS Certificate"
StatusWaitingMinIOClientCert = "Waiting for MinIO TLS Client Certificate"
Expand Down Expand Up @@ -1315,11 +1322,19 @@ func (c *Controller) syncHandler(key string) (Result, error) {
}
}

// Stay in this state until minio is ready
if tenant.Status.HealthStatus != miniov2.HealthStatusGreen {
c.updateTenantStatus(ctx, tenant, StatusWaitingMinIOIsHealthy, 0)
c.recorder.Event(tenant, corev1.EventTypeWarning, WaitingMinIOIsHealthyReason, fmt.Sprintf("Waiting for MinIO to be ready: %s", err))
// retry after 5sec
return WrapResult(Result{RequeueAfter: time.Second * 5}, nil)
}

// Ensure we are only provisioning users one time
if !tenant.Status.ProvisionedUsers && len(tenant.Spec.Users) > 0 {
if err := c.createUsers(ctx, tenant, tenantConfiguration); err != nil {
klog.V(2).Infof("Unable to create MinIO users: %v", err)
c.recorder.Event(tenant, corev1.EventTypeWarning, "UsersCreatedFailed", fmt.Sprintf("Users creation failed: %s", err))
c.recorder.Event(tenant, corev1.EventTypeWarning, UsersCreationFailedReason, fmt.Sprintf("Users creation failed: %s", err))
// retry after 5sec
return WrapResult(Result{RequeueAfter: time.Second * 5}, nil)
}
Expand Down

0 comments on commit d78c5e0

Please sign in to comment.