Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Do not automatically delete nested acorns that require job finalization
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Shepherd <[email protected]>
  • Loading branch information
ibuildthecloud committed Jul 19, 2023
1 parent d7e58ca commit 0d009f5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
3 changes: 1 addition & 2 deletions integration/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"testing"

"github.com/acorn-io/baaah/pkg/apply"
"github.com/acorn-io/baaah/pkg/restconfig"
"github.com/acorn-io/baaah/pkg/router"
"github.com/acorn-io/runtime/integration/helper"
Expand Down Expand Up @@ -1194,7 +1193,7 @@ func TestJobDelete(t *testing.T) {
}

app = helper.WaitForObject(t, helper.Watcher(t, c), new(apiv1.AppList), app, func(app *apiv1.App) bool {
return len(app.Finalizers) > 0 && app.Annotations[apply.AnnotationPrune] == "false"
return len(app.Finalizers) > 0
})

app, err = c.AppDelete(ctx, app.Name)
Expand Down
5 changes: 5 additions & 0 deletions integration/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func TestServiceIgnoreCleanup(t *testing.T) {
t.Fatal(err)
}

// Delete the service.
if _, err := c.AppDelete(ctx, "myapp.myservice"); err != nil {
t.Fatal(err)
}

// This app's service has a delete event job that will fail to run.
// Make sure it still shows up in the app list.
list, err := c.AppList(ctx)
Expand Down
17 changes: 16 additions & 1 deletion pkg/controller/appdefinition/acorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,39 @@ import (
"github.com/acorn-io/baaah/pkg/typed"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/autoupgrade"
"github.com/acorn-io/runtime/pkg/controller/jobs"
"github.com/acorn-io/runtime/pkg/images"
"github.com/acorn-io/runtime/pkg/labels"
"github.com/acorn-io/runtime/pkg/ports"
"github.com/acorn-io/runtime/pkg/publicname"
"github.com/google/go-containerregistry/pkg/name"
"golang.org/x/exp/slices"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func addAcorns(req router.Request, appInstance *v1.AppInstance, tag name.Reference, pullSecrets *PullSecrets, resp router.Response) {
func addAcorns(req router.Request, appInstance *v1.AppInstance, tag name.Reference, pullSecrets *PullSecrets, resp router.Response) error {
for _, acorn := range toAcorns(appInstance, tag, pullSecrets) {
var devSession v1.DevSessionInstance
err := req.Get(&devSession, acorn.Namespace, acorn.Name)
if err == nil {
// Don't update app in dev mode
acorn.Annotations[apply.AnnotationUpdate] = "false"
} else if !apierrors.IsNotFound(err) {
return err
}
var existingApp v1.AppInstance
err = req.Get(&existingApp, acorn.Namespace, acorn.Name)
if err == nil {
if slices.Contains(existingApp.Finalizers, jobs.DestroyJobFinalizer) {
acorn.Annotations[apply.AnnotationPrune] = "false"
}
} else if !apierrors.IsNotFound(err) {
return err
}
resp.Objects(acorn)
}
return nil
}

func toAcorns(appInstance *v1.AppInstance, tag name.Reference, pullSecrets *PullSecrets) (result []*v1.AppInstance) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/config/devconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func PurgeDevConfig(req router.Request, resp router.Response) error {
expiration, err := time.Parse(time.RFC3339, ttlString)
if err == nil {
if time.Now().Before(expiration) {
// Look 15 minutes later (stupid simple logic)
resp.RetryAfter(15 * time.Minute)
return nil
}
logrus.Infof("Time on dev config has expired [%s]", ttlString)
Expand Down
11 changes: 0 additions & 11 deletions pkg/controller/jobs/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"sort"
"time"

"github.com/acorn-io/baaah/pkg/apply"
"github.com/acorn-io/baaah/pkg/router"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/labels"
Expand Down Expand Up @@ -89,16 +88,6 @@ func NeedsDestroyJobFinalization(next router.Handler) router.Handler {
}

if shouldFinalize(app) {
if app.Annotations[apply.AnnotationPrune] != "false" {
if app.Annotations == nil {
app.Annotations = map[string]string{}
}
app.Annotations[apply.AnnotationPrune] = "false"
if err := req.Client.Update(req.Ctx, app); err != nil {
return err
}
}

return next.Handle(req, resp)
}

Expand Down

0 comments on commit 0d009f5

Please sign in to comment.