Skip to content

Commit aee8ebc

Browse files
authored
Merge pull request #2133 from camilamacedo86/fix-book-testdata
📖 update/fix testdata book samples
2 parents 6a23847 + 8eba033 commit aee8ebc

Some content is hidden

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

43 files changed

+393
-142
lines changed

docs/book/src/component-config-tutorial/testdata/project/apis/batch/v1/cronjob_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (r *CronJob) SetupWebhookWithManager(mgr ctrl.Manager) error {
3434

3535
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
3636

37-
// +kubebuilder:webhook:path=/mutate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,sideEffects=None,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=create;update,versions=v1,name=mcronjob.kb.io,admissionReviewVersions={v1beta1}
37+
// +kubebuilder:webhook:path=/mutate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,sideEffects=None,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=create;update,versions=v1,name=mcronjob.kb.io,sideEffects=None,admissionReviewVersions=v1
3838

3939
var _ webhook.Defaulter = &CronJob{}
4040

@@ -46,7 +46,7 @@ func (r *CronJob) Default() {
4646
}
4747

4848
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
49-
// +kubebuilder:webhook:path=/validate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,sideEffects=None,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=create;update,versions=v1,name=vcronjob.kb.io,admissionReviewVersions={v1beta1}
49+
// +kubebuilder:webhook:path=/validate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,sideEffects=None,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=create;update,versions=v1,name=vcronjob.kb.io,sideEffects=None,admissionReviewVersions=v1
5050

5151
var _ webhook.Validator = &CronJob{}
5252

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

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,72 +11,80 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14-
all: manager
14+
all: build
15+
16+
##@ General
17+
18+
# The help target prints out all targets with their descriptions organized
19+
# beneath their categories. The categories are represented by '##@' and the
20+
# target descriptions by '##'. The awk commands is responsible for reading the
21+
# entire set of makefiles included in this invocation, looking for lines of the
22+
# file as xyz: ## something, and then pretty-format the target and help. Then,
23+
# if there's a line with ##@ something, that gets pretty-printed as a category.
24+
# More info on the usage of ANSI control characters for terminal formatting:
25+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
26+
# More info on the awk command:
27+
# http://linuxcommand.org/lc3_adv_awk.php
28+
29+
help: ## Display this help.
30+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
31+
32+
##@ Development
33+
34+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
35+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
36+
37+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
38+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
39+
40+
fmt: ## Run go fmt against code.
41+
go fmt ./...
42+
43+
vet: ## Run go vet against code.
44+
go vet ./...
1545

16-
# Run tests
1746
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
18-
test: generate fmt vet manifests
47+
test: manifests generate fmt vet ## Run tests.
1948
mkdir -p ${ENVTEST_ASSETS_DIR}
20-
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
49+
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
2150
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
2251

23-
# Build manager binary
24-
manager: generate fmt vet
52+
##@ Build
53+
54+
build: generate fmt vet ## Build manager binary.
2555
go build -o bin/manager main.go
2656

27-
# Run against the configured Kubernetes cluster in ~/.kube/config
28-
run: generate fmt vet manifests
57+
run: manifests generate fmt vet ## Run a controller from your host.
2958
go run ./main.go
3059

31-
# Install CRDs into a cluster
32-
install: manifests kustomize
60+
docker-build: test ## Build docker image with the manager.
61+
docker build -t ${IMG} .
62+
63+
docker-push: ## Push docker image with the manager.
64+
docker push ${IMG}
65+
66+
##@ Deployment
67+
68+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
3369
$(KUSTOMIZE) build config/crd | kubectl apply -f -
3470

35-
# Uninstall CRDs from a cluster
36-
uninstall: manifests kustomize
71+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
3772
$(KUSTOMIZE) build config/crd | kubectl delete -f -
3873

39-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
40-
deploy: manifests kustomize
74+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
4175
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
4276
$(KUSTOMIZE) build config/default | kubectl apply -f -
4377

44-
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
45-
undeploy:
78+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
4679
$(KUSTOMIZE) build config/default | kubectl delete -f -
4780

48-
# Generate manifests e.g. CRD, RBAC etc.
49-
manifests: controller-gen
50-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
51-
52-
# Run go fmt against code
53-
fmt:
54-
go fmt ./...
55-
56-
# Run go vet against code
57-
vet:
58-
go vet ./...
59-
60-
# Generate code
61-
generate: controller-gen
62-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
63-
64-
# Build the docker image
65-
docker-build: test
66-
docker build -t ${IMG} .
67-
68-
# Push the docker image
69-
docker-push:
70-
docker push ${IMG}
7181

72-
# Download controller-gen locally if necessary
7382
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
74-
controller-gen:
83+
controller-gen: ## Download controller-gen locally if necessary.
7584
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
7685

77-
# Download kustomize locally if necessary
7886
KUSTOMIZE = $(shell pwd)/bin/kustomize
79-
kustomize:
87+
kustomize: ## Download kustomize locally if necessary.
8088
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
8189

8290
# go-get-tool will 'go get' any package $2 and install it to $1.
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
domain: tutorial.kubebuilder.io
2-
layout: go.kubebuilder.io/v3
2+
layout:
3+
- go.kubebuilder.io/v3
34
projectName: project
45
repo: tutorial.kubebuilder.io/project
56
resources:
67
- api:
78
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: tutorial.kubebuilder.io
812
group: batch
913
kind: CronJob
14+
path: tutorial.kubebuilder.io/project/api/v1
1015
version: v1
1116
webhooks:
17+
defaulting: true
18+
validation: true
1219
webhookVersion: v1
13-
version: 3-alpha
20+
version: "3"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes authors.
2+
Copyright 2021 The Kubernetes authors.
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/cronjob-tutorial/testdata/project/api/v1/cronjob_webhook.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes authors.
2+
Copyright 2021 The Kubernetes authors.
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.
@@ -54,7 +54,7 @@ This marker is responsible for generating a mutating webhook manifest.
5454
The meaning of each marker can be found [here](/reference/markers/webhook.md).
5555
*/
5656

57-
//+kubebuilder:webhook:path=/mutate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=create;update,versions=v1,name=mcronjob.kb.io
57+
//+kubebuilder:webhook:path=/mutate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=true,failurePolicy=fail,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=create;update,versions=v1,name=mcronjob.kb.io,sideEffects=None,admissionReviewVersions=v1
5858

5959
/*
6060
We use the `webhook.Defaulter` interface to set defaults to our CRD.
@@ -89,8 +89,7 @@ func (r *CronJob) Default() {
8989
This marker is responsible for generating a validating webhook manifest.
9090
*/
9191

92-
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
93-
//+kubebuilder:webhook:verbs=create;update,path=/validate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,versions=v1,name=vcronjob.kb.io
92+
//+kubebuilder:webhook:verbs=create;update;delete,path=/validate-batch-tutorial-kubebuilder-io-v1-cronjob,mutating=false,failurePolicy=fail,groups=batch.tutorial.kubebuilder.io,resources=cronjobs,versions=v1,name=vcronjob.kb.io,sideEffects=None,admissionReviewVersions=v1
9493

9594
/*
9695
To validate our CRD beyond what's possible with declarative validation.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes authors.
2+
Copyright 2021 The Kubernetes authors.
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/cronjob-tutorial/testdata/project/api/v1/webhook_suite_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes authors.
2+
Copyright 2021 The Kubernetes authors.
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.
@@ -64,7 +64,8 @@ var _ = BeforeSuite(func() {
6464

6565
By("bootstrapping test environment")
6666
testEnv = &envtest.Environment{
67-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
67+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
68+
ErrorIfCRDPathMissing: false,
6869
WebhookInstallOptions: envtest.WebhookInstallOptions{
6970
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
7071
},

docs/book/src/cronjob-tutorial/testdata/project/api/v1/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/cronjob-tutorial/testdata/project/config/manager/manager.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
control-plane: controller-manager
2424
spec:
2525
securityContext:
26-
runAsUser: 65532
26+
runAsNonRoot: true
2727
containers:
2828
- command:
2929
- /manager
@@ -52,4 +52,5 @@ spec:
5252
requests:
5353
cpu: 100m
5454
memory: 20Mi
55+
serviceAccountName: controller-manager
5556
terminationGracePeriodSeconds: 10

docs/book/src/cronjob-tutorial/testdata/project/config/rbac/auth_proxy_role_binding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ roleRef:
88
name: proxy-role
99
subjects:
1010
- kind: ServiceAccount
11-
name: default
11+
name: controller-manager
1212
namespace: system

0 commit comments

Comments
 (0)