Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ func main() {
tlsOpts = append(tlsOpts, disableHTTP2)
}

// +kubebuilder:docs-gen:collapse=Manager Setup

// Initial webhook TLS options
webhookTLSOpts := tlsOpts
webhookServerOptions := webhook.Options{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
batchv2 "tutorial.kubebuilder.io/project/api/v2"
)

// +kubebuilder:docs-gen:collapse=Imports

// nolint:unused
// log is for logging in this package.
var cronjoblog = logf.Log.WithName("cronjob-resource")
Expand Down Expand Up @@ -157,6 +159,8 @@ func (d *CronJobCustomDefaulter) applyDefaults(cronJob *batchv2.CronJob) {
}
}

// +kubebuilder:docs-gen:collapse=Webhook Setup and Defaulting

// validateCronJob validates the fields of a CronJob object.
func validateCronJob(cronjob *batchv2.CronJob) error {
var allErrs field.ErrorList
Expand Down
23 changes: 15 additions & 8 deletions hack/docs/internal/multiversion-tutorial/generate_multiversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,16 @@ func (sp *Sample) updateWebhookV2() {
)
hackutils.CheckError("replacing imports in v2", err)

// Add collapse marker after the import block to hide imports
err = pluginutil.InsertCode(
filepath.Join(sp.ctx.Dir, path),
`batchv2 "tutorial.kubebuilder.io/project/api/v2"
)`,
`

// +kubebuilder:docs-gen:collapse=Imports`)
hackutils.CheckError("adding imports collapse marker to webhook v2", err)

err = pluginutil.ReplaceInFile(
filepath.Join(sp.ctx.Dir, path),
`// TODO(user): Add more fields as needed for defaulting`,
Expand Down Expand Up @@ -493,17 +503,14 @@ CronJob controller's `+"`SetupWithManager`"+` method.

err = pluginutil.InsertCode(
filepath.Join(sp.ctx.Dir, path),
`if err := (&controller.CronJobReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CronJob")
os.Exit(1)
`if !enableHTTP2 {
tlsOpts = append(tlsOpts, disableHTTP2)
}`,
`
`,

// +kubebuilder:docs-gen:collapse=Manager Setup`,
)
hackutils.CheckError("insert doc marker existing setup main.go", err)
hackutils.CheckError("adding manager setup collapse marker main.go", err)

err = pluginutil.ReplaceInFile(
filepath.Join(sp.ctx.Dir, path),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ func (d *CronJobCustomDefaulter) applyDefaults(cronJob *batchv2.CronJob) {
}
if cronJob.Spec.FailedJobsHistoryLimit == nil {
cronJob.Spec.FailedJobsHistoryLimit = new(int32)
*cronJob.Spec.FailedJobsHistoryLimit = d.DefaultFailedJobsHistoryLimit
*cronJob.Spec .FailedJobsHistoryLimit = d.DefaultFailedJobsHistoryLimit
}
}
`

const cronJobValidationFunction = `
// +kubebuilder:docs-gen:collapse=Webhook Setup and Defaulting
// validateCronJob validates the fields of a CronJob object.
func validateCronJob(cronjob *batchv2.CronJob) error {
var allErrs field.ErrorList
Expand Down