-
Notifications
You must be signed in to change notification settings - Fork 184
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
Failed to list v1alpha1.VulnerabilityReport #1134
Comments
@david-freistrom if you run the following command, you get results : kubectl get vulnerabilityreports -n <namespace> -o yaml Note reports are stored in etcd as single (VulnerabilityReport) no plural , so if you are watching for plural (VulnerabilityReportList) it will not work |
@chen-keinan Yes i will get it when I run kubectl. but here I use goclient. The plural form of the name is defined inside the CRD. this works: func GetVulnerabilityReports(client *rest.RESTClient) (interface{}, error) {
reports := v1alpha1.VulnerabilityReportList{}
err := client.
Get().
Resource("vulnerabilityreports").
Do(context.Background()).
Into(&reports)
if err != nil {
fmt.Printf("Error: %v\n", err)
}
return reports, err
} By the way: The known types are already added to the scheme via v1alpha1.AddToScheme(scheme.Scheme): |
This issue is stale because it has been labeled with inactivity. |
Hi @david-freistrom I am facing the same issue currently. There are no updates on the issue, did you manage to fix it? |
@david-freistrom @cpotter302 in the code it registered, let me know if you have any recommendations |
Thanks for the quick response, could you clarify that a bit? I can see that the types get registered to the scheme, however it's still not working for me. That is the implementation of @david-freistrom from his GitLab repository: https://gitlab.com/freistrom/trivy-exporter. For now i could not verify that this is working either. |
I manage to make it work by using the dynamic client package: Initiliaze the client with the rest config (stays the same) // rest config
cfg.ContentConfig.GroupVersion = &trivytypes.SchemeGroupVersion
cfg.UserAgent = rest.DefaultKubernetesUserAgent()
cfg.NegotiatedSerializer = serializer.NewCodecFactory(scheme.Scheme)
cfg.APIPath = "/apis"
dynClient, err = dynamic.NewForConfig(cfg) func main() {
fac := dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynClient, 0, v1.NamespaceAll, nil)
informer := fac.ForResource(schema.GroupVersionResource{
Group: trivytypes.SchemeGroupVersion.Group,
Version: trivytypes.SchemeGroupVersion.Version,
Resource: "vulnerabilityreports",
}).Informer()
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
//logic here
},
UpdateFunc: func(oldObj, newObj interface{}) {
//logic here
},
})
informer.Run(wait.NeverStop)
} |
This issue is stale because it has been labeled with inactivity. |
I got this working for one of my projects earlier, which you might be able to use as an example: https://github.com/Starttoaster/trivy-operator-explorer/blob/main/internal/kube/client.go Most importantly, to make a client: import (
"fmt"
"github.com/aquasecurity/trivy-operator/pkg/apis/aquasecurity/v1alpha1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// InitClient initializes the Kubernetes client based on the provided configuration.
// If inCluster is true, it uses in-cluster configuration; otherwise, it uses the kubeconfig file.
// Either you need inCluster=true (in which the program is running in a Pod in the cluster), or you need to specify a kube config path
func InitClient(inCluster bool, kubeconfigPath string) (*rest.RESTClient, error) {
var config *rest.Config
var err error
if inCluster {
config, err = rest.InClusterConfig()
if err != nil {
return nil, fmt.Errorf("error getting in-cluster config: %w", err)
}
} else {
config, err = clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
return nil, fmt.Errorf("error getting out-of-cluster config: %w", err)
}
}
err = v1alpha1.AddToScheme(scheme.Scheme)
if err != nil {
return nil, fmt.Errorf("error adding to scheme: %w", err)
}
crdConfig := *config
crdConfig.ContentConfig.GroupVersion = &v1alpha1.SchemeGroupVersion
crdConfig.APIPath = "/apis"
crdConfig.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
crdConfig.UserAgent = rest.DefaultKubernetesUserAgent()
clientset, err := rest.UnversionedRESTClientFor(&crdConfig)
if err != nil {
return nil, fmt.Errorf("error creating clientset from config: %w", err)
}
return clientset, nil
} and then you can list VulnerabilityReports with the following function:
|
This issue is stale because it has been labeled with inactivity. |
What steps did you take and what happened:
I utilized the report structs and functions of v1alpha1 API for my go-client
I installed trivy-operator via helm
I run my go app
What did you expect to happen:
Watch/List Report Objects in my Go app
Anything else you would like to add:
Environment:
Trivy-Operator version (use
trivy-operator version
): ghcr.io/aquasecurity/trivy-operator:0.12.1Kubernetes version (use
kubectl version
): Server Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", GitCommit:"434bfd82814af038ad94d62ebe59b133fcb50506", GitTreeState:"clean", BuildDate:"2022-10-25T19:35:11Z", GoVersion:"go1.19.2", Compiler:"gc", Platform:"linux/amd64"}OS (macOS 10.15, Windows 10, Ubuntu 19.10 etc): Fedora 36 x86_64
The text was updated successfully, but these errors were encountered: