origin: Unable to create CronJob using a Template

Unable to deploy a CronJob using a Template.

Version

oc v3.11.0+0cbc58b kubernetes v1.11.0+d4cacc0 features: Basic-Auth GSSAPI Kerberos SPNEGO

Server ************ openshift v3.11.0+1a90c5c-83 kubernetes v1.11.0+d4cacc0

Steps To Reproduce
  1. Create a template containing a sample CronJob and save it as cronjob-template.yaml
apiVersion: v1
kind: Template
metadata:
  name: cronjob-test
objects:
- apiVersion: batch/v1beta1
  kind: CronJob
  metadata:
    name: hello
  spec:
    schedule: "*/1 * * * *"
    jobTemplate:
      spec:
        template:
          spec:
            containers:
            - name: hello
              image: busybox
              args:
              - /bin/sh
              - -c
              - date; echo Hello from the Kubernetes cluster
            restartPolicy: OnFailure
  1. Deploy from template using oc new-app -f cronjob-template.yaml
Current Result

Deployment fails due to what seems to be an invalid apiVersion

--> Deploying template "default/cronjob-test" for "cronjob-template.yaml" to project default

--> Creating resources ...
    error: no kind "CronJob" is registered for version "batch/v1" in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"
--> Failed
Expected Result

Expect to deploy a cronjob successfully

--> Deploying template "default/cronjob-test" for "cronjob-template.yaml" to project default

--> Creating resources ...
    cronjob "hello" created
--> Success

    Run 'oc status' to view your app.
Additional Information

Same template was tested on an Openshift 3.9.x cluster and was able to deploy successfully. Have also tried using apiVersion ‘batch/v2alpha1’ to create a normal CronJob as specified in the documentation (https://docs.openshift.com/container-platform/3.11/rest_api/apis-batch/v2alpha1.CronJob.html#Post-apis-batch-v2alpha1-cronjobs), but it failed due to invalid apiVersion.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 24 (7 by maintainers)

Most upvoted comments

the recommended solution to this issue is to use oc process -f template.yaml | oc create -f - instead of oc new-app -f template.yaml

oc new-app is unlikely to receive further enhancements to address this issue (as of v4 we recommend always using oc process to instantiate templates, instead of oc new-app)

I’ve also ran into this problem. The cause seems to be the OpenShift CLI: when using version 3.10 running a cron job works as expected.