Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dab613d
This commit stabilizes plugin go/v3-alpha to go/v3 and makes it
estroz Dec 3, 2020
a08bbfb
Fix the path of probes
zoetrope Dec 14, 2020
6e1f8d0
Merge pull request #1905 from zoetrope/fix-probe
k8s-ci-robot Dec 14, 2020
0a807f4
Merge pull request #1882 from estroz/feature/stabilize-go-v3
k8s-ci-robot Dec 14, 2020
7dc4d33
:sparkles: add new extension to markers in order to allow work with .yml
camilamacedo86 Dec 15, 2020
a4ad49a
Merge pull request #1907 from camilamacedo86/add-marker-extension
k8s-ci-robot Dec 15, 2020
90a7ad3
:warning: change structure to store crdVersion and webhkversion (go/v…
camilamacedo86 Dec 11, 2020
762211a
Merge pull request #1899 from camilamacedo86/fix-crd-web-version
k8s-ci-robot Dec 15, 2020
e604838
sparkles: (go/v3-alpha) Add the --force option for the webhook
prafull01 Dec 15, 2020
bba9577
Merge pull request #1903 from prafull01/force-webhook
k8s-ci-robot Dec 15, 2020
258470c
:sparkles: Add the unit tests for HasWebhook
prafull01 Dec 16, 2020
c9114ed
Merge pull request #1909 from prafull01/config-unit-test
k8s-ci-robot Dec 16, 2020
0c02833
:bug: Fix --force option to recreate the files by kubebuilder create api
prafull01 Nov 19, 2020
a4d0a3a
Merge pull request #1847 from prafull01/kb-force
k8s-ci-robot Dec 16, 2020
9ee7a30
Remove spaces from machine-readable comments (v3 only)
Adirio Dec 2, 2020
7245d41
Merge pull request #1868 from Adirio/machine-readable-markers
k8s-ci-robot Dec 17, 2020
6cf73c3
:book: update the docs by removng--plugin=v3/alpha since it no longer…
camilamacedo86 Dec 18, 2020
65f9853
:book: update samples
camilamacedo86 Dec 18, 2020
948887a
Merge pull request #1918 from camilamacedo86/update-docs-testdata-v3
k8s-ci-robot Dec 18, 2020
0082e95
:book: add info to tutorial about apis with examples
camilamacedo86 Dec 18, 2020
ea7e28e
Merge pull request #1920 from camilamacedo86/api-doc-add-info
k8s-ci-robot Dec 21, 2020
8097960
:seedling: Move the license year to 2021 in testdata
prafull01 Jan 5, 2021
23b7082
Merge pull request #1929 from prafull01/copyright-year
k8s-ci-robot Jan 5, 2021
aa9c2e0
Use lowered resource kind as file name
south37 Dec 29, 2020
f660017
Merge pull request #1927 from south37/use-lowered-resource-kind-as-fi…
k8s-ci-robot Jan 6, 2021
26d7b42
Merge pull request #1919 from camilamacedo86/fix-doc-v3-stable
k8s-ci-robot Jan 7, 2021
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
8 changes: 2 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ func main() {
&pluginv2.Plugin{},
&pluginv3.Plugin{},
),
cli.WithDefaultPlugins(config.Version2,
&pluginv2.Plugin{},
),
cli.WithDefaultPlugins(config.Version3Alpha,
&pluginv2.Plugin{},
),
cli.WithDefaultPlugins(config.Version2, &pluginv2.Plugin{}),
cli.WithDefaultPlugins(config.Version3Alpha, &pluginv3.Plugin{}),
cli.WithCompletion,
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/component-config-tutorial/api-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ steps](/quick-start.md#installation) before continuing.
```bash
# we'll use a domain of tutorial.kubebuilder.io,
# so all API groups will be <group>.tutorial.kubebuilder.io.
kubebuilder init --plugins=go/v3-alpha --domain tutorial.kubebuilder.io --component-config
kubebuilder init --domain tutorial.kubebuilder.io --component-config
```

## Setting up an exising project
Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/cronjob-tutorial/cronjob-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ project:
```bash
# we'll use a domain of tutorial.kubebuilder.io,
# so all API groups will be <group>.tutorial.kubebuilder.io.
kubebuilder init --plugins=go/v3-alpha --domain tutorial.kubebuilder.io
kubebuilder init --domain tutorial.kubebuilder.io
```

<aside class="note">
Expand Down
21 changes: 21 additions & 0 deletions docs/book/src/cronjob-tutorial/gvks.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ a package.
Now that we have our terminology straight, we can *actually* create our
API!

## So, how can we create our API?

In the next section, [Adding a new API](./cronjob-tutorial/new-api.html) we will check how the tool help us to create our own API's with the command `kubebuilder create api`.

The goal of this command is to create Custom Resource (CR) and Custom Resource Definition (CRD) for our Kind(s). To check it further see; [Extend the Kubernetes API with CustomResourceDefinitions][kubernetes-extend-api].

## But, why create APIs at all?

New APIs are how we teach Kubernetes about our custom objects. The Go structs are used to generate a Custom Resource Definition (CRD) which includes the schema for our data as well as tracking data like what our new type is called. We can then create instances of our custom objects which will be managed by our [controllers][controllers].

Our APIs and resouces represent our solutions on the clusters. Basically, the CRDs are a definition of our customized Objects, and the CRs are an instance of it.

## Ah, do you have an example?

Let’s think about the classic scenario where the goal is to have an application and its database running on the platform with Kubernetes. Then, one CRD could represent the App, and another one could represent the DB. By having one CRD to describe the App and another one for the DB, we will not be hurting concepts such as encapsulation, the single responsibility principle, and cohesion. Damaging these concepts could cause unexpected side effects, such as difficulty in extending, reuse, or maintenance, just to mention a few.

In this way, we can create the App CRD which will have its controller and which would be responsible for things like creating Deployments that contain the App and creating Services to access it and etc. Similarly, we could create a CRD to represent the DB, and deploy a controller that would manage DB instances.

## Err, but what's that Scheme thing?

The `Scheme` we saw before is simply a way to keep track of what Go type
Expand All @@ -70,3 +88,6 @@ API server that says

or properly look up the group-version when we go to submit a `&CronJob{}`
in an update.

[kubernetes-extend-api]: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/
[controllers]: ../cronjob-tutorial/controller-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function gen_cronjob_tutorial {
mkdir project
cd project
header_text "creating tutorial.kubebuilder.io base ..."
kubebuilder init --plugins=go/v3-alpha --domain=tutorial.kubebuilder.io --project-version=3-alpha --repo=tutorial.kubebuilder.io/project --license apache2 --owner "The Kubernetes authors"
kubebuilder init --domain=tutorial.kubebuilder.io --project-version=3-alpha --repo=tutorial.kubebuilder.io/project --license apache2 --owner "The Kubernetes authors"
kubebuilder create api --group batch --version v1 --kind CronJob --resource --controller
kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation
}
Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/cronjob-tutorial/testdata/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all: manager
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
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-alpha.6/hack/setup-envtest.sh
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
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

# Build manager binary
Expand Down
8 changes: 5 additions & 3 deletions docs/book/src/cronjob-tutorial/testdata/project/PROJECT
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
domain: tutorial.kubebuilder.io
layout: go.kubebuilder.io/v3-alpha
layout: go.kubebuilder.io/v3
projectName: project
repo: tutorial.kubebuilder.io/project
resources:
- crdVersion: v1
- api:
crdVersion: v1
group: batch
kind: CronJob
version: v1
webhookVersion: v1
webhooks:
webhookVersion: v1
version: 3-alpha
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ the fields.

// CronJobSpec defines the desired state of CronJob
type CronJobSpec struct {
// +kubebuilder:validation:MinLength=0
//+kubebuilder:validation:MinLength=0

// The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
Schedule string `json:"schedule"`

// +kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Minimum=0

// Optional deadline in seconds for starting the job if it misses scheduled
// time for any reason. Missed jobs executions will be counted as failed ones.
Expand All @@ -90,14 +90,14 @@ type CronJobSpec struct {
// Specifies the job that will be created when executing a CronJob.
JobTemplate batchv1beta1.JobTemplateSpec `json:"jobTemplate"`

// +kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Minimum=0

// The number of successful finished jobs to retain.
// This is a pointer to distinguish between explicit zero and not specified.
// +optional
SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty"`

// +kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Minimum=0

// The number of failed finished jobs to retain.
// This is a pointer to distinguish between explicit zero and not specified.
Expand Down Expand Up @@ -160,8 +160,8 @@ As previously noted, we don't need to change this, except to mark that
we want a status subresource, so that we behave like built-in kubernetes types.
*/

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// CronJob is the Schema for the cronjobs API
type CronJob struct {
Expand All @@ -174,7 +174,7 @@ type CronJob struct {
Status CronJobStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
//+kubebuilder:object:root=true

// CronJobList contains a list of CronJob
type CronJobList struct {
Expand All @@ -187,4 +187,4 @@ func init() {
SchemeBuilder.Register(&CronJob{}, &CronJobList{})
}

// +kubebuilder:docs-gen:collapse=Root Object Definitions
//+kubebuilder:docs-gen:collapse=Root Object Definitions
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ This marker is responsible for generating a mutating webhook manifest.
The meaning of each marker can be found [here](/reference/markers/webhook.md).
*/

// +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
//+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

/*
We use the `webhook.Defaulter` interface to set defaults to our CRD.
Expand Down Expand Up @@ -90,7 +90,7 @@ This marker is responsible for generating a validating webhook manifest.
*/

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
// +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
//+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

/*
To validate our CRD beyond what's possible with declarative validation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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
// +groupName=batch.tutorial.kubebuilder.io
//+kubebuilder:object:generate=true
//+groupName=batch.tutorial.kubebuilder.io
package v1

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
// +kubebuilder:scaffold:imports
//+kubebuilder:scaffold:imports
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -81,7 +81,7 @@ var _ = BeforeSuite(func() {
err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())

// +kubebuilder:scaffold:scheme
//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme})
Expect(err).NotTo(HaveOccurred())
Expand All @@ -102,7 +102,7 @@ var _ = BeforeSuite(func() {
err = (&CronJob{}).SetupWebhookWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

// +kubebuilder:scaffold:webhook
//+kubebuilder:scaffold:webhook

go func() {
err = mgr.Start(ctx)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# The following manifests contain a self-signed issuer CR and a certificate CR.
# More document can be found at https://docs.cert-manager.io
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for
# breaking changes
apiVersion: cert-manager.io/v1alpha2
# WARNING: Targets CertManager v1.0. Check https://cert-manager.io/docs/installation/upgrading/ for breaking changes.
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: selfsigned-issuer
namespace: system
spec:
selfSigned: {}
---
apiVersion: cert-manager.io/v1alpha2
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
# It should be run by config/default
resources:
- bases/batch.tutorial.kubebuilder.io_cronjobs.yaml
# +kubebuilder:scaffold:crdkustomizeresource
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_cronjobs.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_cronjobs.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@ bases:
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- ../webhook
#- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
- ../certmanager
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus

patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml

# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
#- manager_config_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- manager_webhook_patch.yaml
#- manager_webhook_patch.yaml

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
# 'CERTMANAGER' needs to be enabled to use ca injection
- webhookcainjection_patch.yaml
#- webhookcainjection_patch.yaml

# the following config is for teaching kustomize how to do var substitution
vars:
Expand All @@ -46,15 +50,15 @@ vars:
objref:
kind: Certificate
group: cert-manager.io
version: v1alpha2
version: v1
name: serving-cert # this name should match the one in certificate.yaml
fieldref:
fieldpath: metadata.namespace
- name: CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1alpha2
version: v1
name: serving-cert # this name should match the one in certificate.yaml
- name: SERVICE_NAMESPACE # namespace of the service
objref:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This patch inject a sidecar container which is a HTTP proxy for the
# This patch inject a sidecar container which is a HTTP proxy for the
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
apiVersion: apps/v1
kind: Deployment
Expand All @@ -21,5 +21,6 @@ spec:
name: https
- name: manager
args:
- "--metrics-addr=127.0.0.1:8080"
- "--enable-leader-election"
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
args:
- "--config=controller_manager_config.yaml"
volumeMounts:
- name: manager-config
mountPath: /controller_manager_config.yaml
subPath: controller_manager_config.yaml
volumes:
- name: manager-config
configMap:
name: manager-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
healthProbeBindAddress: :8081
metrics:
bindAddress: 127.0.0.1:8080
webhook:
port: 9443
leaderElection:
leaderElect: true
resourceName: 80807133.tutorial.kubebuilder.io
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
resources:
- manager.yaml

generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- name: manager-config
files:
- controller_manager_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,23 @@ spec:
- command:
- /manager
args:
- --enable-leader-election
- --leader-elect
image: controller:latest
name: manager
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 100m
Expand Down
Loading