Comments (10)
thanks for the detailed explanation @camilamacedo86 !
from kubebuilder.
Hi @ardikabs,
Thank you for bringing up this issue. I agree that the ability to customize all paths, not just specific ones, would be a valuable addition to Kubebuilder. A config file allowing users to define paths for controllers, hack, etc., would indeed enhance the tool's flexibility.
However, introducing such customization for only one aspect without addressing the others would lead to inconsistency in behavior. We aim for a uniform and predictable user experience. Therefore, implementing this feature across the board is crucial, albeit it introduces significant complexities.
IHMO: Given these considerations, the best approach would be to develop a detailed proposal. This document would outline the implementation strategy, consider potential problems, and propose solutions. You can find a template for proposals here: https://github.com/kubernetes-sigs/kubebuilder/blob/master/designs/template.md, and some examples at: https://github.com/kubernetes-sigs/kubebuilder/blob/master/designs.
As a temporary measure for the current issue, one possibility could be to issue a warning instead of an error when the boilerplate is not found, though this might be perceived as a bug by some users. However, it might be an acceptable interim solution.
We're definitely open to contributions that would help us move in this direction.
Would you be interested in working on this feature?
from kubebuilder.
Hi mateusoliveira43,
is there any motivation to separate go files in 3 folders (api, internal and cmd).
Yes, the default layout in Kubebuilder adheres to the standards and best practices established by Golang and Kubernetes communities. Here's a brief explanation of the directory structure:
api
: This directory contains the Go files for APIs. It's where the API types and associated CRD definitions are located.internal
: This directory is intended for code that shouldn't be imported by other applications. In your case, it would typically include the controllers.cmd
: This is where the command-line interfaces are defined. For instance, initialization and manager code are placed here.hack
: The reason why the license file is located in thehack
directory is because it follows a Kubernetes convention. Thehack
directory typically contains scripts that are useful for development, such as those for building, testing, and debugging the project.
For more information, you can refer to these resources:
- Golang Project Layout: golang-standards/project-layout
- Information about the
hack
directory: k8s.io/kubernetes/hack - Recent discussions on Kubebuilder's layout: kubernetes-sigs/kubebuilder/pull/2985
Please note that any changes in the project layout and the scaffolding process are extensively discussed within the community and are not made lightly.
Furthermore: https://book.kubebuilder.io/migration/legacy/v2vsv3#project-customizations
from kubebuilder.
I see, in other words, we need to introduce a new field in the PROJECT file, yes?
And, it seems to me that this would also make sense if we add a possibility to change the boilerplate path under the edit
command, what do you think? @camilamacedo86
from kubebuilder.
Hi @camilamacedo86 , seems I missed the notification, sorry for the late response.
It seems there is no error returned when hack/boilerplate.go.txt
file is missing because it will be overridden with an empty value, the only error that occurs is when hack/boilerplate.go.txt
isn't a valid file like permission denied on read, etc.
Nevertheless, I am willing to address this concern by modifying kubebuilder
to issue a warning rather than an error when an issue arises while reading the file.
Regarding the design proposal, I am interested in contributing to it. However, I'm unsure if focusing solely on hack/boilerplate.go.txt
is acceptable as a design proposal, as it appears to be a relatively minor feature request.
from kubebuilder.
Hi @ardikabs,
Regarding the design proposal, I am interested in contributing to it. However, I'm unsure if focusing solely on hack/boilerplate.go.txt is acceptable as a design proposal, as it appears to be a relatively minor feature request.
That is great, and you are right. The proposal should be a solution that provides a design that allows users to customise the path for controllers and APIs as well. We cannot allow it partially. Otherwise, the UX will be hard. However, I am proposing a third option that might be acceptable.
Nevertheless, I am willing to address this concern by modifying kubebuilder to issue a warning rather than an error when an issue arises while reading the file.
I was thinking better about this one.
If we add a warning, what value does that bring?
Users still need to be able to have the header scaffolded.
So I think we can:
a) Improve the error message, say that the file was not found, and outline the Options. use None if you do not want any scaffold
b) An alternative option might be:
Add a new flag to the kubebuilder edit --bolerplatPath
Then, add a new spec to the PROJECT file to store the bollerplatPath
Change the tool to use the path in the Project File instead
would you like to work on this one?
from kubebuilder.
About current structure (using go/v4
and kubebuilder 3), is there any motivation to separate go files in 3 folders (api, internal and cmd). Adding them under a single folder could be a good approach? Example
├── pkg (or internal)
│ └── cmd
│ └── main.go (or without a sub folder, directly in pkg level)
│ └── controller
│ └── api
from kubebuilder.
Hi @camilamacedo86 , i have submitted a PR for this request, but instead of storing to the PROJECT
file, it seems to me that would be better to loosen that constraint and allow adjustment through flags on every attempt when invoking the command (e.g., init
, create api
, and create webhook
)
from kubebuilder.
Hi @ardikabs
Hi @camilamacedo86, i have submitted a #3716 for this request, but instead of storing to the PROJECT file, it seems to me that it would be better to loosen that constraint and allow adjustment through flags on every attempt when invoking the command (e.g., init, create API, and create webhook)
What you want to change here is related to the base of the Project
That means the only way to do that would be in the init command
Then, could you track it out in the ProjectConfig as described in the PR?
Change it is outside of the domain of responsibility of create API, and create webhook commands
from kubebuilder.
Hi @ardikabs
Yes. We need to:
- a) add the new spec to the ProjectConfig, i.e.
header-file-path
orboilerplate-path
. It is important not to break existing projects if the value is not found in the Config; we set the default path. (see the pkg/config:kubebuilder/pkg/config/v3/config.go
Lines 55 to 74 in 66c3572
- b) allow passing the flag in the init|edit commands
- c) ensure that the hack/boilerplate.go.txt will be generated in this path
- e) that in this case, hack/boilerplate.go will not exist/delete (if has only this file in the hack, delete the dir; otherwise, the file)
- f) also, the makefile target will be scaffolded or updated accordingly ( see an example of how we do those replaces in :
kubebuilder/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go
Lines 208 to 213 in 66c3572
Lastly, we need an e2e test to ensure the functionality.
Ideally, we would need to ensure the init/edit command, like described in: #3716 (comment)
I hope that helps clear things up. Thank you a lot for looking on that.
from kubebuilder.
Related Issues (20)
- versionPattern should be more flexible to allow internal versions HOT 3
- Support for IBM Z (s390x architecture) HOT 1
- `exampleFile.txt` get expanded for every unit-test HOT 1
- Ensure that the projects with webhooks can work well with the latest version of cert-manager
- webhook patches has not been generated properly for projects with multi-group layout
- duplicited CRD in dist/install.yaml HOT 14
- Incorrect case for function doc in "Implementing a ConJob" tutorial HOT 1
- RBAC for `get` on status subresource is unnecessary HOT 11
- Include CRD viewer and editor roles in kustomization file? HOT 6
- Labels added to generated YAML seem a bit aggressive HOT 4
- Can't create an API of Kind with name DNS but creating an API of Kind with name ENS works fine HOT 4
- TestTemplate missing error check
- Invalid leader election ID is generated HOT 9
- Add support for go 1.22 HOT 11
- Kubebuilder docs should more clearly state the interaction between `kubebuilder:validation:Required` and `omitempty` HOT 6
- Making client-gen work with layout V4 HOT 8
- Bump controller-runtime v0.17.2
- Access resource of another CRD HOT 2
- Remove path webhook marker HOT 4
- Trailing spaces in generated README.md HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kubebuilder.