From 35221b48cb3026af4f747487a48e8993a09c54ae Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Thu, 16 May 2024 22:02:07 +0100 Subject: [PATCH] cronjob-tutorial: fix issue faced after upgrade of controller-runtime --- .../testdata/project/api/v1/cronjob_types.go | 25 ++++++++ .../project/api/v1/zz_generated.deepcopy.go | 57 +++++++++++++++++++ .../internal/cronjob-tutorial/api_design.go | 42 +++++++++++--- 3 files changed, 115 insertions(+), 9 deletions(-) diff --git a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_types.go b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_types.go index 662051f80f7..968d28f559d 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_types.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_types.go @@ -107,6 +107,31 @@ type CronJobSpec struct { FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty"` } +// PodSpec is a description of a pod +type PodSpec struct { + // List of references to secrets in the same namespace to use for pulling any of the images used by this pod. + // +kubebuilder:validation:Required + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets"` + + // HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts file if specified. + // +kubebuilder:validation:Required + HostAliases []corev1.HostAlias `json:"hostAliases"` +} + +// LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace. +type LocalObjectReference struct { + // Name of the referent. + // +kubebuilder:validation:Required + Name string `json:"name"` +} + +// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file. +type HostAlias struct { + // IP address of the host file entry. + // +kubebuilder:validation:Required + IP string `json:"ip"` +} + /* We define a custom type to hold our concurrency policy. It's actually just a string under the hood, but the type gives extra documentation, diff --git a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go index 30f97db255f..8729b10f48a 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go @@ -143,3 +143,60 @@ func (in *CronJobStatus) DeepCopy() *CronJobStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HostAlias) DeepCopyInto(out *HostAlias) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostAlias. +func (in *HostAlias) DeepCopy() *HostAlias { + if in == nil { + return nil + } + out := new(HostAlias) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LocalObjectReference) DeepCopyInto(out *LocalObjectReference) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LocalObjectReference. +func (in *LocalObjectReference) DeepCopy() *LocalObjectReference { + if in == nil { + return nil + } + out := new(LocalObjectReference) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodSpec) DeepCopyInto(out *PodSpec) { + *out = *in + if in.ImagePullSecrets != nil { + in, out := &in.ImagePullSecrets, &out.ImagePullSecrets + *out = make([]corev1.LocalObjectReference, len(*in)) + copy(*out, *in) + } + if in.HostAliases != nil { + in, out := &in.HostAliases, &out.HostAliases + *out = make([]corev1.HostAlias, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodSpec. +func (in *PodSpec) DeepCopy() *PodSpec { + if in == nil { + return nil + } + out := new(PodSpec) + in.DeepCopyInto(out) + return out +} diff --git a/hack/docs/internal/cronjob-tutorial/api_design.go b/hack/docs/internal/cronjob-tutorial/api_design.go index 631587526e2..cd3834c772b 100644 --- a/hack/docs/internal/cronjob-tutorial/api_design.go +++ b/hack/docs/internal/cronjob-tutorial/api_design.go @@ -48,19 +48,18 @@ const CronjobSpecExplaination = ` the fields. */ ` - const CronjobSpecStruct = ` //+kubebuilder:validation:MinLength=0 // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. - Schedule string` + " `" + `json:"schedule"` + "`" + ` + Schedule string ` + "`json:\"schedule\"`" + ` //+kubebuilder:validation:Minimum=0 // Optional deadline in seconds for starting the job if it misses scheduled // time for any reason. Missed jobs executions will be counted as failed ones. // +optional - StartingDeadlineSeconds *int64` + " `" + `json:"startingDeadlineSeconds,omitempty"` + "`" + ` + StartingDeadlineSeconds *int64 ` + "`json:\"startingDeadlineSeconds,omitempty\"`" + ` // Specifies how to treat concurrent executions of a Job. // Valid values are: @@ -68,29 +67,54 @@ const CronjobSpecStruct = ` // - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet; // - "Replace": cancels currently running job and replaces it with a new one // +optional - ConcurrencyPolicy ConcurrencyPolicy` + " `" + `json:"concurrencyPolicy,omitempty"` + "`" + ` + ConcurrencyPolicy ConcurrencyPolicy ` + "`json:\"concurrencyPolicy,omitempty\"`" + ` // This flag tells the controller to suspend subsequent executions, it does // not apply to already started executions. Defaults to false. // +optional - Suspend *bool` + " `" + `json:"suspend,omitempty"` + "`" + ` + Suspend *bool ` + "`json:\"suspend,omitempty\"`" + ` // Specifies the job that will be created when executing a CronJob. - JobTemplate batchv1.JobTemplateSpec` + " `" + `json:"jobTemplate"` + "`" + ` + JobTemplate batchv1.JobTemplateSpec ` + "`json:\"jobTemplate\"`" + ` //+kubebuilder:validation:Minimum=0 // The number of successful finished jobs to retain. // This is a pointer to distinguish between explicit zero and not specified. // +optional - SuccessfulJobsHistoryLimit *int32` + " `" + `json:"successfulJobsHistoryLimit,omitempty"` + "`" + ` + SuccessfulJobsHistoryLimit *int32 ` + "`json:\"successfulJobsHistoryLimit,omitempty\"`" + ` //+kubebuilder:validation:Minimum=0 // The number of failed finished jobs to retain. // This is a pointer to distinguish between explicit zero and not specified. // +optional - FailedJobsHistoryLimit *int32` + " `" + `json:"failedJobsHistoryLimit,omitempty"` + "`" + ` + FailedJobsHistoryLimit *int32 ` + "`json:\"failedJobsHistoryLimit,omitempty\"`" + ` +} + +// PodSpec is a description of a pod +type PodSpec struct { + // List of references to secrets in the same namespace to use for pulling any of the images used by this pod. + // +kubebuilder:validation:Required + ImagePullSecrets []corev1.LocalObjectReference ` + "`json:\"imagePullSecrets\"`" + ` + + // HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts file if specified. + // +kubebuilder:validation:Required + HostAliases []corev1.HostAlias ` + "`json:\"hostAliases\"`" + ` +} + +// LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace. +type LocalObjectReference struct { + // Name of the referent. + // +kubebuilder:validation:Required + Name string ` + "`json:\"name\"`" + ` +} + +// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the pod's hosts file. +type HostAlias struct { + // IP address of the host file entry. + // +kubebuilder:validation:Required + IP string ` + "`json:\"ip\"`" + ` } /* @@ -124,7 +148,7 @@ const ( we want users or other controllers to be able to easily obtain. We'll keep a list of actively running jobs, as well as the last time that we successfully - ran our job. Notice that we use` + " `" + `metav1.Time` + "`" + ` instead of` + " `" + `time.Time` + "`" + ` to get the stable + ran our job. Notice that we use ` + "`metav1.Time`" + ` instead of ` + "`time.Time`" + ` to get the stable serialization, as mentioned above. */`