Skip to content

Commit

Permalink
implement preserved trait
Browse files Browse the repository at this point in the history
  • Loading branch information
parametalol committed Jan 15, 2024
1 parent fe1a163 commit 419d224
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/dinosaur/constants/central.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ var ActiveStatuses = func() []CentralStatus {
}
return active
}()

const (
CentralTraitPreserved = "preserved" // Never deprovision expired instance.
)
2 changes: 2 additions & 0 deletions internal/dinosaur/pkg/services/dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/aws/aws-sdk-go/service/route53"
"github.com/golang/glog"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
dinosaurConstants "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"
Expand Down Expand Up @@ -530,6 +531,7 @@ func (k *dinosaurService) DeprovisionExpiredDinosaurs() *errors.ServiceError {
}

dbConn = dbConn.Where("status NOT IN (?)", dinosaurDeletionStatuses)
dbConn.Where("traits IS NULL OR ? != ALL (traits)", constants.CentralTraitPreserved)

db := dbConn.Updates(map[string]interface{}{
"status": dinosaurConstants.CentralRequestStatusDeprovision,
Expand Down
6 changes: 4 additions & 2 deletions internal/dinosaur/pkg/services/dinosaur_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func Test_dinosaurService_DeprovisionExpiredDinosaursQuery(t *testing.T) {
m := mocket.Catcher.Reset().NewMock().WithQuery(`UPDATE "central_requests" ` +
`SET "deletion_timestamp"=$1,"status"=$2,"updated_at"=$3 WHERE ` +
`(expired_at IS NOT NULL AND expired_at < $4 OR instance_type = $5 AND created_at <= $6) ` +
`AND status NOT IN ($7,$8) AND "central_requests"."deleted_at" IS NULL`).
`AND status NOT IN ($7,$8) AND (traits IS NULL OR $9 != ALL (traits)) ` +
`AND "central_requests"."deleted_at" IS NULL`).
OneTime()

svcErr := k.DeprovisionExpiredDinosaurs()
Expand All @@ -196,7 +197,8 @@ func Test_dinosaurService_DeprovisionExpiredDinosaursQuery(t *testing.T) {
m = mocket.Catcher.Reset().NewMock().WithQuery(`UPDATE "central_requests" ` +
`SET "deletion_timestamp"=$1,"status"=$2,"updated_at"=$3 WHERE ` +
`expired_at IS NOT NULL AND expired_at < $4 ` +
`AND status NOT IN ($5,$6) AND "central_requests"."deleted_at" IS NULL`).
`AND status NOT IN ($5,$6) AND (traits IS NULL OR $7 != ALL (traits)) ` +
`AND "central_requests"."deleted_at" IS NULL`).
OneTime()
k.dinosaurConfig.CentralLifespan.EnableDeletionOfExpiredCentral = false
svcErr = k.DeprovisionExpiredDinosaurs()
Expand Down

0 comments on commit 419d224

Please sign in to comment.