Skip to content

Commit

Permalink
add RunOnNotReady feature to cji
Browse files Browse the repository at this point in the history
  • Loading branch information
gburges committed Jul 25, 2023
1 parent c1066bc commit 4ecb52a
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 10 deletions.
3 changes: 3 additions & 0 deletions apis/cloud.redhat.com/v1alpha1/clowdjobinvocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ type ClowdJobInvocationSpec struct {

// Testing is the struct for building out test jobs (iqe, etc) in a CJI
Testing JobTestingSpec `json:"testing,omitempty"`

// RunOnNotReady is a flag that when true, the job will not wait for the deployment to be ready to run
RunOnNotReady bool `json:"runOnNotReady,omitempty"`
}

// ClowdJobInvocationStatus defines the observed state of ClowdJobInvocation
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/cloud.redhat.com_clowdjobinvocations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ spec:
items:
type: string
type: array
runOnNotReady:
description: RunOnNotReady is a flag that when true, the job will
not wait for the deployment to be ready to run
type: boolean
testing:
description: Testing is the struct for building out test jobs (iqe,
etc) in a CJI
Expand Down
31 changes: 21 additions & 10 deletions controllers/cloud.redhat.com/clowdjobinvocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,9 @@ func (r *ClowdJobInvocationReconciler) Reconcile(ctx context.Context, req ctrl.R
}

// Determine if the ClowdApp containing the Job is ready
if !app.IsReady() {
r.Recorder.Eventf(&app, "Warning", "ClowdAppNotReady", "ClowdApp [%s] is not ready", cji.Spec.AppName)
r.Log.Info("App not yet ready, requeue", "jobinvocation", cji.Spec.AppName, "namespace", app.Namespace)
readyErr := errors.NewClowderError(fmt.Sprintf("The %s app must be ready for CJI to start", cji.Spec.AppName))
if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, readyErr); condErr != nil {
return ctrl.Result{}, condErr
}

// requeue with a buffer to let the app come up
return ctrl.Result{Requeue: true}, readyErr
notReadyError := r.HandleNotReady(ctx, app, cji)
if notReadyError != nil {
return ctrl.Result{Requeue: true}, notReadyError
}

// Get the ClowdEnv for InvokeJob. Env is needed to build out our pod
Expand Down Expand Up @@ -382,3 +375,21 @@ func countCompletedJobs(jobs *batchv1.JobList, cji *crd.ClowdJobInvocation) int
}
return jobsCompleted
}

func (r *ClowdJobInvocationReconciler) HandleNotReady(ctx context.Context, app crd.ClowdApp, cji crd.ClowdJobInvocation) error {
if app.IsReady() {
return nil
}
if cji.Spec.RunOnNotReady {
return nil
}
r.Recorder.Eventf(&app, "Warning", "ClowdAppNotReady", "ClowdApp [%s] is not ready", cji.Spec.AppName)
r.Log.Info("App not yet ready, requeue", "jobinvocation", cji.Spec.AppName, "namespace", app.Namespace)
readyErr := errors.NewClowderError(fmt.Sprintf("The %s app must be ready for CJI to start", cji.Spec.AppName))
if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, readyErr); condErr != nil {
return condErr
}

// requeue with a buffer to let the app come up
return readyErr
}
4 changes: 4 additions & 0 deletions deploy-mutate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6774,6 +6774,10 @@ objects:
items:
type: string
type: array
runOnNotReady:
description: RunOnNotReady is a flag that when true, the job will
not wait for the deployment to be ready to run
type: boolean
testing:
description: Testing is the struct for building out test jobs (iqe,
etc) in a CJI
Expand Down
4 changes: 4 additions & 0 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6774,6 +6774,10 @@ objects:
items:
type: string
type: array
runOnNotReady:
description: RunOnNotReady is a flag that when true, the job will
not wait for the deployment to be ready to run
type: boolean
testing:
description: Testing is the struct for building out test jobs (iqe,
etc) in a CJI
Expand Down
1 change: 1 addition & 0 deletions docs/antora/modules/ROOT/pages/api_reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ ClowdJobInvocationSpec defines the desired state of ClowdJobInvocation
| *`appName`* __string__ | Name of the ClowdApp who owns the jobs
| *`jobs`* __string array__ | Jobs is the set of jobs to be run by the invocation
| *`testing`* __xref:{anchor_prefix}-github-com-redhatinsights-clowder-apis-cloud-redhat-com-v1alpha1-jobtestingspec[$$JobTestingSpec$$]__ | Testing is the struct for building out test jobs (iqe, etc) in a CJI
| *`runOnNotReady`* __boolean__ | RunOnNotReady is a flag that when true, the job will not wait for the deployment to be ready to run
|===


Expand Down
7 changes: 7 additions & 0 deletions tests/kuttl/test-runonnotready-cji/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: test-runonnotready-jobs
spec:
finalizers:
- kubernetes
25 changes: 25 additions & 0 deletions tests/kuttl/test-runonnotready-cji/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdApp
metadata:
name: puptoo
namespace: test-runonnotready-jobs
status:
ready: false
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: puptoo-processor
namespace: test-runonnotready-jobs
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdJobInvocation
metadata:
name: runner-runonnotready
namespace: test-runonnotready-jobs
spec:
appName: puptoo
jobs:
- hello-cji
runONotReady: 'true'
70 changes: 70 additions & 0 deletions tests/kuttl/test-runonnotready-cji/01-pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdEnvironment
metadata:
name: test-runonnotready-jobs
spec:
targetNamespace: test-runonnotready-jobs
providers:
web:
port: 8000
mode: operator
privatePort: 10000
tls:
enabled: true
port: 8800
privatePort: 18800
metrics:
port: 9000
mode: operator
path: "/metrics"
kafka:
mode: none
db:
mode: none
logging:
mode: none
objectStore:
mode: none
inMemoryDb:
mode: none
featureFlags:
mode: none
resourceDefaults:
limits:
cpu: 400m
memory: 1024Mi
requests:
cpu: 30m
memory: 512Mi
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdApp
metadata:
name: puptoo
namespace: test-runonnotready-jobs
spec:
envName: test-runonnotready-jobs
deployments:
- name: processor
podSpec:
image: quay.io/psav/clowder-hello
jobs:
- name: hello-cji
podSpec:
image: busybox
args:
- /bin/sh
- -c
- echo "Hello!"
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdJobInvocation
metadata:
name: runner-runonnotready
namespace: test-runonnotready-jobs
spec:
appName: puptoo
jobs:
- hello-cji
runONotReady: 'true'
8 changes: 8 additions & 0 deletions tests/kuttl/test-runonnotready-cji/02-json-asserts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
apiVersion: kuttl.dev/v1alpha1
kind: TestStep
commands:
- script: sleep 30
- script: kubectl get pod -l app=puptoo -l job=puptoo-hello-cji -n test-runonnotready-jobs -o json > /tmp/test-runonnotready-jobs
- script: kubectl logs `jq -r '.items[0].metadata.name' < /tmp/test-runonnotready-jobs` -n test-runonnotready-jobs > /tmp/test-runonnotready-jobs-output-hello-cji-runner
- script: grep "Hello!" /tmp/test-runonnotready-jobs-output-hello-cji-runner
10 changes: 10 additions & 0 deletions tests/kuttl/test-runonnotready-cji/03-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: v1
kind: Namespace
name: test-runonnotready-jobs
- apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdEnvironment
name: test-runonnotready-jobs

0 comments on commit 4ecb52a

Please sign in to comment.