Skip to content

Commit

Permalink
set prewarmDevDB to true as default
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao committed Sep 14, 2023
1 parent e4bf0f3 commit bd574ec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
34 changes: 17 additions & 17 deletions controllers/devdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,8 @@ const (

// cleanUp clean up any resources created by the controller
func (r *AtlasSchemaReconciler) cleanUp(ctx context.Context, sc *dbv1alpha1.AtlasSchema) {
// If prewarmDevDB is true, delete pods to clean up
// Otherwise, scale down the deployment to 0
if r.prewarmDevDB {
pods := &corev1.PodList{}
err := r.List(ctx, pods, client.MatchingLabels(map[string]string{
labelInstance: nameDevDB(sc.ObjectMeta).Name,
}))
if err != nil {
r.recorder.Eventf(sc, corev1.EventTypeWarning, "CleanUpDevDB", "Error listing devDB pods: %v", err)
}

for _, p := range pods.Items {
if err := r.Delete(ctx, &p); err != nil {
r.recorder.Eventf(sc, corev1.EventTypeWarning, "CleanUpDevDB", "Error deleting devDB pod %s: %v", p.Name, err)
}
}
} else {
// If prewarmDevDB is false, scale down the deployment to 0
if !r.prewarmDevDB {
deploy := &appsv1.Deployment{}
key := nameDevDB(sc.ObjectMeta)
err := r.Get(ctx, key, deploy)
Expand All @@ -74,6 +59,21 @@ func (r *AtlasSchemaReconciler) cleanUp(ctx context.Context, sc *dbv1alpha1.Atla
if err := r.Update(ctx, deploy); err != nil {
r.recorder.Eventf(sc, corev1.EventTypeWarning, "CleanUpDevDB", "Error scaling down devDB deployment: %v", err)
}
return
}

// delete pods to clean up
pods := &corev1.PodList{}
err := r.List(ctx, pods, client.MatchingLabels(map[string]string{
labelInstance: nameDevDB(sc.ObjectMeta).Name,
}))
if err != nil {
r.recorder.Eventf(sc, corev1.EventTypeWarning, "CleanUpDevDB", "Error listing devDB pods: %v", err)
}
for _, p := range pods.Items {
if err := r.Delete(ctx, &p); err != nil {
r.recorder.Eventf(sc, corev1.EventTypeWarning, "CleanUpDevDB", "Error deleting devDB pod %s: %v", p.Name, err)
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ func checkForUpdate() {
}

// getPrewarmDevDBEnv returns the value of the env var PREWARM_DEVDB.
// if the env var is not set, it returns true.
func getPrewarmDevDBEnv() bool {
env := os.Getenv(prewarmDevDB)
if env == "" {
return false
return true
}
prewarmDevDB, err := strconv.ParseBool(env)
if err != nil {
Expand Down

0 comments on commit bd574ec

Please sign in to comment.