Skip to content

Commit e607dd5

Browse files
decouple webhooks from APIs dir
1 parent 6dd2130 commit e607dd5

File tree

75 files changed

+707
-5477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+707
-5477
lines changed

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ help: ## Display this help.
4545

4646
.PHONY: manifests
4747
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
48-
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
49-
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
50-
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
51-
# 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.
52-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
48+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
5349

5450
.PHONY: generate
5551
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ limitations under the License.
1919
*/
2020

2121
package v1
22-
2322
/*
2423
*/
2524

@@ -62,6 +61,7 @@ import (
6261
the fields.
6362
*/
6463

64+
6565
// CronJobSpec defines the desired state of CronJob.
6666
type CronJobSpec struct {
6767
// +kubebuilder:validation:MinLength=0
@@ -188,5 +188,4 @@ type CronJobList struct {
188188
func init() {
189189
SchemeBuilder.Register(&CronJob{}, &CronJobList{})
190190
}
191-
192191
// +kubebuilder:docs-gen:collapse=Root Object Definitions

docs/book/src/cronjob-tutorial/testdata/project/api/v1/cronjob_webhook_test.go

Lines changed: 0 additions & 164 deletions
This file was deleted.

docs/book/src/cronjob-tutorial/testdata/project/api/v1/groupversion_info.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
// +kubebuilder:docs-gen:collapse=Apache License
17-
18-
/*
19-
First, we have some *package-level* markers that denote that there are
20-
Kubernetes objects in this package, and that this package represents the group
21-
`batch.tutorial.kubebuilder.io`. The `object` generator makes use of the
22-
former, while the latter is used by the CRD generator to generate the right
23-
metadata for the CRDs it creates from this package.
24-
*/
2516

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

36-
/*
37-
Then, we have the commonly useful variables that help us set up our Scheme.
38-
Since we need to use all the types in this package in our controller, it's
39-
helpful (and the convention) to have a convenient method to add all the types to
40-
some other `Scheme`. SchemeBuilder makes this easy for us.
41-
*/
42-
4327
var (
4428
// GroupVersion is group version used to register these objects.
4529
GroupVersion = schema.GroupVersion{Group: "batch.tutorial.kubebuilder.io", Version: "v1"}

docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go

Lines changed: 3 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
// +kubebuilder:docs-gen:collapse=Apache License
1716

1817
package main
1918

@@ -41,17 +40,6 @@ import (
4140
// +kubebuilder:scaffold:imports
4241
)
4342

44-
// +kubebuilder:docs-gen:collapse=Imports
45-
46-
/*
47-
The first difference to notice is that kubebuilder has added the new API
48-
group's package (`batchv1`) to our scheme. This means that we can use those
49-
objects in our controller.
50-
51-
If we would be using any other CRD we would have to add their scheme the same way.
52-
Builtin types such as Job have their scheme added by `clientgoscheme`.
53-
*/
54-
5543
var (
5644
scheme = runtime.NewScheme()
5745
setupLog = ctrl.Log.WithName("setup")
@@ -64,14 +52,7 @@ func init() {
6452
// +kubebuilder:scaffold:scheme
6553
}
6654

67-
/*
68-
The other thing that's changed is that kubebuilder has added a block calling our
69-
CronJob controller's `SetupWithManager` method.
70-
*/
71-
7255
func main() {
73-
/*
74-
*/
7556
var metricsAddr string
7657
var enableLeaderElection bool
7758
var probeAddr string
@@ -163,24 +144,13 @@ func main() {
163144
os.Exit(1)
164145
}
165146

166-
// +kubebuilder:docs-gen:collapse=old stuff
167-
168147
if err = (&controller.CronJobReconciler{
169148
Client: mgr.GetClient(),
170149
Scheme: mgr.GetScheme(),
171150
}).SetupWithManager(mgr); err != nil {
172151
setupLog.Error(err, "unable to create controller", "controller", "CronJob")
173152
os.Exit(1)
174153
}
175-
176-
/*
177-
We'll also set up webhooks for our type, which we'll talk about next.
178-
We just need to add them to the manager. Since we might want to run
179-
the webhooks separately, or not run them when testing our controller
180-
locally, we'll put them behind an environment variable.
181-
182-
We'll just make sure to set `ENABLE_WEBHOOKS=false` when we run locally.
183-
*/
184154
// nolint:goconst
185155
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
186156
if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
@@ -204,5 +174,4 @@ func main() {
204174
setupLog.Error(err, "problem running manager")
205175
os.Exit(1)
206176
}
207-
// +kubebuilder:docs-gen:collapse=old stuff
208177
}

0 commit comments

Comments
 (0)