Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/v1alpha1/atlasmigration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ type (
// DevURLFrom is a reference to a secret containing the URL of the database to use for normalization and calculations.
// +optional
DevURLFrom Secret `json:"devURLFrom,omitempty"`
// PrewarmDevDB controls whether the automatically managed dev DB should be kept warm after reconciliation.
// If not specified, the operator-wide default is used.
// +optional
PrewarmDevDB *bool `json:"prewarmDevDB,omitempty"`
// RevisionsSchema defines the schema that revisions table resides in
RevisionsSchema string `json:"revisionsSchema,omitempty"`
// BaselineVersion defines the baseline version of the database on the first migration.
Expand Down Expand Up @@ -164,6 +168,11 @@ func (m *AtlasMigration) NamespacedName() types.NamespacedName {
}
}

// GetPrewarmDevDB returns the per-resource dev DB prewarm override, if set.
func (m *AtlasMigration) GetPrewarmDevDB() *bool {
return m.Spec.PrewarmDevDB
}

// IsReady returns true if the ready condition is true.
func (m *AtlasMigration) IsReady() bool {
return meta.IsStatusConditionTrue(m.Status.Conditions, readyCond)
Expand Down
9 changes: 9 additions & 0 deletions api/v1alpha1/atlasschema_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ type (
// DevURLFrom is a reference to a secret containing the URL of the database to use for normalization and calculations.
// +optional
DevURLFrom Secret `json:"devURLFrom,omitempty"`
// PrewarmDevDB controls whether the automatically managed dev DB should be kept warm after reconciliation.
// If not specified, the operator-wide default is used.
// +optional
PrewarmDevDB *bool `json:"prewarmDevDB,omitempty"`
// Exclude a list of glob patterns used to filter existing resources being taken into account.
Exclude []string `json:"exclude,omitempty"`
// TxMode defines the transaction mode to use when applying the schema.
Expand Down Expand Up @@ -203,6 +207,11 @@ func (s *AtlasSchema) NamespacedName() types.NamespacedName {
}
}

// GetPrewarmDevDB returns the per-resource dev DB prewarm override, if set.
func (s *AtlasSchema) GetPrewarmDevDB() *bool {
return s.Spec.PrewarmDevDB
}

// IsReady returns true if the ready condition is true.
func (m *AtlasSchema) IsReady() bool {
return meta.IsStatusConditionTrue(m.Status.Conditions, readyCond)
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions charts/atlas-operator/templates/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8679,6 +8679,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
prewarmDevDB:
description: |-
PrewarmDevDB controls whether the automatically managed dev DB should be kept warm after reconciliation.
If not specified, the operator-wide default is used.
type: boolean
dir:
description: Dir defines the directory to use for migrations as a
configmap key reference.
Expand Down Expand Up @@ -17622,6 +17627,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
prewarmDevDB:
description: |-
PrewarmDevDB controls whether the automatically managed dev DB should be kept warm after reconciliation.
If not specified, the operator-wide default is used.
type: boolean
envName:
description: |-
EnvName defines the environment name that defined in the project configuration.
Expand Down
4 changes: 3 additions & 1 deletion charts/atlas-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ tolerations: []

affinity: {}

# By default, the operator will recreate devdb pods after migration
# By default, the operator will recreate devdb pods after migration.
# Set this to true to keep the devdb pods around.
# This is the global default and can be overridden per AtlasSchema or
# AtlasMigration resource with spec.prewarmDevDB.
prewarmDevDB: true

# Enable this to allow custom project configuration
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/db.atlasgo.io_atlasmigrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8693,6 +8693,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
prewarmDevDB:
description: |-
PrewarmDevDB controls whether the automatically managed dev DB should be kept warm after reconciliation.
If not specified, the operator-wide default is used.
type: boolean
dir:
description: Dir defines the directory to use for migrations as a
configmap key reference.
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/db.atlasgo.io_atlasschemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8688,6 +8688,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
prewarmDevDB:
description: |-
PrewarmDevDB controls whether the automatically managed dev DB should be kept warm after reconciliation.
If not specified, the operator-wide default is used.
type: boolean
envName:
description: |-
EnvName defines the environment name that defined in the project configuration.
Expand Down
16 changes: 15 additions & 1 deletion internal/controller/devdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type (
recorder record.EventRecorder
prewarm bool
}
devDBOwner interface {
client.Object
GetPrewarmDevDB() *bool
}
)

var errWaitDevDB = transient(errors.New("waiting for dev database to be ready"))
Expand All @@ -77,8 +81,9 @@ func newDevDB(mgr Manager, r record.EventRecorder, prewarm bool) *devDBReconcile
// cleanUp clean up any resources created by the controller
func (r *devDBReconciler) cleanUp(ctx context.Context, sc client.Object) {
key := nameDevDB(sc)
prewarm := r.prewarmEnabled(sc)
// If prewarmDevDB is false, scale down the deployment to 0
if !r.prewarm {
if !prewarm {
deploy := &appsv1.Deployment{}
err := r.Get(ctx, key, deploy)
if err != nil {
Expand Down Expand Up @@ -193,6 +198,15 @@ func (r *devDBReconciler) devURL(ctx context.Context, sc client.Object, targetUR
return "", errors.New("no connection template annotation found")
}

func (r *devDBReconciler) prewarmEnabled(sc client.Object) bool {
if owner, ok := sc.(devDBOwner); ok {
if override := owner.GetPrewarmDevDB(); override != nil {
return *override
}
}
return r.prewarm
}

func deploymentDevDB(key types.NamespacedName, drv dbv1alpha1.Driver, podSpec corev1.PodSpec, urlTemplate string) *appsv1.Deployment {
labels := map[string]string{
labelEngine: drv.String(),
Expand Down
43 changes: 43 additions & 0 deletions internal/controller/devdb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package controller

import (
"testing"

dbv1alpha1 "github.com/ariga/atlas-operator/api/v1alpha1"

"github.com/stretchr/testify/require"
)

func TestDevDBPrewarmEnabledFallsBackToGlobalDefault(t *testing.T) {
r := &devDBReconciler{prewarm: true}
sc := &dbv1alpha1.AtlasSchema{}

enabled := r.prewarmEnabled(sc)
require.True(t, enabled)
}

func TestDevDBPrewarmEnabledUsesResourceOverride(t *testing.T) {
r := &devDBReconciler{prewarm: true}
override := false
sc := &dbv1alpha1.AtlasSchema{
Spec: dbv1alpha1.AtlasSchemaSpec{
PrewarmDevDB: &override,
},
}

enabled := r.prewarmEnabled(sc)
require.False(t, enabled)
}

func TestDevDBPrewarmEnabledUsesMigrationOverride(t *testing.T) {
r := &devDBReconciler{prewarm: false}
override := true
mg := &dbv1alpha1.AtlasMigration{
Spec: dbv1alpha1.AtlasMigrationSpec{
PrewarmDevDB: &override,
},
}

enabled := r.prewarmEnabled(mg)
require.True(t, enabled)
}
Loading