Skip to content

Commit

Permalink
decouple webhooks from APIs dir
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Sep 9, 2024
1 parent 6dd2130 commit e607dd5
Show file tree
Hide file tree
Showing 75 changed files with 707 additions and 5,477 deletions.
6 changes: 1 addition & 5 deletions docs/book/src/cronjob-tutorial/testdata/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ help: ## Display this help.

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
# However, it has a size limit and if the CRD is too big with so many long descriptions as this one it will cause the failure.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
*/

package v1

/*
*/

Expand Down Expand Up @@ -62,6 +61,7 @@ import (
the fields.
*/


// CronJobSpec defines the desired state of CronJob.
type CronJobSpec struct {
// +kubebuilder:validation:MinLength=0
Expand Down Expand Up @@ -188,5 +188,4 @@ type CronJobList struct {
func init() {
SchemeBuilder.Register(&CronJob{}, &CronJobList{})
}

// +kubebuilder:docs-gen:collapse=Root Object Definitions

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +kubebuilder:docs-gen:collapse=Apache License

/*
First, we have some *package-level* markers that denote that there are
Kubernetes objects in this package, and that this package represents the group
`batch.tutorial.kubebuilder.io`. The `object` generator makes use of the
former, while the latter is used by the CRD generator to generate the right
metadata for the CRDs it creates from this package.
*/

// Package v1 contains API Schema definitions for the batch v1 API group.
// +kubebuilder:object:generate=true
Expand All @@ -33,13 +24,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

/*
Then, we have the commonly useful variables that help us set up our Scheme.
Since we need to use all the types in this package in our controller, it's
helpful (and the convention) to have a convenient method to add all the types to
some other `Scheme`. SchemeBuilder makes this easy for us.
*/

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "batch.tutorial.kubebuilder.io", Version: "v1"}
Expand Down

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

31 changes: 0 additions & 31 deletions docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +kubebuilder:docs-gen:collapse=Apache License

package main

Expand Down Expand Up @@ -41,17 +40,6 @@ import (
// +kubebuilder:scaffold:imports
)

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

/*
The first difference to notice is that kubebuilder has added the new API
group's package (`batchv1`) to our scheme. This means that we can use those
objects in our controller.
If we would be using any other CRD we would have to add their scheme the same way.
Builtin types such as Job have their scheme added by `clientgoscheme`.
*/

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand All @@ -64,14 +52,7 @@ func init() {
// +kubebuilder:scaffold:scheme
}

/*
The other thing that's changed is that kubebuilder has added a block calling our
CronJob controller's `SetupWithManager` method.
*/

func main() {
/*
*/
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
Expand Down Expand Up @@ -163,24 +144,13 @@ func main() {
os.Exit(1)
}

// +kubebuilder:docs-gen:collapse=old stuff

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)
}

/*
We'll also set up webhooks for our type, which we'll talk about next.
We just need to add them to the manager. Since we might want to run
the webhooks separately, or not run them when testing our controller
locally, we'll put them behind an environment variable.
We'll just make sure to set `ENABLE_WEBHOOKS=false` when we run locally.
*/
// nolint:goconst
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
Expand All @@ -204,5 +174,4 @@ func main() {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
// +kubebuilder:docs-gen:collapse=old stuff
}
Loading

0 comments on commit e607dd5

Please sign in to comment.