diff --git a/internal/dinosaur/constants/central.go b/internal/dinosaur/constants/central.go index aebb512ba2..ce43aeaa0e 100644 --- a/internal/dinosaur/constants/central.go +++ b/internal/dinosaur/constants/central.go @@ -103,3 +103,7 @@ var ActiveStatuses = func() []CentralStatus { } return active }() + +const ( + CentralTraitPreserved = "preserved" // Never deprovision expired instance. +) diff --git a/internal/dinosaur/pkg/services/dinosaur.go b/internal/dinosaur/pkg/services/dinosaur.go index 4f3e7f7d4a..2cc5006829 100644 --- a/internal/dinosaur/pkg/services/dinosaur.go +++ b/internal/dinosaur/pkg/services/dinosaur.go @@ -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" @@ -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, diff --git a/internal/dinosaur/pkg/services/dinosaur_test.go b/internal/dinosaur/pkg/services/dinosaur_test.go index c1d5046e84..e619a7b215 100644 --- a/internal/dinosaur/pkg/services/dinosaur_test.go +++ b/internal/dinosaur/pkg/services/dinosaur_test.go @@ -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() @@ -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()