diff --git a/api/storage/v1alpha1/register.go b/api/storage/v1alpha1/register.go index b0201c8..d35338c 100644 --- a/api/storage/v1alpha1/register.go +++ b/api/storage/v1alpha1/register.go @@ -73,6 +73,11 @@ func AddKnownTypes(scheme *runtime.Scheme) error { if err != nil { return fmt.Errorf("unable to add field selector conversion function to SBOM: %w", err) } + + err = scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("VulnerabilityReport"), imageMetadataFieldSelectorConversion) + if err != nil { + return fmt.Errorf("unable to add field selector conversion function to VulnerabilityReport: %w", err) + } return nil } diff --git a/api/storage/v1alpha1/vulnerabilityreport_types.go.go b/api/storage/v1alpha1/vulnerabilityreport_types.go similarity index 82% rename from api/storage/v1alpha1/vulnerabilityreport_types.go.go rename to api/storage/v1alpha1/vulnerabilityreport_types.go index 8d4a1a6..e104575 100644 --- a/api/storage/v1alpha1/vulnerabilityreport_types.go.go +++ b/api/storage/v1alpha1/vulnerabilityreport_types.go @@ -32,6 +32,12 @@ type VulnerabilityReportList struct { // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:selectablefield:JSONPath=`.spec.imageMetadata.registry` +// +kubebuilder:selectablefield:JSONPath=`.spec.imageMetadata.registryURI` +// +kubebuilder:selectablefield:JSONPath=`.spec.imageMetadata.repository` +// +kubebuilder:selectablefield:JSONPath=`.spec.imageMetadata.tag` +// +kubebuilder:selectablefield:JSONPath=`.spec.imageMetadata.platform` +// +kubebuilder:selectablefield:JSONPath=`.spec.imageMetadata.digest` // VulnerabilityReport is the Schema for the scanresults API type VulnerabilityReport struct { diff --git a/internal/storage/matcher.go b/internal/storage/matcher.go index 73cba39..3128c60 100644 --- a/internal/storage/matcher.go +++ b/internal/storage/matcher.go @@ -40,12 +40,12 @@ func getAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { } selectableFields := fields.Set{ - "spec.imageMetadata.Registry": imageMetadataAccessor.GetImageMetadata().Registry, - "spec.imageMetadata.RegistryURI": imageMetadataAccessor.GetImageMetadata().RegistryURI, - "spec.imageMetadata.Repository": imageMetadataAccessor.GetImageMetadata().Repository, - "spec.imageMetadata.Tag": imageMetadataAccessor.GetImageMetadata().Tag, - "spec.imageMetadata.Platform": imageMetadataAccessor.GetImageMetadata().Platform, - "spec.imageMetadata.Digest": imageMetadataAccessor.GetImageMetadata().Digest, + "spec.imageMetadata.registry": imageMetadataAccessor.GetImageMetadata().Registry, + "spec.imageMetadata.registryURI": imageMetadataAccessor.GetImageMetadata().RegistryURI, + "spec.imageMetadata.repository": imageMetadataAccessor.GetImageMetadata().Repository, + "spec.imageMetadata.tag": imageMetadataAccessor.GetImageMetadata().Tag, + "spec.imageMetadata.platform": imageMetadataAccessor.GetImageMetadata().Platform, + "spec.imageMetadata.digest": imageMetadataAccessor.GetImageMetadata().Digest, } return labels.Set(objMeta.GetLabels()), generic.MergeFieldsSets(selectableMetadata, selectableFields), nil diff --git a/test/crd/storage.sbombastic.rancher.io_scanresults.yaml b/test/crd/storage.sbombastic.rancher.io_scanresults.yaml deleted file mode 100644 index bb65706..0000000 --- a/test/crd/storage.sbombastic.rancher.io_scanresults.yaml +++ /dev/null @@ -1,51 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.16.5 - name: scanresults.storage.sbombastic.rancher.io -spec: - group: storage.sbombastic.rancher.io - names: - kind: ScanResult - listKind: ScanResultList - plural: scanresults - singular: scanresult - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: ScanResult is the Schema for the scanresults API - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: ScanResultSpec defines the desired state of ScanResult - properties: - foo: - description: Foo is an example field of ScanResult. - type: string - type: object - status: - description: ScanResultStatus defines the observed state of ScanResult - type: object - type: object - served: true - storage: true diff --git a/test/crd/storage.sbombastic.rancher.io_vulnerabilityreports.yaml b/test/crd/storage.sbombastic.rancher.io_vulnerabilityreports.yaml index 1a39c1f..238d5b1 100644 --- a/test/crd/storage.sbombastic.rancher.io_vulnerabilityreports.yaml +++ b/test/crd/storage.sbombastic.rancher.io_vulnerabilityreports.yaml @@ -84,5 +84,12 @@ spec: description: VulnerabilityReportStatus defines the observed state of ScanResult type: object type: object + selectableFields: + - jsonPath: .spec.imageMetadata.registry + - jsonPath: .spec.imageMetadata.registryURI + - jsonPath: .spec.imageMetadata.repository + - jsonPath: .spec.imageMetadata.tag + - jsonPath: .spec.imageMetadata.platform + - jsonPath: .spec.imageMetadata.digest served: true storage: true