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

Commit fdff2c4

Browse files
authored
Merge pull request #1647 from thedadams/gh-1646
Stop checking status for jobs that won't run (#1646)
2 parents 1d87ce0 + b5b9365 commit fdff2c4

File tree

33 files changed

+160
-54
lines changed

33 files changed

+160
-54
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
cuelang.org/go v0.4.3
1919
github.com/AlecAivazis/survey/v2 v2.3.6
2020
github.com/acorn-io/aml v0.0.0-20230522195721-1194d1256120
21-
github.com/acorn-io/baaah v0.0.0-20230428031609-d553bca0d3d8
21+
github.com/acorn-io/baaah v0.0.0-20230523230836-5b13bbf77130
2222
github.com/acorn-io/mink v0.0.0-20230424190003-9a32355ec823
2323
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78
2424
github.com/adrg/xdg v0.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ github.com/acorn-io/aml v0.0.0-20230522195721-1194d1256120 h1:6bvZoycPKEsXtpUKQb
160160
github.com/acorn-io/aml v0.0.0-20230522195721-1194d1256120/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
161161
github.com/acorn-io/apiserver v0.25.2-ot-2 h1:drxKtiHh2dGnKlhVYxgPCKkFXRvMFxdflCZ5fHpVp8E=
162162
github.com/acorn-io/apiserver v0.25.2-ot-2/go.mod h1:qRxmYneSxb8B1FYvgQf6mPeWuwugIzYKN3TeMmL4FVo=
163-
github.com/acorn-io/baaah v0.0.0-20230428031609-d553bca0d3d8 h1:8DA+z4B0aC+u4x1H+3vlgQHytVlyxlkNdS1aMYE/Y+A=
164-
github.com/acorn-io/baaah v0.0.0-20230428031609-d553bca0d3d8/go.mod h1:yE5MQ1xi7osIDHNnBdmdTHmtnBbYxHQgQfXm/q2bbkU=
163+
github.com/acorn-io/baaah v0.0.0-20230523230836-5b13bbf77130 h1:0mKG7xI4gJQ9yZx5uqHtpGGepCyMsV3lMRPQdsjvl8c=
164+
github.com/acorn-io/baaah v0.0.0-20230523230836-5b13bbf77130/go.mod h1:yE5MQ1xi7osIDHNnBdmdTHmtnBbYxHQgQfXm/q2bbkU=
165165
github.com/acorn-io/component-base v0.25.2-ot-1 h1:xinqJUNbpW2/zsvm8mDv6Q7riLhvXup9x7Kz9eIPM1M=
166166
github.com/acorn-io/component-base v0.25.2-ot-1/go.mod h1:/5qYr5BXGNPs+cRd6+WL1NfOYtzOstJlm1CMK06cm7s=
167167
github.com/acorn-io/etcd/client/pkg/v3 v3.6.0-ot-1 h1:u2g5S6DbDNyueFeRSAVIBGMrkyLlcBLhTmH8l0a/4DM=

pkg/apis/internal.acorn.io/v1/appinstance.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,12 @@ type ContainerStatus struct {
174174
}
175175

176176
type JobStatus struct {
177-
Succeed bool `json:"succeed,omitempty"`
178-
Failed bool `json:"failed,omitempty"`
179-
Running bool `json:"running,omitempty"`
180-
Message string `json:"message,omitempty"`
181-
CreateDone bool `json:"createDone,omitempty"`
177+
Succeed bool `json:"succeed,omitempty"`
178+
Failed bool `json:"failed,omitempty"`
179+
Running bool `json:"running,omitempty"`
180+
Message string `json:"message,omitempty"`
181+
CreateEventSucceeded bool `json:"createEventSucceeded,omitempty"`
182+
Skipped bool `json:"skipped,omitempty"`
182183
}
183184

184185
type AppColumns struct {

pkg/controller/appdefinition/jobs.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func addJobs(req router.Request, appInstance *v1.AppInstance, tag name.Reference
2727
return nil
2828
}
2929

30-
func stripPrune(annotations map[string]string) map[string]string {
30+
func stripPruneAndUpdate(annotations map[string]string) map[string]string {
3131
result := map[string]string{}
3232
for k, v := range annotations {
33-
if k == apply.AnnotationPrune {
33+
if k == apply.AnnotationPrune || k == apply.AnnotationUpdate {
3434
continue
3535
}
3636
result[k] = v
@@ -44,12 +44,12 @@ func toJobs(req router.Request, appInstance *v1.AppInstance, pullSecrets *PullSe
4444
if err != nil || job == nil {
4545
return nil, err
4646
}
47-
sa, err := toServiceAccount(req, job.GetName(), job.GetLabels(), stripPrune(job.GetAnnotations()), appInstance)
47+
sa, err := toServiceAccount(req, job.GetName(), job.GetLabels(), stripPruneAndUpdate(job.GetAnnotations()), appInstance)
4848
if err != nil {
4949
return nil, err
5050
}
5151
if perms := v1.FindPermission(job.GetName(), appInstance.Spec.Permissions); perms.HasRules() {
52-
result = append(result, toPermissions(perms, job.GetLabels(), stripPrune(job.GetAnnotations()), appInstance)...)
52+
result = append(result, toPermissions(perms, job.GetLabels(), stripPruneAndUpdate(job.GetAnnotations()), appInstance)...)
5353
}
5454
result = append(result, sa, job)
5555
}
@@ -86,7 +86,7 @@ func getJobEvent(jobName string, appInstance *v1.AppInstance) string {
8686
if !appInstance.DeletionTimestamp.IsZero() {
8787
return "delete"
8888
}
89-
if appInstance.Status.JobsStatus[jobName].CreateDone {
89+
if appInstance.Generation > 1 && appInstance.Status.JobsStatus[jobName].CreateEventSucceeded {
9090
return "update"
9191
}
9292
return "create"
@@ -96,7 +96,14 @@ func toJob(req router.Request, appInstance *v1.AppInstance, pullSecrets *PullSec
9696
interpolator = interpolator.ForService(name)
9797
jobEventName := getJobEvent(name, appInstance)
9898

99-
if !matchesJobEvent(jobEventName, container) {
99+
jobStatus := appInstance.Status.JobsStatus[name]
100+
if appInstance.Status.JobsStatus == nil {
101+
appInstance.Status.JobsStatus = make(map[string]v1.JobStatus)
102+
}
103+
jobStatus.Skipped = !matchesJobEvent(jobEventName, container)
104+
appInstance.Status.JobsStatus[name] = jobStatus
105+
106+
if jobStatus.Skipped {
100107
return nil, nil
101108
}
102109

@@ -156,6 +163,7 @@ func toJob(req router.Request, appInstance *v1.AppInstance, pullSecrets *PullSec
156163
job.Spec.Template.Spec.Containers = setJobEventName(setTerminationPath(containers), jobEventName)
157164
job.Spec.Template.Spec.InitContainers = setJobEventName(setTerminationPath(initContainers), jobEventName)
158165
job.Annotations[apply.AnnotationPrune] = "false"
166+
job.Annotations[apply.AnnotationUpdate] = "true"
159167
return job, nil
160168
}
161169
return &batchv1.CronJob{

pkg/controller/appdefinition/jobs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ func TestJobsLabelsNamespace(t *testing.T) {
2323
func TestCronJobs(t *testing.T) {
2424
tester.DefaultTest(t, scheme.Scheme, "testdata/cronjob", DeploySpec)
2525
}
26+
27+
func TestDeleteJob(t *testing.T) {
28+
tester.DefaultTest(t, scheme.Scheme, "testdata/job/delete-job", DeploySpec)
29+
}

pkg/controller/appdefinition/testdata/computeclass/job/expected.yaml.d/appinstance.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ status:
7272
- type: defined
7373
reason: Success
7474
status: "True"
75-
success: true
75+
success: true
76+
jobsStatus:
77+
oneimage: {}

pkg/controller/appdefinition/testdata/computeclass/job/expected.yaml.d/job.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ metadata:
55
namespace: app-created-namespace
66
annotations:
77
"apply.acorn.io/prune": "false"
8+
apply.acorn.io/update: "true"
89
labels:
910
"acorn.io/app-namespace": "app-namespace"
1011
"acorn.io/app-name": "app-name"

pkg/controller/appdefinition/testdata/cronjob/expected.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,5 @@ status:
7979
reason: Success
8080
status: "True"
8181
success: true
82+
jobsStatus:
83+
oneimage: {}

pkg/controller/appdefinition/testdata/deployspec/filter-user-labels/expected.yaml.d/appinstance.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ status:
7878
reason: Success
7979
status: "True"
8080
success: true
81+
jobsStatus:
82+
job-name: {}
8183
---

pkg/controller/appdefinition/testdata/deployspec/filter-user-labels/expected.yaml.d/job.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ metadata:
1515
allowed-global.io: test-global
1616
annotations:
1717
apply.acorn.io/prune: "false"
18+
apply.acorn.io/update: "true"
1819
admit-job.io: test-admit-job-ann
1920
allowed-global.io: test-global
2021
allowed.io: test-allowed-app-spec-ann

0 commit comments

Comments
 (0)