Bug 1815082 - When creating a job from a cronjob the ownerReference is wrong as it uses apps/v1 for a cronjob which should be batch/v1beta1
Summary: When creating a job from a cronjob the ownerReference is wrong as it uses app...
Keywords:
Status: CLOSED DUPLICATE of bug 1814728
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: oc
Version: 4.3.z
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
: ---
Assignee: Maciej Szulik
QA Contact: zhou ying
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-03-19 12:35 UTC by Sergio G.
Modified: 2023-10-06 19:27 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-03-20 09:22:04 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Sergio G. 2020-03-19 12:35:22 UTC
Description of problem:
When creating a job from a cronjob, the ownerReference is wrong as it uses apps/v1 for a cronjob which should be batch/v1beta1

Version-Release number of selected component (if applicable):
4.3.z


How reproducible:
Always


Steps to Reproduce:
1. Install OpenShift 4.3.5 with oc client 4.3.5

2. Create a cronjob (from the documentation):
$ echo "
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: pi
spec:
  schedule: "*/1 * * * *"  
  jobTemplate:             
    spec:
      template:
        metadata:
          labels:          
            parent: "cronjobpi"
        spec:
          containers:
          - name: pi
            image: perl
            command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
          restartPolicy: OnFailure
" | oc create -f -
cronjob.batch/pi created

3. Create a job from the previous cronjob:
$ oc create job test --from=cronjob/pi 
error: failed to create job: jobs.batch "test" is forbidden: cannot set blockOwnerDeletion in this case because cannot find RESTMapping for APIVersion apps/v1 Kind CronJob: no matches for kind "CronJob" in version "apps/v1"


Actual results:
The job cannot be created as it contains a wrong ApiVersion:
error: failed to create job: jobs.batch "test" is forbidden: cannot set blockOwnerDeletion in this case because cannot find RESTMapping for APIVersion apps/v1 Kind CronJob: no matches for kind "CronJob" in version "apps/v1"


Expected results:
The job should be created


Additional info:
 - This works when using oc 4.2 as it doesn't adds the ownerReference
 - If we use sed to replace apps/v1 with the right version batch/v1beta1 it works:
  $ oc create job test --from=cronjob/pi --dry-run -o yaml | sed 's/apps\/v1/batch\/v1beta1/' | oc create -f - 
  job.batch/test created

Comment 1 Maciej Szulik 2020-03-20 09:22:04 UTC

*** This bug has been marked as a duplicate of bug 1814728 ***


Note You need to log in before you can comment on or make changes to this bug.