Skip to content

Commit 8f04d2d

Browse files
committed
demo-generate addition in makefile
🌱 fix (ci): fix lint issue: shadow: declaration of pluginCfg shadows declaration (#4725) fix (ci): fix lint issue: shadow: declaration of pluginCfg shadows declaration Fix plugin config test by resetting struct to avoid value reuse Avoids test contamination caused by shared PluginConfig variable by explicitly resetting it before decoding in each test case. Also resolves shadowing linter errors reported by golangci-lint. Updated 404 page updated error page updated book.toml Delete docs/book/src/404.md fix: use limited scoped error in generated main.go Updated migration pages and added index for better navigation removed prerequisite and verfication steps changed the header removed toc fix: Use dynamic controller-runtime version in doc generator Replace hardcoded controller-runtime version in hack/docs/internal/cronjob-tutorial/generate_cronjob.go with a reference to the ControllerRuntimeVersion constant from the scaffolding package. This prevents the docs generation from breaking when the controller-runtime version is updated in the scaffolding logic, ensuring that `make generate-docs` remains stable across version bumps. Update hack/docs/internal/cronjob-tutorial/generate_cronjob.go Co-authored-by: Saan <94980910+sbin64@users.noreply.github.com> Update hack/docs/internal/cronjob-tutorial/generate_cronjob.go Co-authored-by: Kersten Burkhardt <kerstenk@gmail.com> 🌱 (chore): enable ginkgolinter forbid-spec-pollution to enforce isolated test specs :seedling: (chore): enable ginkgolinter forbid-focus-container :seedling: enable ginkgolinter forbid-focus-container This PR adds the following configuration to `.golangci.yml`: ```yaml linters-settings: ginkgolinter: forbid-focus-container: true ``` Enabling forbid-focus-container protects the code in the repository against accident commiting of debug code. A contributeor may use ginkgo's focus container (e.g. `FIt`, `FContext` etc. or by adding the `Focus` decorator), in order to locally debug a specific test. Merging a ginkgo's focus container will prevent running of all the other tests in CI. Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com> 📖 Fixed grammatical errors in designs doc (#4716) Fixed grammatical error in designs doc few more typos 🌱 (chore): replace errors.As() with MatchError() in error assertions This update improves Gomega assertions by replacing `errors.As()` with `MatchError()` where the test intends to match specific error types rather than extract them. This change simplifies the assertions and improves readability, aligning with idiomatic Gomega style.
1 parent 23b74ea commit 8f04d2d

File tree

30 files changed

+215
-144
lines changed

30 files changed

+215
-144
lines changed

.golangci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ issues:
1717
- gosec
1818

1919
linters-settings:
20+
ginkgolinter:
21+
forbid-spec-pollution: true
2022
govet:
2123
enable-all: true
2224
disable:
@@ -63,7 +65,8 @@ linters-settings:
6365
- name: bool-literal-in-expr
6466
- name: constant-logical-expr
6567
- name: comment-spacings
66-
68+
ginkgolinter:
69+
forbid-focus-container: true
6770
linters:
6871
disable-all: true
6972
enable:

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/ku
8484
rm -rf testdata/
8585
./test/testdata/generate.sh
8686

87+
.PHONY: demo-generate
88+
demo-generate: ## Generate a new demo recording using Asciinema
89+
@if ! command -v asciinema &> /dev/null; then \
90+
echo "asciinema is not installed. Please install it first:"; \
91+
echo " https://asciinema.org/docs/installation"; \
92+
exit 1; \
93+
fi
94+
@echo "Generating new demo recording..."
95+
@cd scripts/demo && ./run.sh
96+
@echo "Demo recording completed. The cast file is saved in scripts/demo/demo.cast"
97+
@echo "You can now upload it to asciinema.org or embed it in the README"
98+
8799
.PHONY: generate-docs
88100
generate-docs: ## Update/generate the docs
89101
./hack/docs/generate.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Follow the [instructions](https://book.kubebuilder.io/quick-start.html#installat
4747

4848
See the [Getting Started](https://book.kubebuilder.io/quick-start.html) documentation.
4949

50-
![Quick Start](docs/gif/kb-demo.v3.11.1.svg)
50+
<script id="asciicast-id" src="https://asciinema.org/a/id.js" async></script>
5151

5252
Also, ensure that you check out the [Deploy Image](./docs/book/src/plugins/available/deploy-image-plugin-v1-alpha.md)
5353
Plugin. This plugin allows users to scaffold API/Controllers to deploy and manage an

designs/extensible-cli-and-scaffolding-plugins-phase-2.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ Note: If the name is ambiguous, then the qualified name `myexternalplugin.my.dom
103103

104104
### What Plugin system should we use
105105

106-
I propose we use our own plugin system that passes JSON blobs back and forth across `stdin/stdout/stderr` and make this the only option for now as its a language-agnostic medium and it is easy to work with in most languages.
106+
I propose we use our own plugin system that passes JSON blobs back and forth across `stdin/stdout/stderr` and make this the only option for now as it's a language-agnostic medium and it is easy to work with in most languages.
107107

108-
We came to the conclusion that a kubebuilder-specific plugin library should be written after evaluating plugin libraries such as the [built-in go-plugin library](https://golang.org/pkg/plugin/) and [Hashicorps plugin library](https://github.com/hashicorp/go-plugin):
108+
We came to the conclusion that a kubebuilder-specific plugin library should be written after evaluating plugin libraries such as the [built-in go-plugin library](https://golang.org/pkg/plugin/) and [Hashicorp's plugin library](https://github.com/hashicorp/go-plugin):
109109

110-
* The built-in plugin library seems to be more suitable for in-tree plugins rather than out-of-tree plugins and it doesnt offer cross-language support, thereby making it a non-starter.
111-
* Hashicorps go plugin system is more suitable than the built-in go-plugin library as it enables cross language/platform support. However, it is more suited for long running plugins as opposed to short lived plugins and the usage of protobuf could be overkill as we will not be handling 10s of 1000s of deserializations.
110+
* The built-in plugin library seems to be more suitable for in-tree plugins rather than out-of-tree plugins and it doesn't offer cross-language support, thereby making it a non-starter.
111+
* Hashicorp's go plugin system is more suitable than the built-in go-plugin library as it enables cross-language/platform support. However, it is more suited for long-running plugins as opposed to short-lived plugins and the usage of protobuf could be overkill as we will not be handling 10s of 1000s of deserializations.
112112

113-
In the future, if a need arises (for example, users are hitting performance issues), we can then explore the possibility of using the Hashicorps go plugin library. From a design standpoint, to leave it architecturally open, I propose using a `type` field in the PROJECT file to potentially allow other plugin libraries in the future and make this a seperate field in the PROJECT file per plugin; and this field determines how the `universe` will be passed for a given plugin. However, for the sake of simplicity in initial design and not to introduce any breaking changes as Project version 3 would suffice for our needs, this option is out of scope in this proposal.
113+
In the future, if a need arises (for example, users are hitting performance issues), we can then explore the possibility of using the Hashicorp's go plugin library. From a design standpoint, to leave it architecturally open, I propose using a `type` field in the PROJECT file to potentially allow other plugin libraries in the future and make this a separate field in the PROJECT file per plugin; and this field determines how the `universe` will be passed for a given plugin. However, for the sake of simplicity in initial design and not to introduce any breaking changes as Project version 3 would suffice for our needs, this option is out of scope in this proposal.
114114

115115
### Project configuration
116116

@@ -165,14 +165,14 @@ resources:
165165

166166
![Kubebuilder to external plugins sequence diagram](https://github.com/rashmigottipati/POC-Phase2-Plugins/blob/main/docs/externalplugins-sequence-diagram.png)
167167

168-
* What to pass between `kubebuilder` and an external plugin?
168+
* What should be passed between `kubebuilder` and an external plugin?
169169

170170
Message passing between `kubebuilder` and the external plugin will occur through a request / response mechanism. The `PluginRequest` will contain information that `kubebuilder` sends *to* the external plugin. The `PluginResponse` will contain information that `kubebuilder` receives *from* the external plugin.
171171

172-
The following scenarios shows what `kubebuilder` will send/receive to the external plugin:
172+
The following scenarios show what `kubebuilder` will send/receive to the external plugin:
173173

174174
* `kubebuilder` to external plugin:
175-
* `kubebuilder` constructs a `PluginRequest` that contains the `Command` (such as `init`, `create api`, or `create webhook`), `Args` containing all the raw flags from the CLI request and license boilerplate without comment delimiters, and an empty `Universe` that contains the current virtual state of file contents that is not written to the disk yet. `kubebuilder` writes the `PluginRequest` through `stdin`.
175+
* `kubebuilder` constructs a `PluginRequest` that contains the `Command` (such as `init`, `create api`, or `create webhook`), `Args` containing all the raw flags from the CLI request and license boilerplate without comment delimiters, and an empty `Universe` that contains the current virtual state of file contents that are not written to disk yet. `kubebuilder` writes the `PluginRequest` through `stdin`.
176176

177177
* External plugin to `kubebuilder`:
178178
* The plugin reads the `PluginRequest` through its `stdin` and processes the request based on the `Command` that was sent. If the `Command` doesn't match what the plugin supports, it writes back an error immediately without any further processing. If the `Command` matches what the plugin supports, it constructs a `PluginResponse` containing the `Command` that was executed by the plugin, and modified `Universe` based on the new files that were scaffolded by the external plugin, `Error` and `ErrorMsg` that add any error information, and writes the `PluginResponse` back to `kubebuilder` through `stdout`.
@@ -314,7 +314,7 @@ What happens when the above is invoked?
314314

315315
#### User specified file paths
316316

317-
A user will provide a list of file paths for `kubebuilder` to discover the plugins in. We will define a variable `KUBEBUILDER_PLUGINS_DIRS` that will take a list of file paths to search for the plugin name. It will also have a default value to search in, in case no file paths are provided. It will search for the plugin name that was provided to the `--plugins` flag in the CLI. `kubebuilder` will recursively search for all file paths until the plugin name is found and returns the successful match, and if it doesnt exist, it returns an error message that the plugin is not found in the provided file paths. Also use the host system mechanism for PATH separation.
317+
A user will provide a list of file paths for `kubebuilder` to discover the plugins in. We will define a variable `KUBEBUILDER_PLUGINS_DIRS` that will take a list of file paths to search for the plugin name. It will also have a default value to search in, in case no file paths are provided. It will search for the plugin name that was provided to the `--plugins` flag in the CLI. `kubebuilder` will recursively search for all file paths until the plugin name is found and returns the successful match, and if it doesn't exist, it returns an error message that the plugin is not found in the provided file paths. Also use the host system mechanism for PATH separation.
318318

319319
* Alternatively, this could be handled in a way that [helm kustomize plugin](https://helm.sh/docs/topics/advanced/#post-rendering) discovers the plugin based on the non-existence of a separator in the path provided, in which case `kubebuilder` will search in `$PATH`, otherwise resolve any relative paths to a fully qualified path.
320320

@@ -330,9 +330,9 @@ A user will provide a list of file paths for `kubebuilder` to discover the plugi
330330
Another approach is adding plugin executables with a prefix `kubebuilder-` followed by the plugin name to the PATH variable. This will enable `kubebuilder` to traverse through the PATH looking for the plugin executables starting with the prefix `kubebuilder-` and matching by the plugin name that was provided in the CLI. Furthermore, a check should be added to verify that the match is an executable or not and return an error if it's not an executable. This approach provides a lot of flexibility in terms of plugin discovery as all the user needs to do is to add the plugin executable to the PATH and `kubebuilder` will discover it.
331331

332332
* Pros
333-
* `kubectl` and `git` follow the same approach for discovering plugins, so theres prior art.
333+
* `kubectl` and `git` follow the same approach for discovering plugins, so there's prior art.
334334

335-
* Theres a lot of flexibility in just dropping plugin binaries to PATH variable and enabling the discovery without having to enforce any other constraints on the placements of the plugins.
335+
* There's a lot of flexibility in just dropping plugin binaries to PATH variable and enabling the discovery without having to enforce any other constraints on the placements of the plugins.
336336

337337
* Cons
338338
* Enumerating the list of all available plugins might be a bit tough compared to having a single folder with the list of available plugins and having to enumerate those.

designs/helper_to_upgrade_projects_by_rescaffolding.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ the projects might have bug fixes and new incremental features added to the
2929
templates which will result in changes to the files that are generated by
3030
the tool for new projects.
3131

32-
In this case, you used previously the tool to generate the project
32+
In this case, you previously used the tool to generate the project
3333
and now would like to update your project with the latest changes
3434
provided for the same plugin version. Therefore, you will need to:
3535

3636
- Download and install KubeBuilder binary ( latest / upper release )
3737
- You will run the command in the root directory of your project: `kubebuilder alpha generate`
3838
- Then, the command will remove the content of your local directory and re-scaffold the project from the scratch
3939
- It will allow you to compare your local branch with the remote branch of your project to re-add the code on top OR
40-
if you do not use the flag `--no-backup` then you can compare the local directory with the copy of your project
41-
copied to the path `.backup/project-name/` before the re-scaffold be done.
40+
if you do not use the flag `--no-backup`, then you can compare the local directory with the copy of your project
41+
copied to the path `.backup/project-name/` before the re-scaffold is done.
4242
- Therefore, you can run make all and test the final result. You will have after all your project updated.
4343

4444
**To update the project with major changes provided**
@@ -66,16 +66,16 @@ A common scenario is to upgrade the project based on the newer Kubebuilder. The
6666
The proposed command will automate the process at maximum, therefore helping operator authors with minimizing the manual effort.
6767

6868
The main motivation of this proposal is to provide a helper for upgrades and
69-
make less painful this process. Examples:
69+
make this process less painful. Examples:
7070

7171
- See the discussion [How to regenerate scaffolding?](https://github.com/kubernetes-sigs/kubebuilder/discussions/2864)
7272
- From [slack channel By Paul Laffitte](https://kubernetes.slack.com/archives/CAR30FCJZ/p1675166014762669)
7373

7474
### Goals
7575

7676
- Help users upgrade their project with the latest changes
77-
- Help users to re-scaffold projects from scratch based on what was done previously with the tool
78-
- Make less painful the process to upgrade
77+
- Help users re-scaffold projects from scratch based on what was done previously with the tool
78+
- Make the upgrade process less painful
7979

8080
### Non-Goals
8181

@@ -106,7 +106,7 @@ kubebuilder alpha generate \
106106
- no-backup: [Optional] If not informed then, the current directory should be copied to the path `.backup/project-name`
107107
- backup: [Optional] If not informed then, the backup will be copied to the path `.backup/project-name`
108108
- plugins: [Optional] If not informed then, it is the same plugin chain available in the layout field
109-
- binary: [Optional] If not informed then, the command will use KubeBuilder binary installed globaly.
109+
- binary: [Optional] If not informed then, the command will use KubeBuilder binary installed globally.
110110

111111
> Note that the backup created in the current directory must be prefixed with `.`. Otherwise the tool
112112
will not able to perform the scaffold to create a new project from the scratch.
@@ -116,12 +116,12 @@ This command would mainly perform the following operations:
116116
- 1. Check the flags
117117
- 2. If the backup flag be used, then check if is a valid path and make a backup of the current project
118118
- 3. Copy the whole current directory to `.backup/project-name`
119-
- 4. Ensure that the output path is clean. By default it is the current directory project where the project was scaffolded previously and it should be cleaned up before to do the re-scaffold.
119+
- 4. Ensure that the output path is clean. By default it is the current directory project where the project was scaffolded previously and it should be cleaned up before doing the re-scaffold.
120120
Only the content under `.backup/project-name` should be kept.
121-
- 4. Read the [PROJECT config][project-config]
122-
- 5. Re-run all commands using the KubeBuilder binary to recreate the project in the output directory
121+
- 5. Read the [PROJECT config][project-config]
122+
- 6. Re-run all commands using the KubeBuilder binary to recreate the project in the output directory
123123

124-
The command should also provide a comprensive help with examples of the proposed workflows. So that, users
124+
The command should also provide comprehensive help with examples of the proposed workflows. So that, users
125125
are able to understand how to use it when run `--help`.
126126

127127
### User Stories

designs/integrating-kubebuilder-and-osdk.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
|---------------|---------------|-------------|-------|
33
| @joelanford | Sep 6, 2019 | implemented | - |
44

5-
Integrating Kubebuilder and Operator SDK
6-
========================================
5+
# Integrating Kubebuilder and Operator SDK
76

87
## Goal
98

10-
To unite Kubebuilder and Operator SDK around Kubebuilders project scaffolding, to move Operator SDKs Go operator features upstream, where appropriate, and to join forces on maintaining Kubebuilder so that both Kubebuilder and Operator SDK support the same project structure and command line interface for Go-based operators.
9+
To unite Kubebuilder and Operator SDK around Kubebuilder's project scaffolding, to move Operator SDK's Go operator features upstream, where appropriate, and to join forces on maintaining Kubebuilder so that both Kubebuilder and Operator SDK support the same project structure and command line interface for Go-based operators.
1110

1211
## Background
1312

@@ -26,17 +25,17 @@ The Kubebuilder and Operator SDK contributors created a [GitHub project][kb-osdk
2625
### Upstream code from Operator SDK
2726

2827
The Operator SDK project contains various features that can be used by Go operator developers regardless of whether the project is based on Kubebuilder or Operator SDK. These features will be upstreamed into `kubebuilder`, `controller-runtime`, and `controller-tools`, where appropriate. These include:
29-
* a `DynamicRESTMapper` that enables an operator to dynamically and automatically discover new CRDs added to the cluster after the operator has started
30-
* a `GenerationChangedPredicate` that can trigger reconciliation events when a resource's `metadata.generation` field has changed.
31-
* flags and helpers that can be used to provide more fine-grained configuration when constructing the default `zap`-based logger.
28+
* A `DynamicRESTMapper` that enables an operator to dynamically and automatically discover new CRDs added to the cluster after the operator has started
29+
* A `GenerationChangedPredicate` that can trigger reconciliation events when a resource's `metadata.generation` field has changed
30+
* Flags and helpers that can be used to provide more fine-grained configuration when constructing the default `zap`-based logger
3231

3332
The Operator SDK contributors plan to begin conducting all development of Go operator related code in upstream Kubebuilder (and related projects) and to spend more time helping the Kubebuilder contributors maintain these projects.
3433

3534
### Prototypes
3635

3736
To make Kubebuilder more extensible, the community has been discussing a proposal to add extension points to Kubebuilder to support different operator patterns. One example of an operator pattern is the [addon pattern][addon-pattern-pr] that uses an existing library to instantiate an opinionated API and controller.
3837

39-
More broadly, the idea is to add support for executable plugin-based extensions that can modify Kubebuilders base scaffolding before files are written to disk so that the project (e.g. Go code, kustomize templates, the project Makefile and Dockerfile) can have customized content provided by an extension.
38+
More broadly, the idea is to add support for executable plugin-based extensions that can modify Kubebuilder's base scaffolding before files are written to disk so that the project (e.g. Go code, kustomize templates, the project Makefile and Dockerfile) can have customized content provided by an extension.
4039

4140
### Documentation
4241

designs/simplified-scaffolding.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ they think it is, we're probably better served coming up with a standard
137137
"can I create this example YAML file".
138138

139139
Furthermore, since the structure is quite convoluted, it makes it more
140-
difficult to write examples, since the actual code we care about ends up
141-
scattered deep in a folder structure.
140+
difficult to write examples, as the actual code we care about ends up
141+
scattered deep in the folder structure.
142142

143143
### Lack of Builder
144144

designs/template.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
|---------------|---------------|-------------|---|
33
| @name | date | Implementable | - |
44

5-
Title of the Design/Proposal
6-
===================
5+
# Title of the Design/Proposal
76

87
<!-- Describe your change here. This is purposefully freeform: we want
98
enough information to evaluate the design, but not so much that you're

docs/book/book.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ src = "src"
55
title = "The Kubebuilder Book"
66

77
[output.html]
8-
curly-quotes = true
8+
smart-punctuation = true
99
additional-css = ["theme/css/markers.css", "theme/css/custom.css", "theme/css/version-dropdown.css"]
1010
git-repository-url = "https://github.com/kubernetes-sigs/kubebuilder"
1111
edit-url-template = "https://github.com/kubernetes-sigs/kubebuilder/edit/master/docs/book/{path}"

docs/book/src/404.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)