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

Commit e77c2e6

Browse files
committed
Ensure create jobs are only run once
If a create job is also an update job, then we would lose track of the create "doneness" of the job. After this change, it should be maintained for the life of the app. Additionally, if an app is stopped, then jobs will be suspended. Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent e2ac7b3 commit e77c2e6

File tree

6 files changed

+160
-1
lines changed

6 files changed

+160
-1
lines changed

pkg/controller/appdefinition/jobs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func toJob(req router.Request, appInstance *v1.AppInstance, pullSecrets *PullSec
123123
appInstance.Status.AppSpec.Annotations, container.Annotations, appInstance.Spec.Annotations))
124124

125125
jobSpec := batchv1.JobSpec{
126+
Suspend: appInstance.Spec.Stop,
126127
Template: corev1.PodTemplateSpec{
127128
ObjectMeta: metav1.ObjectMeta{
128129
Labels: jobLabels(appInstance, container, name,

pkg/controller/appdefinition/jobs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ func TestCronJobs(t *testing.T) {
2727
func TestDeleteJob(t *testing.T) {
2828
tester.DefaultTest(t, scheme.Scheme, "testdata/job/delete-job", DeploySpec)
2929
}
30+
31+
func TestJobAppStopped(t *testing.T) {
32+
tester.DefaultTest(t, scheme.Scheme, "testdata/job/stopped-app", DeploySpec)
33+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
kind: Job
2+
apiVersion: batch/v1
3+
metadata:
4+
name: oneimage
5+
namespace: app-created-namespace
6+
annotations:
7+
apply.acorn.io/prune: "false"
8+
apply.acorn.io/update: "true"
9+
labels:
10+
"acorn.io/app-namespace": "app-namespace"
11+
"acorn.io/app-name": "app-name"
12+
acorn.io/app-public-name: "app-name"
13+
"acorn.io/job-name": "oneimage"
14+
"acorn.io/managed": "true"
15+
spec:
16+
suspend: true
17+
backoffLimit: 1000
18+
template:
19+
metadata:
20+
labels:
21+
"acorn.io/app-namespace": "app-namespace"
22+
"acorn.io/app-name": "app-name"
23+
acorn.io/app-public-name: "app-name"
24+
"acorn.io/job-name": "oneimage"
25+
"acorn.io/managed": "true"
26+
annotations:
27+
acorn.io/container-spec: '{"build":{"context":".","dockerfile":"Dockerfile"},"image":"image-name","ports":[{"port":80,"protocol":"http","targetPort":81}],"probes":null,"sidecars":{"left":{"image":"foo","ports":[{"port":90,"protocol":"tcp","targetPort":91}],"probes":null}}}'
28+
spec:
29+
imagePullSecrets:
30+
- name: oneimage-pull-1234567890ab
31+
restartPolicy: Never
32+
serviceAccountName: oneimage
33+
enableServiceLinks: false
34+
terminationGracePeriodSeconds: 5
35+
containers:
36+
- name: oneimage
37+
image: "image-name"
38+
readinessProbe:
39+
tcpSocket:
40+
port: 81
41+
ports:
42+
- containerPort: 81
43+
protocol: "TCP"
44+
terminationMessagePath: "/run/secrets/output"
45+
env:
46+
- name: ACORN_EVENT
47+
value: "create"
48+
- name: left
49+
env:
50+
- name: ACORN_EVENT
51+
value: "create"
52+
image: "foo"
53+
readinessProbe:
54+
tcpSocket:
55+
port: 91
56+
ports:
57+
- containerPort: 91
58+
protocol: "TCP"
59+
terminationMessagePath: "/run/secrets/output"
60+
---
61+
kind: Secret
62+
apiVersion: v1
63+
metadata:
64+
name: oneimage-pull-1234567890ab
65+
namespace: app-created-namespace
66+
labels:
67+
acorn.io/managed: "true"
68+
acorn.io/pull-secret: "true"
69+
type: "kubernetes.io/dockerconfigjson"
70+
data:
71+
".dockerconfigjson": eyJhdXRocyI6eyJpbmRleC5kb2NrZXIuaW8iOnsiYXV0aCI6Ik9nPT0ifX19
72+
---
73+
kind: AppInstance
74+
apiVersion: internal.acorn.io/v1
75+
metadata:
76+
name: app-name
77+
namespace: app-namespace
78+
uid: 1234567890abcdef
79+
spec:
80+
stop: true
81+
image: test
82+
status:
83+
namespace: app-created-namespace
84+
appImage:
85+
id: test
86+
appSpec:
87+
jobs:
88+
oneimage:
89+
sidecars:
90+
left:
91+
image: "foo"
92+
ports:
93+
- port: 90
94+
targetPort: 91
95+
protocol: tcp
96+
ports:
97+
- port: 80
98+
targetPort: 81
99+
protocol: http
100+
image: "image-name"
101+
build:
102+
dockerfile: "Dockerfile"
103+
context: "."
104+
conditions:
105+
- type: defined
106+
reason: Success
107+
status: "True"
108+
success: true
109+
jobsStatus:
110+
oneimage: {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: ServiceAccount
2+
apiVersion: v1
3+
metadata:
4+
name: oneimage
5+
namespace: app-created-namespace
6+
labels:
7+
acorn.io/app-name: app-name
8+
acorn.io/app-public-name: "app-name"
9+
acorn.io/app-namespace: app-namespace
10+
acorn.io/managed: "true"
11+
acorn.io/job-name: "oneimage"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
kind: AppInstance
2+
apiVersion: internal.acorn.io/v1
3+
metadata:
4+
name: app-name
5+
namespace: app-namespace
6+
uid: 1234567890abcdef
7+
spec:
8+
stop: true
9+
image: test
10+
status:
11+
namespace: app-created-namespace
12+
appImage:
13+
id: test
14+
appSpec:
15+
jobs:
16+
oneimage:
17+
sidecars:
18+
left:
19+
image: "foo"
20+
ports:
21+
- port: 90
22+
targetPort: 91
23+
protocol: tcp
24+
ports:
25+
- port: 80
26+
targetPort: 81
27+
protocol: http
28+
image: "image-name"
29+
build:
30+
dockerfile: "Dockerfile"
31+
context: "."

pkg/controller/appstatus/status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ func JobStatus(req router.Request, resp router.Response) error {
293293
messageSet.Insert(message...)
294294
}
295295
jobStatus := v1.JobStatus{
296-
Message: strings.Join(messageSet.List(), "; "),
296+
Message: strings.Join(messageSet.List(), "; "),
297+
CreateEventSucceeded: app.Status.JobsStatus[job.Name].CreateEventSucceeded,
298+
Skipped: app.Status.JobsStatus[job.Name].Skipped,
297299
}
298300
if job.Status.Active > 0 {
299301
jobStatus.Running = true

0 commit comments

Comments
 (0)