Skip to content

Commit

Permalink
Rename dinosaurService#Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kovayur committed Mar 20, 2024
1 parent c2f6dfe commit ff23de5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions internal/dinosaur/pkg/services/data_plane_dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *dataPlaneCentralService) setCentralClusterFailed(centralRequest *dbapi.

centralRequest.Status = string(constants.CentralRequestStatusFailed)
centralRequest.FailedReason = fmt.Sprintf("Central reported as failed: '%s'", errMessage)
err = s.dinosaurService.Update(centralRequest)
err = s.dinosaurService.UpdateIgnoreNils(centralRequest)
if err != nil {
return serviceError.NewWithCause(err.Code, err, "failed to update central cluster to %s status for central cluster %s", constants.CentralRequestStatusFailed, centralRequest.ID)
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func (s *dataPlaneCentralService) reassignCentralCluster(centralRequest *dbapi.C
// But now we only have one OSD cluster, so we need to change the placementId field so that the fleetshard-operator will try it again
// In the future, we may consider adding a new table to track the placement history for dinosaur clusters if there are multiple OSD clusters and the value here can be the key of that table
centralRequest.PlacementID = api.NewID()
if err := s.dinosaurService.Update(centralRequest); err != nil {
if err := s.dinosaurService.UpdateIgnoreNils(centralRequest); err != nil {
return err
}
metrics.UpdateCentralRequestsStatusSinceCreatedMetric(constants.CentralRequestStatusProvisioning, centralRequest.ID, centralRequest.ClusterID, time.Since(centralRequest.CreatedAt))
Expand Down Expand Up @@ -244,7 +244,7 @@ func (s *dataPlaneCentralService) persistCentralValues(centralRequest *dbapi.Cen
return err
}

if err := s.dinosaurService.Update(centralRequest); err != nil {
if err := s.dinosaurService.UpdateIgnoreNils(centralRequest); err != nil {
return serviceError.NewWithCause(err.Code, err, "failed to update routes for central cluster %s", centralRequest.ID)
}

Expand Down
22 changes: 11 additions & 11 deletions internal/dinosaur/pkg/services/dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ type DinosaurService interface {
// same as the original status. The error will contain any error encountered when attempting to update or the reason
// why no attempt has been done
UpdateStatus(id string, status dinosaurConstants.CentralStatus) (bool, *errors.ServiceError)
// Update does NOT update nullable fields when they're nil in the request. Use Updates() instead.
Update(dinosaurRequest *dbapi.CentralRequest) *errors.ServiceError
// Updates() updates the given fields of a dinosaur. This takes in a map so that even zero-fields can be updated.
// UpdateIgnoreNils does NOT update nullable fields when they're nil in the request. Use Updates() instead.
UpdateIgnoreNils(dinosaurRequest *dbapi.CentralRequest) *errors.ServiceError
// Updates changes the given fields of a dinosaur. This takes in a map so that even zero-fields can be updated.
// Use this only when you want to update the multiple columns that may contain zero-fields, otherwise use the `DinosaurService.Update()` method.
// See https://gorm.io/docs/update.html#Updates-multiple-columns for more info
Updates(dinosaurRequest *dbapi.CentralRequest, values map[string]interface{}) *errors.ServiceError
Expand Down Expand Up @@ -167,7 +167,7 @@ func (k *dinosaurService) RotateCentralRHSSOClient(ctx context.Context, centralR
if err := rhsso.AugmentWithDynamicAuthConfig(ctx, centralRequest, k.iamConfig.RedhatSSORealm, k.rhSSODynamicClientsAPI); err != nil {
return errors.NewWithCause(errors.ErrorClientRotationFailed, err, "failed to augment auth config")
}
if err := k.Update(centralRequest); err != nil {
if err := k.UpdateIgnoreNils(centralRequest); err != nil {
glog.Errorf("Rotating RHSSO client failed: created new RHSSO dynamic client, but failed to update central record, client ID is %s", centralRequest.AuthConfig.ClientID)
return errors.NewWithCause(errors.ErrorClientRotationFailed, err, "failed to update database record")
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func (k *dinosaurService) AcceptCentralRequest(centralRequest *dbapi.CentralRequ
centralRequest.Host = clusterDNS
}

// Update the fields of the CentralRequest record in the database.
// UpdateIgnoreNils the fields of the CentralRequest record in the database.
updatedDinosaurRequest := &dbapi.CentralRequest{
Meta: api.Meta{
ID: centralRequest.ID,
Expand All @@ -348,7 +348,7 @@ func (k *dinosaurService) AcceptCentralRequest(centralRequest *dbapi.CentralRequ
Status: dinosaurConstants.CentralRequestStatusPreparing.String(),
Namespace: centralRequest.Namespace,
}
if err := k.Update(updatedDinosaurRequest); err != nil {
if err := k.UpdateIgnoreNils(updatedDinosaurRequest); err != nil {
return errors.NewWithCause(errors.ErrorGeneral, err, "failed to update central request")
}

Expand Down Expand Up @@ -381,15 +381,15 @@ func (k *dinosaurService) PrepareDinosaurRequest(dinosaurRequest *dbapi.CentralR
return errors.OrganisationNameInvalid(dinosaurRequest.OrganisationID, orgName)
}

// Update the fields of the CentralRequest record in the database.
// UpdateIgnoreNils the fields of the CentralRequest record in the database.
updatedCentralRequest := &dbapi.CentralRequest{
Meta: api.Meta{
ID: dinosaurRequest.ID,
},
OrganisationName: orgName,
Status: dinosaurConstants.CentralRequestStatusProvisioning.String(),
}
if err := k.Update(updatedCentralRequest); err != nil {
if err := k.UpdateIgnoreNils(updatedCentralRequest); err != nil {
return errors.NewWithCause(errors.ErrorGeneral, err, "failed to update central request")
}

Expand Down Expand Up @@ -689,7 +689,7 @@ func (k *dinosaurService) List(ctx context.Context, listArgs *services.ListArgum
}

// Update ...
func (k *dinosaurService) Update(dinosaurRequest *dbapi.CentralRequest) *errors.ServiceError {
func (k *dinosaurService) UpdateIgnoreNils(dinosaurRequest *dbapi.CentralRequest) *errors.ServiceError {
dbConn := k.connectionFactory.New().
Model(dinosaurRequest).
Where("status not IN (?)", dinosaurDeletionStatuses) // ignore updates of dinosaur under deletion
Expand Down Expand Up @@ -735,7 +735,7 @@ func (k *dinosaurService) VerifyAndUpdateDinosaurAdmin(ctx context.Context, dino
return errors.New(errors.ErrorValidation, fmt.Sprintf("Unable to get cluster for central %s", dinosaurRequest.ID))
}

return k.Update(dinosaurRequest)
return k.UpdateIgnoreNils(dinosaurRequest)
}

// UpdateStatus ...
Expand Down Expand Up @@ -855,7 +855,7 @@ func (k *dinosaurService) Restore(ctx context.Context, id string) *errors.Servic
}

// use a new central request, so that unset field for columnsToReset will automatically be set to the zero value
// this Update only changes columns listed in columnsToReset
// this UpdateIgnoreNils only changes columns listed in columnsToReset
resetRequest := &dbapi.CentralRequest{}
resetRequest.ID = centralRequest.ID
resetRequest.Status = dinosaurConstants.CentralRequestStatusPreparing.String()
Expand Down
42 changes: 21 additions & 21 deletions internal/dinosaur/pkg/services/dinosaurservice_moq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (k *CentralAuthConfigManager) reconcileCentralRequest(cr *dbapi.CentralRequ
cr.AuthConfig.ClientOrigin = ternary.String(k.centralConfig.HasStaticAuth(),
dbapi.AuthConfigStaticClientOrigin, dbapi.AuthConfigDynamicClientOrigin)

if err := k.centralService.Update(cr); err != nil {
if err := k.centralService.UpdateIgnoreNils(cr); err != nil {
return errors.Wrapf(err, "failed to update central request %s", cr.ID)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (k *DinosaurRoutesCNAMEManager) Reconcile() []error {
dinosaur.RoutesCreated = true
}

if err := k.dinosaurService.Update(dinosaur); err != nil {
if err := k.dinosaurService.UpdateIgnoreNils(dinosaur); err != nil {
errs = append(errs, err)
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (k *PreparingDinosaurManager) handleDinosaurRequestCreationError(dinosaurRe
metrics.IncreaseCentralTotalOperationsCountMetric(constants2.CentralOperationCreate)
dinosaurRequest.Status = string(constants2.CentralRequestStatusFailed)
dinosaurRequest.FailedReason = err.Reason
updateErr := k.dinosaurService.Update(dinosaurRequest)
updateErr := k.dinosaurService.UpdateIgnoreNils(dinosaurRequest)
if updateErr != nil {
return errors.Wrapf(updateErr, "Failed to update central %s in failed state. Central failed reason %s", dinosaurRequest.ID, dinosaurRequest.FailedReason)
}
Expand All @@ -111,7 +111,7 @@ func (k *PreparingDinosaurManager) handleDinosaurRequestCreationError(dinosaurRe
metrics.IncreaseCentralTotalOperationsCountMetric(constants2.CentralOperationCreate)
dinosaurRequest.Status = string(constants2.CentralRequestStatusFailed)
dinosaurRequest.FailedReason = err.Reason
updateErr := k.dinosaurService.Update(dinosaurRequest)
updateErr := k.dinosaurService.UpdateIgnoreNils(dinosaurRequest)
if updateErr != nil {
return errors.Wrapf(err, "Failed to update central %s in failed state", dinosaurRequest.ID)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dinosaur/pkg/workers/dinosaurmgrs/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func FailIfTimeoutExceeded(centralService services.DinosaurService, timeout time
centralRequest.Status = constants2.CentralRequestStatusFailed.String()
centralRequest.FailedReason = "Creation time went over the timeout. Interrupting central initialization."

if err := centralService.Update(centralRequest); err != nil {
if err := centralService.UpdateIgnoreNils(centralRequest); err != nil {
return errors.Wrapf(err, "failed to update timed out central %s", centralRequest.ID)
}
metrics.UpdateCentralRequestsStatusSinceCreatedMetric(constants2.CentralRequestStatusFailed, centralRequest.ID, centralRequest.ClusterID, time.Since(centralRequest.CreatedAt))
Expand Down

0 comments on commit ff23de5

Please sign in to comment.