Bug 1815082

Summary: When creating a job from a cronjob the ownerReference is wrong as it uses apps/v1 for a cronjob which should be batch/v1beta1
Product: OpenShift Container Platform Reporter: Sergio G. <sgarciam>
Component: ocAssignee: Maciej Szulik <maszulik>
Status: CLOSED DUPLICATE QA Contact: zhou ying <yinzhou>
Severity: high Docs Contact:
Priority: unspecified    
Version: 4.3.zCC: aos-bugs, jokerman, mfojtik, ocasalsa
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-20 09:22:04 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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 ***