forked from stackrox/acs-fleet-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROX-16108: Replace Skip Scheduling with Schedulable; fix Placement lo…
…gic (stackrox#904) * Remove skip scheduling. * Add migration to delete the SkipScheduling column. * Remove final references to skip scheduling. Replace with use of schedulable. * Remove SkipScheduling, add Schedulable to cluster API and table columns * Tests * Fixed tests for placement. Removed supported instance type from cluster search API. * Fix migration * Fix migration ID * Remove unnecessary columns in migrations, per @machi1990's review comments. * Fix typo * Update moq file * Fix unit test * Fixes * Remove gorm default value from Schedulable. No columns use default values and, while 'false' may be surprising, the default value should never be used (aside from when this change is initially rolled out until the first reconciliation of the data plane config in saas.yaml is merged). * Update Schedulable field in database if the field's value changes in the dataplane config * Use values map to convince Gorm to update * Update moq --------- Co-authored-by: Vlad Bologa <[email protected]> Co-authored-by: Manyanda Chitimbo <[email protected]>
- Loading branch information
1 parent
ec52fac
commit 4cdd011
Showing
14 changed files
with
261 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
internal/dinosaur/pkg/migrations/202303220000_drop_skip_scheduling_from_clusters.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package migrations | ||
|
||
// Migrations should NEVER use types from other packages. Types can change | ||
// and then migrations run on a _new_ database will fail or behave unexpectedly. | ||
// Instead of importing types, always re-create the type in the migration, as | ||
// is done here, even though the same type is defined in pkg/api | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
|
||
"github.com/go-gormigrate/gormigrate/v2" | ||
"github.com/pkg/errors" | ||
"github.com/stackrox/acs-fleet-manager/pkg/db" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func dropSkipSchedulingFromClusters() *gormigrate.Migration { | ||
type Cluster struct { | ||
db.Model | ||
SkipScheduling bool `json:"skip_scheduling" gorm:"default:false"` // To be dropped | ||
} | ||
|
||
id := "202303221200" | ||
colName := "SkipScheduling" | ||
return &gormigrate.Migration{ | ||
ID: id, | ||
Migrate: func(tx *gorm.DB) error { | ||
if tx.Migrator().HasColumn(&Cluster{}, colName) { | ||
if err := tx.Migrator().DropColumn(&Cluster{}, colName); err != nil { | ||
return errors.Wrapf(err, "rolling back from column %s in migration %s", colName, id) | ||
} | ||
glog.Infof("Successfully removed the %s column", colName) | ||
} | ||
return nil | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
if !tx.Migrator().HasColumn(&Cluster{}, colName) { | ||
if err := tx.Migrator().AddColumn(&Cluster{}, colName); err != nil { | ||
return errors.Wrapf(err, "adding column %s in migration %s", colName, id) | ||
} | ||
glog.Infof("Successfully added the %s column", colName) | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
internal/dinosaur/pkg/migrations/202303230000_add_schedulable_to_clusters.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package migrations | ||
|
||
// Migrations should NEVER use types from other packages. Types can change | ||
// and then migrations run on a _new_ database will fail or behave unexpectedly. | ||
// Instead of importing types, always re-create the type in the migration, as | ||
// is done here, even though the same type is defined in pkg/api | ||
|
||
import ( | ||
"github.com/golang/glog" | ||
|
||
"github.com/go-gormigrate/gormigrate/v2" | ||
"github.com/pkg/errors" | ||
"github.com/stackrox/acs-fleet-manager/pkg/db" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func addSchedulableToClusters() *gormigrate.Migration { | ||
type Cluster struct { | ||
db.Model | ||
Schedulable bool `json:"schedulable"` // To be added | ||
} | ||
|
||
id := "202303231200" | ||
colName := "Schedulable" | ||
return &gormigrate.Migration{ | ||
ID: id, | ||
Migrate: func(tx *gorm.DB) error { | ||
if !tx.Migrator().HasColumn(&Cluster{}, colName) { | ||
if err := tx.Migrator().AddColumn(&Cluster{}, colName); err != nil { | ||
return errors.Wrapf(err, "adding column %s in migration %s", colName, id) | ||
} | ||
glog.Infof("Successfully added the %s column", colName) | ||
} | ||
return nil | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
if tx.Migrator().HasColumn(&Cluster{}, colName) { | ||
if err := tx.Migrator().DropColumn(&Cluster{}, colName); err != nil { | ||
return errors.Wrapf(err, "rolling back from column %s in migration %s", colName, id) | ||
} | ||
glog.Infof("Successfully removed the %s column", colName) | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.