This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for jobs that are both cron and event based
Before this change, a cronjob that also specifies events would produce a cronjob that is only running after one of the events occurs and is deleted after a non-listed event. Additionally, a cronjob is not marked as "ready" until it runs at least once. After this change, a cronjob is marked as ready unless it is running or failed. Additionally, a job that specifies both events and schedule, a cronjob is created for the schedule and a "regular" job for each event. Once the event-based job succeeds, the job's status is read from the cronjob. That means, if the "regular" job fails, then the job's status will be "failed" until the "regular" job passed, regardless of what is happening with the cronjob. Signed-off-by: Donnie Adams <[email protected]>
- Loading branch information
Showing
28 changed files
with
2,113 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package run | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/acorn-io/runtime/integration/helper" | ||
apiv1 "github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1" | ||
"github.com/acorn-io/runtime/pkg/client" | ||
crClient "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func TestJobDelete(t *testing.T) { | ||
helper.StartController(t) | ||
|
||
ctx := helper.GetCTX(t) | ||
c, _ := helper.ClientAndProject(t) | ||
|
||
image, err := c.AcornImageBuild(ctx, "./testdata/jobfinalize/Acornfile", &client.AcornImageBuildOptions{ | ||
Cwd: "./testdata/jobfinalize", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app, err := c.AppRun(ctx, image.ID, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app = helper.WaitForObject(t, helper.Watcher(t, c), new(apiv1.AppList), app, func(app *apiv1.App) bool { | ||
return len(app.Finalizers) > 0 | ||
}) | ||
|
||
app, err = c.AppDelete(ctx, app.Name) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_ = helper.EnsureDoesNotExist(ctx, func() (crClient.Object, error) { | ||
return c.AppGet(ctx, app.Name) | ||
}) | ||
} | ||
|
||
func TestCronJobWithCreate(t *testing.T) { | ||
helper.StartController(t) | ||
|
||
ctx := helper.GetCTX(t) | ||
c, _ := helper.ClientAndProject(t) | ||
|
||
image, err := c.AcornImageBuild(ctx, "./testdata/jobs/cron-with-create/Acornfile", &client.AcornImageBuildOptions{ | ||
Cwd: "./testdata/jobs/cron-with-create", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app, err := c.AppRun(ctx, image.ID, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app = helper.WaitForObject(t, helper.Watcher(t, c), new(apiv1.AppList), app, func(app *apiv1.App) bool { | ||
return app.Status.Ready | ||
}) | ||
|
||
app, err = c.AppDelete(ctx, app.Name) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_ = helper.EnsureDoesNotExist(ctx, func() (crClient.Object, error) { | ||
return c.AppGet(ctx, app.Name) | ||
}) | ||
} | ||
|
||
func TestCronJobWithUpdate(t *testing.T) { | ||
helper.StartController(t) | ||
|
||
ctx := helper.GetCTX(t) | ||
c, _ := helper.ClientAndProject(t) | ||
|
||
image, err := c.AcornImageBuild(ctx, "./testdata/jobs/cron-with-update/Acornfile", &client.AcornImageBuildOptions{ | ||
Cwd: "./testdata/jobs/cron-with-update", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app, err := c.AppRun(ctx, image.ID, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
app = helper.WaitForObject(t, helper.Watcher(t, c), new(apiv1.AppList), app, func(app *apiv1.App) bool { | ||
return app.Status.Ready && app.Status.AppStatus.Jobs["update"].Skipped | ||
}) | ||
|
||
app, err = c.AppUpdate(ctx, app.Name, &client.AppUpdateOptions{ | ||
DeployArgs: map[string]any{ | ||
"forceUpdateGen": 2, | ||
}, | ||
}) | ||
|
||
app = helper.WaitForObject(t, helper.Watcher(t, c), new(apiv1.AppList), app, func(app *apiv1.App) bool { | ||
return app.Status.Ready && !app.Status.AppStatus.Jobs["update"].Skipped | ||
}) | ||
|
||
app, err = c.AppDelete(ctx, app.Name) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_ = helper.EnsureDoesNotExist(ctx, func() (crClient.Object, error) { | ||
return c.AppGet(ctx, app.Name) | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
jobs: create: { | ||
image: "ghcr.io/acorn-io/images-mirror/busybox:latest" | ||
schedule: "0 0 31 2 *" // February 31st, never runs | ||
events: ["create"] | ||
dirs: "/app": "./scripts" | ||
command: "/app/run.sh" | ||
} |
3 changes: 3 additions & 0 deletions
3
integration/run/testdata/jobs/cron-with-create/scripts/run.sh
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,3 @@ | ||
#!/bin/sh | ||
set -x -e | ||
[ "$ACORN_EVENT" = "create" ] |
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,11 @@ | ||
args: { | ||
forceUpdateGen: 1 | ||
} | ||
|
||
jobs: update: { | ||
image: "ghcr.io/acorn-io/images-mirror/busybox:latest" | ||
schedule: "0 0 31 2 *" // February 31st, never runs | ||
events: ["update"] | ||
dirs: "/app": "./scripts" | ||
command: "/app/run.sh" | ||
} |
3 changes: 3 additions & 0 deletions
3
integration/run/testdata/jobs/cron-with-update/scripts/run.sh
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,3 @@ | ||
#!/bin/sh | ||
set -x -e | ||
[ "$ACORN_EVENT" = "update" ] |
File renamed without changes.
File renamed without changes.
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
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.