docs/book/src/reference/license-header.md
Kubebuilder creates a file at hack/boilerplate.go.txt that contains your license header. This header is automatically added to all generated Go files.
The boilerplate file is used by:
create api, create webhook, etc.)controller-gen when generating code (DeepCopy methods, etc.)make generate and make manifests commandsBy default, Kubebuilder uses the Apache 2.0 license.
<aside class="warning" role="note"> <p class="note-title">Boilerplate is a Template</p>hack/boilerplate.go.txt is a template used when generating or regenerating files. Changing this file does not automatically update existing files.
To apply changes to existing files:
make generate && make manifests to update generated codekubebuilder alpha generate to regenerate the entire projectUse the --license flag during initialization or to update an existing project:
# During initialization
kubebuilder init --domain example.com --license apache2 --owner "Your Name"
# After initialization (update existing project)
kubebuilder edit --license apache2 --owner "Your Company"
Available license values:
apache2 - Apache 2.0 License (default)copyright - Copyright notice only (no license text)none - No license headerProvide your own license header from a file. Kubebuilder reads the content from your file and copies it to hack/boilerplate.go.txt:
# During initialization
kubebuilder init --domain example.com --license-file ./my-header.txt
# After initialization
kubebuilder edit --license-file ./my-header.txt
How it works:
hack/boilerplate.go.txtThe --license-file flag overrides the --license flag. If you provide --license-file, a boilerplate will always be created, even if you also specify --license none.
Use this when you need:
After initialization, you can edit hack/boilerplate.go.txt directly:
vim hack/boilerplate.go.txt
Your custom license file must include Go comment delimiters (/* and */).
Example (my-license-header.txt):
/*
Copyright YEAR Your Company Name.
Licensed under the MIT License.
See LICENSE file in the project root for full license text.
*/
Use YEAR in your boilerplate and it is automatically replaced with the current year:
/*
Copyright YEAR Your Company.
*/
How it works:
YEAR when creating files (create api, create webhook, etc.)YEAR when generating code (make generate)The Makefile passes the year to controller-gen:
YEAR ?= $(shell date +%Y)
.PHONY: generate
generate:
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt",year=$(YEAR) paths="./..."
Both automatically use the current year, so your boilerplate stays up-to-date.
</aside>After updating hack/boilerplate.go.txt, choose how to apply the changes:
Regenerate Generated Code (Recommended):
make generate # Update DeepCopy methods
make manifests # Update CRDs, RBAC, webhooks
This updates generated code but keeps your hand-written files unchanged.
Regenerate Entire Project:
kubebuilder alpha generate
This overwrites all scaffolded files. Commit your changes before running.
</aside>New Files Only: New files will automatically use the updated template:
kubebuilder create api --group myapp --version v1 --kind MyNewKind
Manual Updates:
For hand-written files, manually update headers using hack/boilerplate.go.txt as a reference.
hack/boilerplate.go.txt is used when generating or regenerating files:
kubebuilder create api and create webhook - new filesmake generate - DeepCopy methods, etc.make manifests - CRDs, RBAC, webhookskubebuilder alpha generate - entire projectAll tools automatically reference hack/boilerplate.go.txt. The Makefile is already configured - no changes needed.
Use the built-in Apache 2.0 license:
kubebuilder init --domain example.com --license apache2 --owner "Your Company"
This generates:
/*
Copyright YEAR Your Company.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
*/
Use the built-in copyright license for just a copyright notice:
kubebuilder init --domain example.com --license copyright --owner "Your Company"
This generates:
/*
Copyright YEAR Your Company.
*/
For licenses not built-in, create a custom file mit-header.txt:
/*
Copyright YEAR Your Name.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
Then initialize your project:
kubebuilder init --domain example.com --license-file ./mit-header.txt
What happens:
./mit-header.txthack/boilerplate.go.txt with that contenthack/boilerplate.go.txt becomes the source of truth for all generated files