diff --git a/integration/run/run_test.go b/integration/run/run_test.go index c52646481..e660d2946 100644 --- a/integration/run/run_test.go +++ b/integration/run/run_test.go @@ -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" @@ -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) diff --git a/integration/services/services_test.go b/integration/services/services_test.go index 5355e457c..6ec8f95ab 100644 --- a/integration/services/services_test.go +++ b/integration/services/services_test.go @@ -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) diff --git a/pkg/controller/appdefinition/acorn.go b/pkg/controller/appdefinition/acorn.go index 83c008f00..8d7574508 100644 --- a/pkg/controller/appdefinition/acorn.go +++ b/pkg/controller/appdefinition/acorn.go @@ -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) { diff --git a/pkg/controller/config/devconfig.go b/pkg/controller/config/devconfig.go index f22e54b69..ea4f3f80d 100644 --- a/pkg/controller/config/devconfig.go +++ b/pkg/controller/config/devconfig.go @@ -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) diff --git a/pkg/controller/jobs/finalize.go b/pkg/controller/jobs/finalize.go index 5ecad1bb6..baac9ea59 100644 --- a/pkg/controller/jobs/finalize.go +++ b/pkg/controller/jobs/finalize.go @@ -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" @@ -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) }