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(controller): add spec.imageMetadata.registry index to SBOM and Image #42

Merged
merged 1 commit into from
Nov 19, 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
11 changes: 11 additions & 0 deletions internal/controller/image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ func (r *ImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl

// SetupWithManager sets up the controller with the Manager.
func (r *ImageReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Add an indexer for the field `spec.imageMetadata.registry`
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &storagev1alpha1.Image{}, "spec.imageMetadata.registry", func(rawObj client.Object) []string {
sbom, ok := rawObj.(*storagev1alpha1.Image)
if !ok {
panic(fmt.Sprintf("Expected Image, got %T", rawObj))
}
return []string{sbom.Spec.ImageMetadata.Registry}
}); err != nil {
return fmt.Errorf("unable to create field indexer: %w", err)
}

err := ctrl.NewControllerManagedBy(mgr).
For(&storagev1alpha1.Image{}).
Complete(r)
Expand Down
11 changes: 11 additions & 0 deletions internal/controller/sbom_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ func (r *SBOMReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.

// SetupWithManager sets up the controller with the Manager.
func (r *SBOMReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Add an indexer for the field `spec.imageMetadata.registry`
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &storagev1alpha1.SBOM{}, "spec.imageMetadata.registry", func(rawObj client.Object) []string {
sbom, ok := rawObj.(*storagev1alpha1.SBOM)
if !ok {
panic(fmt.Sprintf("Expected SBOM, got %T", rawObj))
}
return []string{sbom.Spec.ImageMetadata.Registry}
}); err != nil {
return fmt.Errorf("unable to create field indexer: %w", err)
}

err := ctrl.NewControllerManagedBy(mgr).
// Uncomment the following line adding a pointer to an instance of the controlled resource as an argument
For(&storagev1alpha1.SBOM{}).
Expand Down