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
Generate clientset for vm crds #481
Comments
Hello, you can use kubernetes controller runtime client Example in pseudo-code, it may throw errors, it didn't test it. But it shows main concept. go.mod
usage package main
import (
"sigs.k8s.io/controller-runtime/pkg/client"
operator "github.com/VictoriaMetrics/operator/api/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
)
func setupRuntime() *runtime.Scheme {
s := scheme.Scheme
s.AddKnownTypes(operator.GroupVersion,
&operator.VMRule{},
&operator.VMRuleList{},
)
if err := operator.AddToScheme(s); err != nil {
logger.Fatalf("BUG, cannot add scheme to client")
}
return s
}
func main(){
lr := clientcmd.NewDefaultClientConfigLoadingRules()
cfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(lr, &clientcmd.ConfigOverrides{})
restCfg, err := cfg.ClientConfig()
if err != nil {
return nil, fmt.Errorf("cannot read client cfg from kubeconfig: %w", err)
}
c, err := client.NewWithWatch(restCfg, client.Options{Scheme: setupRuntime()})
if err != nil {
return nil, fmt.Errorf("cannot build client: %w", err)
}
var rules operator.VMRuleList
if err := c.List(context.Background(), &rules); err != nil {
logger.Fatalf("cannot list rules: %s",err)
}
for _, rule := range rules.Items{}
} |
Thank you for the example :) |
It shouldn't be hard to implement it with https://github.com/kubernetes/code-generator Will add it to backlog. |
It should simplify API usage for typed clients #481
@f41gh7 Thanks for adding it. |
Thanks! Will fix it soon. I've just added generation and didn't test it yet. |
v0.26.0 release contains versioned client. It's moved into separate go module, which should reduce dependency blob. Feel free to re-open, if it's not working. |
Hi Team,
I'm trying to operate some crud in vm crd like vmrules, but can't find any client available now in project.
So I'm wondering why you guys not use tool like code-generator to generate clientset for them.
Thanks.
The text was updated successfully, but these errors were encountered: