-
Notifications
You must be signed in to change notification settings - Fork 5
Add resources for ope-notebook-culler cronjob #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dystewart
wants to merge
4
commits into
OCP-on-NERC:main
Choose a base branch
from
dystewart:cron
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d2bbdac
Add docker resources underlying toolkit container image
dystewart 8a34990
Add resources for ope-notebook-culler cronjob
dystewart d70cc73
Update README.md to include instructions for running ope-notebook-culler
dystewart 69e730f
Renames cronjob and makes naming consistent across cronjob resources
dystewart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,68 @@ | ||
| kind: CronJob | ||
| apiVersion: batch/v1 | ||
| metadata: | ||
| name: nb-culler | ||
| labels: | ||
| component.opendatahub.io/name: nb-culler | ||
| opendatahub.io/component: 'true' | ||
| opendatahub.io/modified: 'false' | ||
| spec: | ||
| schedule: '0 7 * * *' | ||
| startingDeadlineSeconds: 200 | ||
| concurrencyPolicy: Replace | ||
| suspend: false | ||
| jobTemplate: | ||
| metadata: | ||
| labels: | ||
| component.opendatahub.io/name: nb-culler | ||
| opendatahub.io/component: 'true' | ||
| spec: | ||
| template: | ||
| metadata: | ||
| labels: | ||
| component.opendatahub.io/name: nb-culler | ||
| opendatahub.io/component: 'true' | ||
| parent: nb-culler | ||
| spec: | ||
| restartPolicy: Never | ||
| serviceAccountName: ope-notebook-culler | ||
| schedulerName: default-scheduler | ||
| terminationGracePeriodSeconds: 30 | ||
| securityContext: {} | ||
| containers: | ||
| - name: oc-cli | ||
| image: >- | ||
| registry.redhat.io/openshift4/ose-cli@sha256:25fef269ac6e7491cb8340119a9b473acbeb53bc6970ad029fdaae59c3d0ca61 | ||
| command: ["/bin/bash", "-c", "--"] | ||
| args: | ||
| - | | ||
| #threshold to stop running notebooks. Currently set to 24 hours | ||
| cutoff_time=86400 | ||
| current_time=$(date +%s) | ||
| notebooks=$(oc get notebooks -n rhods-notebooks -o jsonpath='{range .items[?(@.status.containerState.running)]}{.metadata.name}{" "}{.metadata.namespace}{" "}{.status.containerState.running.startedAt}{"\n"}{end}') | ||
| if [ -z "$notebooks" ]; then | ||
| echo "No running notebooks found" | ||
| exit 0 | ||
| fi | ||
| # Loop through each notebook | ||
| while read -r nb ns ts; do | ||
| timestamp=$(date -d $ts +%s) | ||
| difference=$((current_time - timestamp)) | ||
| if [ $difference -gt $cutoff_time ]; then | ||
| echo "$nb is more than 24 hours old, stopping the notebook" | ||
| oc patch notebook $nb -n $ns --type merge -p '{"metadata":{"annotations":{"kubeflow-resource-stopped":"'$(date -u +"%Y-%m-%dT%H:%M:%SZ")'"}}}' | ||
| fi | ||
| done <<< "$notebooks" | ||
| resources: | ||
| limits: | ||
| memory: 800Mi | ||
| requests: | ||
| memory: 400Mi | ||
| terminationMessagePath: /dev/termination-log | ||
| terminationMessagePolicy: File | ||
| imagePullPolicy: IfNotPresent | ||
| serviceAccount: nb-culler | ||
| dnsPolicy: ClusterFirst | ||
| successfulJobsHistoryLimit: 7 | ||
| failedJobsHistoryLimit: 7 | ||
|
|
This file contains hidden or 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 @@ | ||
| apiVersion: kustomize.config.k8s.io/v1beta1 | ||
| kind: Kustomization | ||
| resources: | ||
| - cronjob.yaml | ||
| - rolebinding.yaml | ||
| - serviceaccount.yaml | ||
| namespace: rhods-notebooks |
This file contains hidden or 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 @@ | ||
| kind: RoleBinding | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| metadata: | ||
| name: nb-culler | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: nb-culler | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: edit |
This file contains hidden or 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,4 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: nb-culler |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.