-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fabrizio Sestito <[email protected]>
- Loading branch information
1 parent
2188055
commit e90b1ef
Showing
31 changed files
with
1,503 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// SBOMList contains a list of Software Bill of Materials | ||
type SBOMList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ScanResult `json:"items"` | ||
} | ||
|
||
// +genclient | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// SBOM represents a Software Bill of Materials of an OCI artifact | ||
type SBOM struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec SBOMSpec `json:"spec,omitempty"` | ||
Status SBOMStatus `json:"status,omitempty"` | ||
} | ||
|
||
// SBOMSpec defines the desired state of a SBOM | ||
type SBOMSpec struct { | ||
Data runtime.RawExtension `json:"data"` | ||
} | ||
|
||
// SBOMStatus defines the observed state of a SBOM | ||
type SBOMStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
} |
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,45 +18,71 @@ package controller | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
sbombasticv1alpha1 "github.com/rancher/sbombastic/api/v1alpha1" | ||
storagev1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" | ||
"github.com/rancher/sbombastic/api/v1alpha1" | ||
"github.com/rancher/sbombastic/internal/messaging" | ||
) | ||
|
||
// ImageReconciler reconciles a Image object | ||
type ImageReconciler struct { | ||
client.Client | ||
Scheme *runtime.Scheme | ||
Scheme *runtime.Scheme | ||
Publisher messaging.Publisher | ||
} | ||
|
||
// +kubebuilder:rbac:groups=sbombastic.sbombastic.rancher.io,resources=images,verbs=get;list;watch;create;update;patch;delete | ||
// +kubebuilder:rbac:groups=sbombastic.sbombastic.rancher.io,resources=images/status,verbs=get;update;patch | ||
// +kubebuilder:rbac:groups=sbombastic.sbombastic.rancher.io,resources=images/finalizers,verbs=update | ||
|
||
// Reconcile is part of the main kubernetes reconciliation loop which aims to | ||
// move the current state of the cluster closer to the desired state. | ||
// TODO(user): Modify the Reconcile function to compare the state specified by | ||
// the Image object against the actual cluster state, and then | ||
// perform operations to make the cluster state reflect the state specified by | ||
// the user. | ||
// | ||
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *ImageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
_ = log.FromContext(ctx) | ||
log := log.FromContext(ctx) | ||
|
||
// TODO(user): your logic here | ||
var image v1alpha1.Image | ||
if err := r.Get(ctx, req.NamespacedName, &image); err != nil { | ||
if !apierrors.IsNotFound(err) { | ||
return ctrl.Result{}, fmt.Errorf("unable to fetch Image: %w", err) | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} | ||
|
||
var sbom storagev1alpha1.SBOM | ||
if err := r.Get(ctx, req.NamespacedName, &sbom); err != nil { | ||
if apierrors.IsNotFound(err) { | ||
log.Info("Creating SBOM of Image", "name", image.Name, "namespace", image.Namespace) | ||
|
||
msg := messaging.CreateSBOM{ | ||
ImageName: image.Name, | ||
ImageNamespace: image.Namespace, | ||
} | ||
|
||
if err := r.Publisher.Publish(&msg); err != nil { | ||
return ctrl.Result{}, fmt.Errorf("unable to publish CreateSBOM message: %w", err) | ||
} | ||
} else { | ||
return ctrl.Result{}, fmt.Errorf("unable to fetch SBOM: %w", err) | ||
} | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} | ||
|
||
// SetupWithManager sets up the controller with the Manager. | ||
func (r *ImageReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&sbombasticv1alpha1.Image{}). | ||
err := ctrl.NewControllerManagedBy(mgr). | ||
For(&v1alpha1.Image{}). | ||
Complete(r) | ||
if err != nil { | ||
return fmt.Errorf("failed to create Image controller: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.