Skip to content

Commit 0c2a2ca

Browse files
authored
ROX-31105: Use CentralID to ignore quota checks (#2446)
* Use CentralID to ignore quota checks * Update comment
1 parent 146b126 commit 0c2a2ca

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

internal/central/pkg/config/central.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (c *CentralConfig) AddFlags(fs *pflag.FlagSet) {
4646
fs.IntVar(&c.CentralLifespan.CentralLifespanInHours, "central-lifespan", c.CentralLifespan.CentralLifespanInHours, "The desired lifespan of a Central instance")
4747
fs.StringVar(&c.CentralDomainName, "central-domain-name", c.CentralDomainName, "The domain name to use for Central instances")
4848
fs.StringVar(&c.Quota.Type, "quota-type", c.Quota.Type, "The type of the quota service to be used. The available options are: 'ams' for AMS backed implementation and 'quota-management-list' for quota list backed implementation (default).")
49-
fs.StringArrayVar(&c.Quota.InternalOrganisationIDs, "quota-internal-organisation-ids", c.Quota.InternalOrganisationIDs, "Comma separated list of organisation IDs that should be ignored for quota checks and for the expiration worker.")
49+
fs.StringArrayVar(&c.Quota.InternalCentralIDs, "quota-internal-central-ids", c.Quota.InternalCentralIDs, "Comma separated list of Central IDs that should be ignored for quota checks and for the expiration worker.")
5050
fs.BoolVar(&c.Quota.AllowEvaluatorInstance, "allow-evaluator-instance", c.Quota.AllowEvaluatorInstance, "Allow the creation of central evaluator instances")
5151

5252
fs.StringVar(&c.CentralIDPClientID, "central-idp-client-id", c.CentralIDPClientID, "OIDC client_id to pass to Central's auth config")

internal/central/pkg/config/central_quota.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import "github.com/stackrox/acs-fleet-manager/pkg/api"
66
type CentralQuotaConfig struct {
77
Type string `json:"type"`
88
AllowEvaluatorInstance bool `json:"allow_evaluator_instance"`
9-
// InternalOrganisationIDs is a list of organisation IDs that should be ignored for quota checks
10-
InternalOrganisationIDs []string `json:"internal_organisation_ids"`
9+
// InternalCentralIDs is a list of Central IDs that should be ignored for quota checks
10+
InternalCentralIDs []string `json:"internal_central_ids"`
1111
}
1212

1313
// NewCentralQuotaConfig ...
1414
func NewCentralQuotaConfig() *CentralQuotaConfig {
1515
return &CentralQuotaConfig{
16-
Type: api.QuotaManagementListQuotaType.String(),
17-
AllowEvaluatorInstance: true,
18-
InternalOrganisationIDs: []string{},
16+
Type: api.QuotaManagementListQuotaType.String(),
17+
AllowEvaluatorInstance: true,
18+
InternalCentralIDs: []string{},
1919
}
2020
}

internal/central/pkg/workers/centralmgrs/expiration_date_mgr.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ func (k *ExpirationDateManager) reconcileCentralExpiredAt(centrals dbapi.Central
9494

9595
quotaCostCache := make(map[quotaCostCacheKey]bool, 0)
9696
for _, central := range centrals {
97-
if slice.Contains(k.centralConfig.Quota.InternalOrganisationIDs, central.OrganisationID) {
98-
glog.Infof("skipping quota check for central instance %q as it belongs to an internal organisation", central.ID)
99-
// remove expiration date from internal organisation Central instances
97+
if slice.Contains(k.centralConfig.Quota.InternalCentralIDs, central.ID) {
98+
glog.Infof("skipping quota check for internal central instance %q", central.ID)
99+
// remove expiration date from internal Central instances
100100
if central.ExpiredAt.Valid {
101101
central.ExpiredAt = dbapi.TimePtrToNullTime(nil)
102102
if err := k.updateExpiredAtInDB(central); err != nil {
103103
svcErrors = append(svcErrors, errors.Wrapf(err,
104-
"failed to update expired_at for internal organisation central instance %q", central.ID))
104+
"failed to update expired_at for internal central instance %q", central.ID))
105105
}
106106
}
107107
continue

internal/central/pkg/workers/centralmgrs/expiration_date_mgr_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/stackrox/acs-fleet-manager/pkg/errors"
1818
)
1919

20+
const internalCentralID = "internal-central-id"
21+
2022
func TestExpirationDateManager(t *testing.T) {
2123
withEntitlement := func(e bool) (*services.QuotaServiceMock, *services.QuotaServiceFactoryMock) {
2224
qs := &services.QuotaServiceMock{
@@ -44,7 +46,7 @@ func TestExpirationDateManager(t *testing.T) {
4446
}
4547
}
4648
quotaConf := config.NewCentralQuotaConfig()
47-
quotaConf.InternalOrganisationIDs = []string{"internal-org-id"}
49+
quotaConf.InternalCentralIDs = []string{internalCentralID}
4850
defaultCfg := &config.CentralConfig{
4951
Quota: quotaConf,
5052
}
@@ -92,8 +94,9 @@ func TestExpirationDateManager(t *testing.T) {
9294
assert.Len(t, quotaFactory.GetQuotaServiceCalls(), 1)
9395
})
9496

95-
t.Run("skip setting expired_at for internal organisation even if no valid quota", func(t *testing.T) {
96-
central := &dbapi.CentralRequest{OrganisationID: "internal-org-id"}
97+
t.Run("skip setting expired_at for internal central even if no valid quota", func(t *testing.T) {
98+
central := &dbapi.CentralRequest{}
99+
central.ID = internalCentralID
97100
centralService := withCentrals(central)
98101
quotaSvc, quotaFactory := withEntitlement(true)
99102
gpm := NewExpirationDateManager(centralService, quotaFactory, defaultCfg)

templates/service-template.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ parameters:
294294
description: The domain name to use for Central instances
295295
value: acs-stage.rhcloud.com
296296

297-
- name: QUOTA_INTERNAL_ORG_IDS
298-
displayName: Quota internal organisation ids
299-
description: A Comma separated list of organisation IDs that should be ignored for quota checks and for the expiration worker
297+
- name: QUOTA_INTERNAL_CENTRAL_IDS
298+
displayName: Quota internal Central ids
299+
description: A Comma separated list of Central IDs that should be ignored for quota checks and for the expiration worker
300300
value: ""
301301

302302
- name: ENABLE_READY_DATA_PLANE_CLUSTERS_RECONCILE
@@ -963,7 +963,7 @@ objects:
963963
- --public-host-url=${SERVICE_PUBLIC_HOST_URL}
964964
- --dataplane-cluster-scaling-type=${DATAPLANE_CLUSTER_SCALING_TYPE}
965965
- --central-domain-name=${CENTRAL_DOMAIN_NAME}
966-
- --quota-internal-organisation-ids=${QUOTA_INTERNAL_ORG_IDS}
966+
- --quota-internal-central-ids=${QUOTA_INTERNAL_CENTRAL_IDS}
967967
- --alsologtostderr
968968
- --central-request-expiration-timeout=${CENTRAL_REQUEST_EXPIRATION_TIMEOUT}
969969
- --central-request-internal-user-agents=${CENTRAL_REQUEST_INTERNAL_USER_AGENTS}

0 commit comments

Comments
 (0)