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

fix(storage): field selectors #49

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/storage/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions internal/storage/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 0 additions & 51 deletions test/crd/storage.sbombastic.rancher.io_scanresults.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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