Skip to content

Commit

Permalink
cronjob-tutorial: fix issue faced after upgrade of controller-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed May 16, 2024
1 parent 1f2e54f commit 35221b4
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 33 additions & 9 deletions hack/docs/internal/cronjob-tutorial/api_design.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,73 @@ 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:
// - "Allow" (default): allows CronJobs to run concurrently;
// - "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\"`" + `
}
/*
Expand Down Expand Up @@ -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.
*/`

Expand Down

0 comments on commit 35221b4

Please sign in to comment.