Skip to content
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

[Suggestion] Scaffolding Jobs and CronJobs #82

Open
ThorstenHans opened this issue Jun 19, 2024 · 0 comments
Open

[Suggestion] Scaffolding Jobs and CronJobs #82

ThorstenHans opened this issue Jun 19, 2024 · 0 comments

Comments

@ThorstenHans
Copy link

Users can create WebAssembly workloads that execute once leveraging the Command Trigger, which allows us to build and run Jobs and CronJobs in Kubernetes environments.

Although I was able to create the corresponding Kubernetes manifests manually, it is tedious to create full fledged manifests that use Runtime Configuration Files.

Being able to scaffold both Jobs and CronJobs would be very handy.

CLI Interface Suggestions

IMO, the most intuitive CLI interface would rely on using flags:

# Create a manifest of kind Job when --job is present
spin kube scaffold -f ttl.sh/job:12h --runtime-config-file ./rtc.toml --job

# Create a manifest of kind CronJob when --cron and --schedule are present
spin kube scaffold -f tt.sh/cronjob:12h --runtime-config-file ./rtc.toml --cron --schedule "* * * * *"
# Alternatively --cron could take the actual schedule as value
spin kube scaffold -f tt.sh/cronjob:12h --runtime-config-file ./rtc.toml --cron "* * * * *"

As an alternative, job and cron could be defined as sub-commands of scaffold:

# Create a manifest of kind Job
spin kube scaffold job -f ttl.sh/job:12h --runtime-config-file ./rtc.toml

# Create a manifest of kind CronJob
spin kube scaffold cron -f tt.sh/cronjob:12h --runtime-config-file ./rtc.toml  --schedule "* * * * *"

Sample CronJob Manifest

See the following CronJob manifest for reference:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: wasm-cronjob
spec:
  schedule: '* * * * *'
  jobTemplate:
    metadata:
      name: wasm-cronjob
    spec:
      template:
        spec:
          runtimeClassName: wasmtime-spin-v2
          containers:
          - image: ttl.sh/wasm-cron:12h
            command:
              - /
            name: main
            volumeMounts:
            - mountPath: /runtime-config.toml
              name: spin-runtime-config
              readOnly: true
              subPath: runtime-config.toml
            - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
              name: kube-api-access-876nv
              readOnly: true
          restartPolicy: OnFailure
          volumes:
          - name: spin-runtime-config
            secret:
              defaultMode: 420
              items:
              - key: runtime-config.toml
                path: runtime-config.toml
              optional: true
              secretName: api-runtime-config
          - name: kube-api-access-876nv
            projected:
              defaultMode: 420
              sources:
              - serviceAccountToken:
                  expirationSeconds: 3607
                  path: token
              - configMap:
                  items:
                  - key: ca.crt
                    path: ca.crt
                  name: kube-root-ca.crt
              - downwardAPI:
                  items:
                  - fieldRef:
                      apiVersion: v1
                      fieldPath: metadata.namespace
                    path: namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant