Skip to content
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

Golang Plugins for kube-linter #642

Open
Voldemat opened this issue Oct 18, 2023 · 5 comments
Open

Golang Plugins for kube-linter #642

Voldemat opened this issue Oct 18, 2023 · 5 comments
Labels
decision pending Still deciding whether this is something we should do enhancement New feature or request

Comments

@Voldemat
Copy link

Description of the problem/feature request
Ability to write your own custom plugins for linter, using golang. Looks like golang supports plugin loading through https://pkg.go.dev/plugin.

Description of the existing behavior vs. expected behavior
Doesn`t exist yet.

Additional context
Example of such plugin would be knative, as it has its own set of abstractions that you work with and I for example would like to check that my ingress controllers uses real knative services and applies required annotations for dns resolution. I would like to work on PR if you will be interested.

@janisz janisz added enhancement New feature or request decision pending Still deciding whether this is something we should do labels Oct 18, 2023
@janisz
Copy link
Collaborator

janisz commented Oct 18, 2023

Looks like golang supports plugin loading through https://pkg.go.dev/plugin.

I think this is halfly baked feature :(
We are thinking about having a way to declare CRDs maybe this could be done in some kind of scripting language #24

@Voldemat
Copy link
Author

Voldemat commented Oct 18, 2023

Why do you think so? I`m just curious, as don`t program in Go a lot, mostly Python and Typescript. On first glance sounds like a cool feature. For example we can define each custom linting rule as separate file, then compile it in docker build and load it in runtime when we call kube-linter.

@janisz
Copy link
Collaborator

janisz commented Oct 25, 2023

Why do you think so?

Good question so I've asked chat gpt about it 😄

  • Limited platform support: Go plugins were primarily designed for Unix-like operating systems. They were not well-supported on all platforms, which limited their portability.
  • Limited dynamic loading: Go plugins were capable of dynamic loading and unloading, but the implementation was not as flexible as some other languages. Loading and unloading plugins could be tricky and had some restrictions.
  • Limited access to symbols: Plugins in Go had limitations in terms of accessing symbols (functions and variables) defined in the host program. This was due to concerns about maintaining type safety and avoiding symbol conflicts.
  • Compatibility issues: Plugins were sensitive to changes in the host program's code. If the host program was updated or recompiled, it could lead to incompatibility issues with existing plugins.
  • Lack of official support: While Go plugins existed, they were not part of the official Go standard library, indicating that they were not fully matured or recommended for production use.

In my experience although they look like java jars or dynamic libs they are not close to this. Another thing is popularity, I've not seen many projects using it (although there are some. Even golangci/golangci-lint which could be perfect case for a plugin system is based on including a linters and compile them all into a single binary and other projects prefer subprocesses or some other solutions like traefik/yaegi or hashicorp/go-plugin

Other sources:

@mvdan: Because I think the Plugin package is a very good idea, but it's sort of half-baked. It has no Windows support, it's very easy to misuse... If somebody else builds a plugin and tries to run it with your binary, it's almost certainly not gonna work. So I think it's a great idea, but it should never have hit the standard library until it was finished.

Don’t use Go’s plug-in system, it’s essentially a hacked together mess that really should be deprecated.

@Voldemat
Copy link
Author

ChatGPT saver of all) Yeah it makes sense, subprocess approach would be much better, only thing that can go wrong is performance.

@AlanMasciangelo
Copy link

I'm also looking to extend with fully custom checks but based on the examples it looks like only way is to fork and rebuild, is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision pending Still deciding whether this is something we should do enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants