Skip to content

Commit

Permalink
Address review comments - added message and reason to db migration st…
Browse files Browse the repository at this point in the history
…atus
  • Loading branch information
rhkp committed Oct 7, 2024
1 parent 547b77f commit 062ac5d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
14 changes: 13 additions & 1 deletion api/v1alpha08/sonataflowplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,22 @@ const (
DBMigrationStatusInProgress DBMigrationStatus = "In-Progress"
DBMigrationStatusSucceeded DBMigrationStatus = "Succeeded"
DBMigrationStatusFailed DBMigrationStatus = "Failed"

MessageDBMigrationStatusStarted string = "Started the database migrations for the services"
MessageDBMigrationStatusInProgress string = "The database migrations for the services are in-progress"
MessageDBMigrationStatusSucceeded string = "The database migrations for the services are successful"
MessageDBMigrationStatusFailed string = "The database migrations for the services have failed"

ReasonDBMigrationStatusStarted string = "Started by SonataFlow operator"
ReasonDBMigrationStatusInProgress string = "The database migration job is in-progress"
ReasonDBMigrationStatusSucceeded string = "The database migration job completed as expected"
ReasonDBMigrationStatusFailed string = "The database may be unreachable, invalid credentials supplied or flyway migration failed. Please check logs for further details."
)

type SonataFlowPlatformDBMigrationStatus struct {
Status DBMigrationStatus `json:"dbMigrationStatus,omitempty"`
Status DBMigrationStatus `json:"dbMigrationStatus,omitempty"`
Message string `json:"message,omitempty"`
Reason string `json:"reason,omitempty"`
}

// SonataFlowPlatformStatus defines the observed state of SonataFlowPlatform
Expand Down
8 changes: 8 additions & 0 deletions bundle/manifests/sonataflow.org_sonataflowplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16900,6 +16900,10 @@ spec:
properties:
dbMigrationStatus:
type: string
message:
type: string
reason:
type: string
type: object
triggers:
description: Triggers list of triggers created for the SonataFlowPlatform
Expand All @@ -16917,6 +16921,10 @@ spec:
properties:
dbMigrationStatus:
type: string
message:
type: string
reason:
type: string
type: object
required:
- name
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/sonataflow.org_sonataflowplatforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16900,6 +16900,10 @@ spec:
properties:
dbMigrationStatus:
type: string
message:
type: string
reason:
type: string
type: object
triggers:
description: Triggers list of triggers created for the SonataFlowPlatform
Expand All @@ -16917,6 +16921,10 @@ spec:
properties:
dbMigrationStatus:
type: string
message:
type: string
reason:
type: string
type: object
required:
- name
Expand Down
28 changes: 22 additions & 6 deletions internal/controller/platform/dbMigratorJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,26 @@ func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowP
return job
}

func (dbmj DBMigratorJob) ReconcileMigratorJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) error {
platform.Status.SonataFlowPlatformDBMigrationStatus = &operatorapi.SonataFlowPlatformDBMigrationStatus{
Status: operatorapi.DBMigrationStatusStarted,
func NewSonataFlowPlatformDBMigrationStatus(status v1alpha08.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationStatus {
return &operatorapi.SonataFlowPlatformDBMigrationStatus{
Status: status,
Message: message,
Reason: reason,
}
}

func UpdateSonataFlowPlatformDBMigrationStatus(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationStatus, status v1alpha08.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationStatus {
if dbMigrationStatus != nil {
dbMigrationStatus.Status = status
dbMigrationStatus.Message = message
dbMigrationStatus.Reason = reason
return dbMigrationStatus
}
return nil
}

func (dbmj DBMigratorJob) ReconcileMigratorJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) error {
platform.Status.SonataFlowPlatformDBMigrationStatus = NewSonataFlowPlatformDBMigrationStatus(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)

for {
job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, cfg.GetDBMigrationJobCfg().JobName, metav1.GetOptions{})
Expand All @@ -206,15 +222,15 @@ func (dbmj DBMigratorJob) ReconcileMigratorJob(ctx context.Context, client clien
}

klog.V(log.I).InfoS("Started to monitor the db migration job: ", "error", err)
platform.Status.SonataFlowPlatformDBMigrationStatus.Status = operatorapi.DBMigrationStatusInProgress
platform.Status.SonataFlowPlatformDBMigrationStatus = UpdateSonataFlowPlatformDBMigrationStatus(platform.Status.SonataFlowPlatformDBMigrationStatus, operatorapi.DBMigrationStatusInProgress, operatorapi.MessageDBMigrationStatusInProgress, operatorapi.ReasonDBMigrationStatusInProgress)

klog.V(log.I).InfoS("Db migration job status: ", "active", job.Status.Active, "ready", job.Status.Ready, "failed", job.Status.Failed, "success", job.Status.Succeeded, "CompletedIndexes", job.Status.CompletedIndexes, "terminatedPods", job.Status.UncountedTerminatedPods)
if job.Status.Failed > 0 {
platform.Status.SonataFlowPlatformDBMigrationStatus.Status = operatorapi.DBMigrationStatusFailed
platform.Status.SonataFlowPlatformDBMigrationStatus = UpdateSonataFlowPlatformDBMigrationStatus(platform.Status.SonataFlowPlatformDBMigrationStatus, operatorapi.DBMigrationStatusFailed, operatorapi.MessageDBMigrationStatusFailed, operatorapi.ReasonDBMigrationStatusFailed)
klog.V(log.E).InfoS("DB migrator job failed")
return errors.New("DB migrator job failed and could not complete")
} else if job.Status.Succeeded > 0 {
platform.Status.SonataFlowPlatformDBMigrationStatus.Status = operatorapi.DBMigrationStatusSucceeded
platform.Status.SonataFlowPlatformDBMigrationStatus = UpdateSonataFlowPlatformDBMigrationStatus(platform.Status.SonataFlowPlatformDBMigrationStatus, operatorapi.DBMigrationStatusSucceeded, operatorapi.MessageDBMigrationStatusSucceeded, operatorapi.ReasonDBMigrationStatusSucceeded)
klog.V(log.E).InfoS("DB migrator job completed successful")
return nil
} else {
Expand Down
8 changes: 8 additions & 0 deletions operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17434,6 +17434,10 @@ spec:
properties:
dbMigrationStatus:
type: string
message:
type: string
reason:
type: string
type: object
triggers:
description: Triggers list of triggers created for the SonataFlowPlatform
Expand All @@ -17451,6 +17455,10 @@ spec:
properties:
dbMigrationStatus:
type: string
message:
type: string
reason:
type: string
type: object
required:
- name
Expand Down

0 comments on commit 062ac5d

Please sign in to comment.