Skip to content

Commit

Permalink
Fix access policies not updating status when no job (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhny authored Sep 9, 2024
1 parent 948f03b commit ab2657e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/controllers/skipjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ func (r *SKIPJobReconciler) updateConditions(ctx context.Context, skipJob *skipe
if err != nil {
return fmt.Errorf("failed to list jobs: %w", err)
}
if len(jobList.Items) == 0 {
return nil
}

//find last job to set conditions, cronjobs have multiple jobs
lastJob := &batchv1.Job{}
Expand All @@ -302,7 +299,14 @@ func (r *SKIPJobReconciler) updateConditions(ctx context.Context, skipJob *skipe
lastJob = &liveJob
}
}
if isFailed, failedJobMessage := isFailedJob(lastJob); isFailed {

if len(jobList.Items) == 0 {
skipJob.Status.Conditions = []v1.Condition{
r.getConditionFailed(skipJob, v1.ConditionFalse, nil),
r.getConditionRunning(skipJob, v1.ConditionFalse),
r.getConditionFinished(skipJob, v1.ConditionFalse),
}
} else if isFailed, failedJobMessage := isFailedJob(lastJob); isFailed {
skipJob.Status.Conditions = []v1.Condition{
r.getConditionFailed(skipJob, v1.ConditionTrue, &failedJobMessage),
r.getConditionRunning(skipJob, v1.ConditionFalse),
Expand Down
5 changes: 5 additions & 0 deletions tests/skipjob/access-policy-job/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ spec:
file: netpol-istio.yaml
- assert:
file: netpol-istio-assert.yaml
- try:
- apply:
file: status-ready-no-job.yaml
- assert:
file: status-ready-no-job-assert.yaml
1 change: 1 addition & 0 deletions tests/skipjob/access-policy-job/skipjob-cron-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ spec:
cron:
schedule: "* * * * *"
status:
accessPolicies: Ready
conditions:
- type: Failed
status: "False"
Expand Down
45 changes: 45 additions & 0 deletions tests/skipjob/access-policy-job/status-ready-no-job-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: skiperator.kartverket.no/v1alpha1
kind: SKIPJob
metadata:
name: status-ready-no-job
status:
accessPolicies: Ready
conditions:
- type: Failed
status: 'False'
- type: Running
status: 'False'
- type: Finished
status: 'False'
- message: Internal rules are valid
reason: ApplicationReconciled
status: 'True'
type: InternalRulesValid
subresources:
CronJob[status-ready-no-job]:
message: CronJob has finished synchronizing
status: Synced
ServiceAccount[status-ready-no-job-skipjob]:
message: ServiceAccount has finished synchronizing
status: Synced
ServiceEntry[skipjob-status-ready-no-job-egress-3da5ecd99bd5b65]:
message: ServiceEntry has finished synchronizing
status: Synced
summary:
message: All subresources synced
status: Synced
spec:
container:
accessPolicy:
outbound:
external:
- host: data.helsecert.no
image: image
cron:
allowConcurrency: Allow
schedule: 0 6 * * *
suspend: false
job:
backoffLimit: 6
suspend: false
ttlSecondsAfterFinished: 3600
19 changes: 19 additions & 0 deletions tests/skipjob/access-policy-job/status-ready-no-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: skiperator.kartverket.no/v1alpha1
kind: SKIPJob
metadata:
name: status-ready-no-job
spec:
container:
accessPolicy:
outbound:
external:
- host: data.helsecert.no
image: image
cron:
allowConcurrency: Allow
schedule: "0 6 * * *"
suspend: false
job:
backoffLimit: 6
suspend: false
ttlSecondsAfterFinished: 3600

0 comments on commit ab2657e

Please sign in to comment.