knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/duck/v1/cronjob_types.go (about)

     1  /*
     2  Copyright 2021 The Knative Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1
    18  
    19  import (
    20  	batchv1 "k8s.io/api/batch/v1"
    21  	corev1 "k8s.io/api/core/v1"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  	"k8s.io/apimachinery/pkg/runtime"
    24  
    25  	"knative.dev/pkg/apis"
    26  	"knative.dev/pkg/apis/duck/ducktypes"
    27  )
    28  
    29  // +genduck
    30  
    31  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    32  
    33  // CronJob is a wrapper around CronJob resource, which supports our interfaces
    34  // for webhooks
    35  type CronJob struct {
    36  	metav1.TypeMeta   `json:",inline"`
    37  	metav1.ObjectMeta `json:"metadata,omitempty"`
    38  
    39  	Spec batchv1.CronJobSpec `json:"spec,omitempty"`
    40  }
    41  
    42  // Verify CronJob resources meet duck contracts.
    43  var (
    44  	_ apis.Validatable      = (*CronJob)(nil)
    45  	_ apis.Defaultable      = (*CronJob)(nil)
    46  	_ apis.Listable         = (*CronJob)(nil)
    47  	_ ducktypes.Populatable = (*CronJob)(nil)
    48  )
    49  
    50  // GetFullType implements duck.Implementable
    51  func (c *CronJob) GetFullType() ducktypes.Populatable {
    52  	return &CronJob{}
    53  }
    54  
    55  // Populate implements duck.Populatable
    56  func (c *CronJob) Populate() {
    57  	c.Spec = batchv1.CronJobSpec{
    58  		JobTemplate: batchv1.JobTemplateSpec{
    59  			Spec: batchv1.JobSpec{
    60  				Template: corev1.PodTemplateSpec{
    61  					Spec: corev1.PodSpec{
    62  						Containers: []corev1.Container{{
    63  							Name:  "container-name",
    64  							Image: "container-image:latest",
    65  						}},
    66  					},
    67  				},
    68  			},
    69  		},
    70  	}
    71  }
    72  
    73  // GetListType implements apis.Listable
    74  func (c *CronJob) GetListType() runtime.Object {
    75  	return &CronJob{}
    76  }
    77  
    78  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    79  
    80  // CronJobList is a list of CronJob resources
    81  type CronJobList struct {
    82  	metav1.TypeMeta `json:",inline"`
    83  	metav1.ListMeta `json:"metadata"`
    84  
    85  	Items []CronJob `json:"items"`
    86  }