-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Align Helm/Ansible plugins using common/v3 base #4701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Align Helm/Ansible plugins using common/v3 base #4701
Conversation
internal/cmd/operator-sdk/cli/cli.go
Outdated
| gov2Bundle, | ||
| gov3Bundle, | ||
| helmBundle, | ||
| commonv3.Plugin{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not include this for now as it is not used for anything and it will imply backwards compatibility issues if removed later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fine. It is only to show @jmrodri the possibility of something that we spoke about. That would be in its own pr with my wish/idea of adding a Plugin Contribution doc with the vision of plugins. Also, we need/can add the custom plugin provide by kB ( the declarative.go.kubebuilder.io/v1: pattern too to allow people to get the advantage of this one and custom their implementation )
It allows people such as Java developers who want to create their own plugin to follow up the same base structure and then scaffold the rest with their language of preference instead of using Golang.
| "strings" | ||
| ) | ||
|
|
||
| func ReplaceInFile(path, old, new string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are going to use this functions to scaffold, they should receive a filesystem.Filesystem and use afero internally instead of ioutil or os. If we use these others directly, once we implement improvements in the filesystem abstraction (for example the scaffold atomicity we talked about) these methods will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that in a follow-up. These funcs exist in KB https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/e2e/utils/util.go#L63 but are not returning the errors. (needs improvements see my todo in this file)
Note that there or here we need to Insert/Replace data in the files to customize the plugins. So, IMO it can be promoted as utils from KB. Then, we can check the possibility to change that to use afero.
Also, see my comment in : #4701 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also see that we have a very complex code in the manifests plugin that could be simplified with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But before this PR, and in the KB package you mentioned, they are used during tests after running the correspondig command call, which means that the file exists in disk.
However, here you are using these functions during scaffolding, and all scaffolding should be done through the filesystem abstraction, not directly with os and ioutil packages. Thats the point I wanted to make. I know the current machinery only allows to create files from templates, or insert code-fragments before special markers. Do we need to improve the machinery for generalized insertion and replacement? Yes. But until that is done, SDK will have to rely on these functions, and scaffolding directly to the filesystem without using the abstraction provided should not be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not about the file. It is about the content not be found. The same issue can happen there indeed in the tests. So, for example, the test will pass because the required change has not been performed.
However, I am totally fine with the improvements sugggested getting done in follow ups. the intention here was just to share the scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not talking about the logic if the content is not found Camila, I'm talking about the filesystenm abstraction. We are providing one common filesystem abstraction that all Scaffold() must use. This allows us to, for example, test by saying that the underlying filesystem is an afero.MemMapFs. If we do this, when it gets to this scaffold, the part that uses the system abstraction will work, but the direct calls to os and ioutil will break. The files that you are trying to insert into will only be created in memory while os and ioutil calls will expect it to be in disk.
If you want to use these functions inside Scaffold and PreScaffold methods, you must turn those calls to os and ioutil functions to the equivalents of afero and pass the filesystem abstraction. If you only want to use them for tests (like until now) you don't have this problem. After moving everything to afero, when you call this function from tests that don't have a filesystem you just create one like so: filesystem.Filesystem{FS: afero.NewOsFs()}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could not it be done in a follow-up? Could not do this after we improve these implementations in upstream/kb and provide them from there? Is that a blocker for us to move forward here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear it should block, but should be pretty easy:
- Add
fs filesystem.Filesystemas an argument. - When calling this function from inside
Scaffoldpass thefsthat you have there. - When calling this function from any other place (tests) pass it a
filesystem.Filesystem(FS: afero.NewOsFs()). - When using
ioutil.Xxxxxx(...)change it toafero.Xxxxxx(fs.FS, ...). - When using
os.Xxxxxx(....)change it tofs.FS.Xxxxxx(...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What bug/issue we will face that justify we block this PR instead of address that in follow up when your pr kubernetes-sigs/kubebuilder#2119 get merged? I do not think so. So, we can do that as follow up. I will add the todo comments.
| makefileBytes = []byte(strings.Replace(string(makefileBytes), oldMakefileTestTarget, fmt.Sprintf(makefileTestTarget, controllerRuntimeVersion), 1)) | ||
|
|
||
| var mode os.FileMode = 0644 | ||
| if info, err := fs.FS.Stat(filePath); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Adirio , regarding the code implementation, suggested which I am ok within a follow-up. See that it was NOT raising the issue when the target is not found as it is in the Insert/replace functions that we used. Just to let, you know.
internal/cmd/operator-sdk/cli/cli.go
Outdated
| ) | ||
| gov3Bundle, _ := plugin.NewBundle(golangv3.Plugin{}.Name(), golangv3.Plugin{}.Version(), | ||
| gov3Bundle, _ := plugin.NewBundle(golang.DefaultGoNameQualifier, golangv3.Plugin{}.Version(), | ||
| commonv3.Plugin{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might not need to use the common here. see: kubernetes-sigs/kubebuilder#2112
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to do this, we need to export the bundle, which I have planned to do once kubernetes-sigs/kubebuilder#2106 is merged. (I'm not doing it right now to prevent rebases)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do that in a follow-up. I will add a comment
jmrodri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
|
/lgtm |
Signed-off-by: Camila Macedo <[email protected]>
| f.TemplateBody = kustomizeTemplate | ||
|
|
||
| f.IfExistsAction = machinery.Error | ||
| // For Anible/Helm is no supported webhooks then, we customize |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
| f.TemplateBody = kustomizeTemplate | ||
|
|
||
| f.IfExistsAction = machinery.Error | ||
| // For Anible/Helm is no supported webhooks then, we customize |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
internal/plugins/ansible/v1/init.go
Outdated
| env: | ||
| - name: ANSIBLE_GATHERING | ||
| value: explicit` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit to align YAML formatting
| env: | |
| - name: ANSIBLE_GATHERING | |
| value: explicit` | |
| env: | |
| - name: ANSIBLE_GATHERING | |
| value: explicit` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
estroz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the formatting nit
/lgtm
|
New changes are detected. LGTM label has been removed. |
Signed-off-by: Camila Macedo <[email protected]>
Update related to v1.6.1 https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.6.1/ operator-framework/operator-sdk#4701 Signed-off-by: Wayne Sun <[email protected]>
Description
Motvation
Closes: #4542
Closes: #4643
Blocked by
kubernetes-sigs/kubebuilder#2106