Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
parametalol committed Sep 12, 2023
1 parent 7682b77 commit 4b7461c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
15 changes: 0 additions & 15 deletions internal/dinosaur/pkg/services/dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ type DinosaurService interface {
ListCentralsWithoutAuthConfig() ([]*dbapi.CentralRequest, *errors.ServiceError)
VerifyAndUpdateDinosaurAdmin(ctx context.Context, dinosaurRequest *dbapi.CentralRequest) *errors.ServiceError
Restore(ctx context.Context, id string) *errors.ServiceError
// IsQuotaEntitlementActive checks if the user/organisation have an active entitlement to the quota
// used by the given Central instance.
//
// It returns true if the user has an active quota entitlement and false if not.
// It returns false and an error if it encounters any issues while trying to check the quota entitlement status.
IsQuotaEntitlementActive(centralRequest *dbapi.CentralRequest) (bool, error)
}

var _ DinosaurService = &dinosaurService{}
Expand Down Expand Up @@ -949,12 +943,3 @@ func buildResourceRecordChange(recordName string, clusterIngress string, action

return resourceRecordChange
}

func (k *dinosaurService) IsQuotaEntitlementActive(centralRequest *dbapi.CentralRequest) (bool, error) {
quotaService, factoryErr := k.quotaServiceFactory.GetQuotaService(api.QuotaType(k.dinosaurConfig.Quota.Type))
if factoryErr != nil {
return false, factoryErr
}

return quotaService.IsQuotaEntitlementActive(centralRequest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type DinosaurRoutesCNAMEManager struct {
var _ workers.Worker = &DinosaurRoutesCNAMEManager{}

// NewDinosaurCNAMEManager ...
func NewDinosaurCNAMEManager(dinosaurService services.DinosaurService, kafkfConfig *config.CentralConfig) *DinosaurRoutesCNAMEManager {
func NewDinosaurCNAMEManager(dinosaurService services.DinosaurService, dinosaurConfig *config.CentralConfig) *DinosaurRoutesCNAMEManager {
metrics.InitReconcilerMetricsForType(centralDNSWorkerType)
return &DinosaurRoutesCNAMEManager{
BaseWorker: workers.BaseWorker{
Expand All @@ -31,7 +31,7 @@ func NewDinosaurCNAMEManager(dinosaurService services.DinosaurService, kafkfConf
Reconciler: workers.Reconciler{},
},
dinosaurService: dinosaurService,
dinosaurConfig: kafkfConfig,
dinosaurConfig: dinosaurConfig,
}
}

Expand Down
22 changes: 17 additions & 5 deletions internal/dinosaur/pkg/workers/dinosaurmgrs/grace_period_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ import (
"github.com/pkg/errors"
constants "github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/dbapi"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/config"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/services"
"github.com/stackrox/acs-fleet-manager/pkg/api"
serviceErr "github.com/stackrox/acs-fleet-manager/pkg/errors"
"github.com/stackrox/acs-fleet-manager/pkg/workers"
)

// GracePeriodManager represents a dinosaur manager that manages grace period date.
type GracePeriodManager struct {
workers.BaseWorker
dinosaurService services.DinosaurService
dinosaurService services.DinosaurService
quotaServiceFactory services.QuotaServiceFactory
dinosaurConfig *config.CentralConfig
}

// NewGracePeriodManager creates a new grace period manager
func NewGracePeriodManager(dinosaurService services.DinosaurService) *DinosaurManager {
return &DinosaurManager{
func NewGracePeriodManager(dinosaurService services.DinosaurService, quotaServiceFactory services.QuotaServiceFactory, dinosaur *config.CentralConfig) *GracePeriodManager {
return &GracePeriodManager{
BaseWorker: workers.BaseWorker{
ID: uuid.New().String(),
WorkerType: "grace_period_worker",
Reconciler: workers.Reconciler{},
},
dinosaurService: dinosaurService,
dinosaurService: dinosaurService,
quotaServiceFactory: quotaServiceFactory,
dinosaurConfig: dinosaur,
}
}

Expand Down Expand Up @@ -87,7 +93,13 @@ func (k *GracePeriodManager) reconcileCentralGraceFrom(centrals dbapi.CentralLis
glog.Infof("checking quota entitlement status for Central instance %q", central.ID)
active, exists := subscriptionStatusByOrg[central.OrganisationID]
if !exists {
isActive, err := k.dinosaurService.IsQuotaEntitlementActive(central)
quotaService, factoryErr := k.quotaServiceFactory.GetQuotaService(api.QuotaType(k.dinosaurConfig.Quota.Type))
if factoryErr != nil {
svcErrors = append(svcErrors, factoryErr)
continue
}

isActive, err := quotaService.IsQuotaEntitlementActive(central)
if err != nil {
svcErrors = append(svcErrors, errors.Wrapf(err, "failed to get quota entitlement status of central instance %q", central.ID))
continue
Expand Down

0 comments on commit 4b7461c

Please sign in to comment.