Skip to content

Commit f2b0119

Browse files
authored
📖 : update ComponentConfig tutorial (#3181)
docs: update ComponentConfig
1 parent da54c08 commit f2b0119

File tree

12 files changed

+129
-307
lines changed

12 files changed

+129
-307
lines changed

docs/book/src/component-config-tutorial/config-type.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ To scaffold out a new config Kind, we can use `kubebuilder create api`.
66
kubebuilder create api --group config --version v2 --kind ProjectConfig --resource --controller=false --make=false
77
```
88

9+
Then, run `make build` to implement the interface for your API type, which would generate the file `zz_generated.deepcopy.go`.
910

1011
<aside class="note">
1112

@@ -18,9 +19,9 @@ intended to be an API extension and cannot be reconciled.
1819
</aside>
1920

2021
This will create a new type file in `api/config/v2/` for the `ProjectConfig`
21-
kind. We'll need to change this file to embed the
22+
kind. We'll need to change this file to embed the
2223
[v1alpha1.ControllerManagerConfigurationSpec](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/config/v1alpha1/#ControllerManagerConfigurationSpec)
2324

2425
{{#literatego ./testdata/projectconfig_types.go}}
2526

26-
Lastly, we'll change the `main.go` to reference this type for parsing the file.
27+
Lastly, we'll change the `main.go` to reference this type for parsing the file.

docs/book/src/component-config-tutorial/testdata/project/Makefile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ test: manifests generate fmt vet envtest ## Run tests.
6161
##@ Build
6262

6363
.PHONY: build
64-
build: generate fmt vet ## Build manager binary.
64+
build: manifests generate fmt vet ## Build manager binary.
6565
go build -o bin/manager main.go
6666

6767
.PHONY: run
@@ -92,7 +92,7 @@ docker-buildx: test ## Build and push docker image for the manager for cross-pla
9292
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
9393
- docker buildx create --name project-v3-builder
9494
docker buildx use project-v3-builder
95-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
95+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
9696
- docker buildx rm project-v3-builder
9797
rm Dockerfile.cross
9898

@@ -132,19 +132,24 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
132132
ENVTEST ?= $(LOCALBIN)/setup-envtest
133133

134134
## Tool Versions
135-
KUSTOMIZE_VERSION ?= v4.5.7
136-
CONTROLLER_TOOLS_VERSION ?= v0.10.0
135+
KUSTOMIZE_VERSION ?= v3.8.7
136+
CONTROLLER_TOOLS_VERSION ?= v0.11.1
137137

138138
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
139139
.PHONY: kustomize
140-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
140+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
141141
$(KUSTOMIZE): $(LOCALBIN)
142+
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
143+
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
144+
rm -rf $(LOCALBIN)/kustomize; \
145+
fi
142146
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
143147

144148
.PHONY: controller-gen
145-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
149+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
146150
$(CONTROLLER_GEN): $(LOCALBIN)
147-
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
151+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
152+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
148153

149154
.PHONY: envtest
150155
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.

docs/book/src/component-config-tutorial/testdata/project/PROJECT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
componentConfig: true
26
domain: tutorial.kubebuilder.io
37
layout:

docs/book/src/component-config-tutorial/testdata/project/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ kubectl apply -f config/samples/
1616
```
1717

1818
2. Build and push your image to the location specified by `IMG`:
19-
19+
2020
```sh
2121
make docker-build docker-push IMG=<some-registry>/project:tag
2222
```
23-
23+
2424
3. Deploy the controller to the cluster with the image specified by `IMG`:
2525

2626
```sh
@@ -35,7 +35,7 @@ make uninstall
3535
```
3636

3737
### Undeploy controller
38-
UnDeploy the controller to the cluster:
38+
UnDeploy the controller from the cluster:
3939

4040
```sh
4141
make undeploy
@@ -45,10 +45,10 @@ make undeploy
4545
// TODO(user): Add detailed information on how you would like others to contribute to this project
4646

4747
### How it works
48-
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
48+
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/).
4949

50-
It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
51-
which provides a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster
50+
It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/),
51+
which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.
5252

5353
### Test It Out
5454
1. Install the CRDs into the cluster:
@@ -78,7 +78,7 @@ More information can be found via the [Kubebuilder Documentation](https://book.k
7878

7979
## License
8080

81-
Copyright 2022 The Kubernetes authors.
81+
Copyright 2023.
8282

8383
Licensed under the Apache License, Version 2.0 (the "License");
8484
you may not use this file except in compliance with the License.

docs/book/src/component-config-tutorial/testdata/project/api/v2/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Kubernetes authors.
2+
Copyright 2023.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

docs/book/src/component-config-tutorial/testdata/project/api/v2/projectconfig_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Kubernetes authors.
2+
Copyright 2023.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

docs/book/src/component-config-tutorial/testdata/project/api/v2/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/component-config-tutorial/testdata/project/config/crd/bases/config.tutorial.kubebuilder.io_projectconfigs.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.10.0
6+
controller-gen.kubebuilder.io/version: v0.11.1
77
creationTimestamp: null
88
name: projectconfigs.config.tutorial.kubebuilder.io
99
spec:
@@ -56,6 +56,9 @@ spec:
5656
in form with GroupKind.String(), e.g. ReplicaSet in apps group (regardless
5757
of version) would be `ReplicaSet.apps`."
5858
type: object
59+
recoverPanic:
60+
description: RecoverPanic indicates if panics should be recovered.
61+
type: boolean
5962
type: object
6063
gracefulShutDown:
6164
description: GracefulShutdownTimeout is the duration given to runnable
@@ -69,7 +72,8 @@ spec:
6972
properties:
7073
healthProbeBindAddress:
7174
description: HealthProbeBindAddress is the TCP address that the controller
72-
should bind to for serving health probes
75+
should bind to for serving health probes It can be set to "0" or
76+
"" to disable serving the health probe.
7377
type: string
7478
livenessEndpointName:
7579
description: LivenessEndpointName, defaults to "healthz"

docs/book/src/component-config-tutorial/testdata/project/go.mod

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,65 @@ module tutorial.kubebuilder.io/project
33
go 1.19
44

55
require (
6-
k8s.io/apimachinery v0.25.0
7-
k8s.io/client-go v0.25.0
8-
sigs.k8s.io/controller-runtime v0.13.0
6+
k8s.io/apimachinery v0.26.0
7+
k8s.io/client-go v0.26.0
8+
sigs.k8s.io/controller-runtime v0.14.1
99
)
1010

1111
require (
12-
cloud.google.com/go v0.97.0 // indirect
13-
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
14-
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
15-
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
16-
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
17-
github.com/Azure/go-autorest/logger v0.2.1 // indirect
18-
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
19-
github.com/PuerkitoBio/purell v1.1.1 // indirect
20-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
2112
github.com/beorn7/perks v1.0.1 // indirect
2213
github.com/cespare/xxhash/v2 v2.1.2 // indirect
2314
github.com/davecgh/go-spew v1.1.1 // indirect
24-
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
15+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
2516
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
26-
github.com/fsnotify/fsnotify v1.5.4 // indirect
17+
github.com/fsnotify/fsnotify v1.6.0 // indirect
2718
github.com/go-logr/logr v1.2.3 // indirect
2819
github.com/go-logr/zapr v1.2.3 // indirect
2920
github.com/go-openapi/jsonpointer v0.19.5 // indirect
30-
github.com/go-openapi/jsonreference v0.19.5 // indirect
21+
github.com/go-openapi/jsonreference v0.20.0 // indirect
3122
github.com/go-openapi/swag v0.19.14 // indirect
3223
github.com/gogo/protobuf v1.3.2 // indirect
33-
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
3424
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3525
github.com/golang/protobuf v1.5.2 // indirect
3626
github.com/google/gnostic v0.5.7-v3refs // indirect
37-
github.com/google/go-cmp v0.5.8 // indirect
27+
github.com/google/go-cmp v0.5.9 // indirect
3828
github.com/google/gofuzz v1.1.0 // indirect
3929
github.com/google/uuid v1.1.2 // indirect
40-
github.com/imdario/mergo v0.3.12 // indirect
30+
github.com/imdario/mergo v0.3.6 // indirect
4131
github.com/josharian/intern v1.0.0 // indirect
4232
github.com/json-iterator/go v1.1.12 // indirect
4333
github.com/mailru/easyjson v0.7.6 // indirect
44-
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
34+
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
4535
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4636
github.com/modern-go/reflect2 v1.0.2 // indirect
4737
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4838
github.com/pkg/errors v0.9.1 // indirect
49-
github.com/prometheus/client_golang v1.12.2 // indirect
50-
github.com/prometheus/client_model v0.2.0 // indirect
51-
github.com/prometheus/common v0.32.1 // indirect
52-
github.com/prometheus/procfs v0.7.3 // indirect
39+
github.com/prometheus/client_golang v1.14.0 // indirect
40+
github.com/prometheus/client_model v0.3.0 // indirect
41+
github.com/prometheus/common v0.37.0 // indirect
42+
github.com/prometheus/procfs v0.8.0 // indirect
5343
github.com/spf13/pflag v1.0.5 // indirect
5444
go.uber.org/atomic v1.7.0 // indirect
5545
go.uber.org/multierr v1.6.0 // indirect
56-
go.uber.org/zap v1.21.0 // indirect
57-
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
58-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
59-
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
60-
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
61-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
62-
golang.org/x/text v0.3.7 // indirect
63-
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
46+
go.uber.org/zap v1.24.0 // indirect
47+
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
48+
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
49+
golang.org/x/sys v0.3.0 // indirect
50+
golang.org/x/term v0.3.0 // indirect
51+
golang.org/x/text v0.5.0 // indirect
52+
golang.org/x/time v0.3.0 // indirect
6453
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
6554
google.golang.org/appengine v1.6.7 // indirect
66-
google.golang.org/protobuf v1.28.0 // indirect
55+
google.golang.org/protobuf v1.28.1 // indirect
6756
gopkg.in/inf.v0 v0.9.1 // indirect
6857
gopkg.in/yaml.v2 v2.4.0 // indirect
6958
gopkg.in/yaml.v3 v3.0.1 // indirect
70-
k8s.io/api v0.25.0 // indirect
71-
k8s.io/apiextensions-apiserver v0.25.0 // indirect
72-
k8s.io/component-base v0.25.0 // indirect
73-
k8s.io/klog/v2 v2.70.1 // indirect
74-
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
75-
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
59+
k8s.io/api v0.26.0 // indirect
60+
k8s.io/apiextensions-apiserver v0.26.0 // indirect
61+
k8s.io/component-base v0.26.0 // indirect
62+
k8s.io/klog/v2 v2.80.1 // indirect
63+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
64+
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
7665
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
7766
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
7867
sigs.k8s.io/yaml v1.3.0 // indirect

0 commit comments

Comments
 (0)