kubectl create cronjobs: Manually set OwnerReferences
Kubernetes-commit: 398ab938efc1cf2eaf47f4d8da842892f212ce65
This commit is contained in:
		
							parent
							
								
									0fe334ad70
								
							
						
					
					
						commit
						596b0a6d98
					
				| 
						 | 
				
			
			@ -35,6 +35,7 @@ import (
 | 
			
		|||
	"k8s.io/kubectl/pkg/util"
 | 
			
		||||
	"k8s.io/kubectl/pkg/util/i18n"
 | 
			
		||||
	"k8s.io/kubectl/pkg/util/templates"
 | 
			
		||||
	"k8s.io/utils/ptr"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
| 
						 | 
				
			
			@ -264,7 +265,18 @@ func (o *CreateJobOptions) createJobFromCronJob(cronJob *batchv1.CronJob) *batch
 | 
			
		|||
			Name:        o.Name,
 | 
			
		||||
			Annotations: annotations,
 | 
			
		||||
			Labels:      cronJob.Spec.JobTemplate.Labels,
 | 
			
		||||
			OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(cronJob, batchv1.SchemeGroupVersion.WithKind("CronJob"))},
 | 
			
		||||
			OwnerReferences: []metav1.OwnerReference{
 | 
			
		||||
				{
 | 
			
		||||
					// we are not using metav1.NewControllerRef because it
 | 
			
		||||
					// sets BlockOwnerDeletion to true which additionally mandates
 | 
			
		||||
					// cronjobs/finalizer role and not backwards-compatible.
 | 
			
		||||
					APIVersion: batchv1.SchemeGroupVersion.String(),
 | 
			
		||||
					Kind:       "CronJob",
 | 
			
		||||
					Name:       cronJob.GetName(),
 | 
			
		||||
					UID:        cronJob.GetUID(),
 | 
			
		||||
					Controller: ptr.To(true),
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Spec: cronJob.Spec.JobTemplate.Spec,
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,6 +24,7 @@ import (
 | 
			
		|||
	corev1 "k8s.io/api/core/v1"
 | 
			
		||||
	apiequality "k8s.io/apimachinery/pkg/api/equality"
 | 
			
		||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
			
		||||
	"k8s.io/utils/ptr"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestCreateJobValidation(t *testing.T) {
 | 
			
		||||
| 
						 | 
				
			
			@ -163,7 +164,15 @@ func TestCreateJobFromCronJob(t *testing.T) {
 | 
			
		|||
				ObjectMeta: metav1.ObjectMeta{
 | 
			
		||||
					Name:        jobName,
 | 
			
		||||
					Annotations: map[string]string{"cronjob.kubernetes.io/instantiate": "manual"},
 | 
			
		||||
					OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(cronJob, batchv1.SchemeGroupVersion.WithKind("CronJob"))},
 | 
			
		||||
					OwnerReferences: []metav1.OwnerReference{
 | 
			
		||||
						{
 | 
			
		||||
							APIVersion: batchv1.SchemeGroupVersion.String(),
 | 
			
		||||
							Kind:       "CronJob",
 | 
			
		||||
							Name:       cronJob.GetName(),
 | 
			
		||||
							UID:        cronJob.GetUID(),
 | 
			
		||||
							Controller: ptr.To(true),
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				Spec: batchv1.JobSpec{
 | 
			
		||||
					Template: corev1.PodTemplateSpec{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue