diff --git a/api/storage/v1alpha1/register.go b/api/storage/v1alpha1/register.go index fc4a93f..6e6afe8 100644 --- a/api/storage/v1alpha1/register.go +++ b/api/storage/v1alpha1/register.go @@ -49,6 +49,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &ScanResult{}, &ScanResultList{}, + &SBOM{}, + &SBOMList{}, ) return nil } diff --git a/api/storage/v1alpha1/sbom_types.go b/api/storage/v1alpha1/sbom_types.go new file mode 100644 index 0000000..fd4054b --- /dev/null +++ b/api/storage/v1alpha1/sbom_types.go @@ -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 +} diff --git a/api/storage/v1alpha1/storage_types.go b/api/storage/v1alpha1/scanresult_types.go similarity index 100% rename from api/storage/v1alpha1/storage_types.go rename to api/storage/v1alpha1/scanresult_types.go diff --git a/api/storage/v1alpha1/zz_generated.deepcopy.go b/api/storage/v1alpha1/zz_generated.deepcopy.go index d11e505..076431c 100644 --- a/api/storage/v1alpha1/zz_generated.deepcopy.go +++ b/api/storage/v1alpha1/zz_generated.deepcopy.go @@ -24,6 +24,100 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SBOM) DeepCopyInto(out *SBOM) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SBOM. +func (in *SBOM) DeepCopy() *SBOM { + if in == nil { + return nil + } + out := new(SBOM) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SBOM) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SBOMList) DeepCopyInto(out *SBOMList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ScanResult, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SBOMList. +func (in *SBOMList) DeepCopy() *SBOMList { + if in == nil { + return nil + } + out := new(SBOMList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SBOMList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SBOMSpec) DeepCopyInto(out *SBOMSpec) { + *out = *in + in.Data.DeepCopyInto(&out.Data) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SBOMSpec. +func (in *SBOMSpec) DeepCopy() *SBOMSpec { + if in == nil { + return nil + } + out := new(SBOMSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SBOMStatus) DeepCopyInto(out *SBOMStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SBOMStatus. +func (in *SBOMStatus) DeepCopy() *SBOMStatus { + if in == nil { + return nil + } + out := new(SBOMStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ScanResult) DeepCopyInto(out *ScanResult) { *out = *in diff --git a/cmd/controller/main.go b/cmd/controller/main.go index a495ec5..902dcf1 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -35,6 +35,7 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" + storagev1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" "github.com/rancher/sbombastic/api/v1alpha1" "github.com/rancher/sbombastic/internal/controller" "github.com/rancher/sbombastic/internal/messaging" @@ -48,8 +49,9 @@ var ( func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) - utilruntime.Must(v1alpha1.AddToScheme(scheme)) + utilruntime.Must(storagev1alpha1.AddToScheme(scheme)) + // +kubebuilder:scaffold:scheme } @@ -167,6 +169,16 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "Registry") os.Exit(1) } + + if err = (&controller.ImageReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + Publisher: publisher, + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "Image") + os.Exit(1) + } + // +kubebuilder:scaffold:builder if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { diff --git a/internal/controller/image_controller.go b/internal/controller/image_controller.go index b01c59d..9429405 100644 --- a/internal/controller/image_controller.go +++ b/internal/controller/image_controller.go @@ -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/controller-runtime@v0.19.0/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) + } + } + + 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 } diff --git a/internal/controller/image_controller_test.go b/internal/controller/image_controller_test.go index 51e3898..69b983c 100644 --- a/internal/controller/image_controller_test.go +++ b/internal/controller/image_controller_test.go @@ -19,66 +19,57 @@ package controller import ( "context" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/reconcile" + . "github.com/onsi/ginkgo/v2" //nolint:revive // Required for testing + . "github.com/onsi/gomega" //nolint:revive // Required for testing + "github.com/google/uuid" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/reconcile" sbombasticv1alpha1 "github.com/rancher/sbombastic/api/v1alpha1" + "github.com/rancher/sbombastic/internal/messaging" + messagingMocks "github.com/rancher/sbombastic/internal/messaging/mocks" ) var _ = Describe("Image Controller", func() { - Context("When reconciling a resource", func() { - const resourceName = "test-resource" - - ctx := context.Background() + When("An Image without a SBOM is created", func() { + var reconciler ImageReconciler + var image sbombasticv1alpha1.Image - typeNamespacedName := types.NamespacedName{ - Name: resourceName, - Namespace: "default", // TODO(user):Modify as needed - } - image := &sbombasticv1alpha1.Image{} + BeforeEach(func(ctx context.Context) { + By("Creating a new RegistryReconciler") + reconciler = ImageReconciler{ + Client: k8sClient, + } - BeforeEach(func() { - By("creating the custom resource for the Kind Image") - err := k8sClient.Get(ctx, typeNamespacedName, image) - if err != nil && errors.IsNotFound(err) { - resource := &sbombasticv1alpha1.Image{ - ObjectMeta: metav1.ObjectMeta{ - Name: resourceName, - Namespace: "default", - }, - // TODO(user): Specify other spec details if needed. - } - Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + By("Creating the Image") + image = sbombasticv1alpha1.Image{ + ObjectMeta: metav1.ObjectMeta{ + Name: uuid.New().String(), + Namespace: "default", + }, } + Expect(k8sClient.Create(ctx, &image)).To(Succeed()) }) - AfterEach(func() { - // TODO(user): Cleanup logic after each test, like removing the resource instance. - resource := &sbombasticv1alpha1.Image{} - err := k8sClient.Get(ctx, typeNamespacedName, resource) - Expect(err).NotTo(HaveOccurred()) - - By("Cleanup the specific resource instance Image") - Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) - }) - It("should successfully reconcile the resource", func() { - By("Reconciling the created resource") - controllerReconciler := &ImageReconciler{ - Client: k8sClient, - Scheme: k8sClient.Scheme(), - } + It("should successfully reconcile the resource", func(ctx context.Context) { + By("Ensuring the right message is published to the worker queue") + mockPublisher := messagingMocks.NewPublisher(GinkgoT()) + mockPublisher.On("Publish", &messaging.CreateSBOM{ + ImageName: image.Name, + ImageNamespace: image.Namespace, + }).Return(nil) + reconciler.Publisher = mockPublisher - _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ - NamespacedName: typeNamespacedName, + By("Reconciling the Registry") + _, err := reconciler.Reconcile(ctx, reconcile.Request{ + NamespacedName: types.NamespacedName{ + Name: image.Name, + Namespace: image.Namespace, + }, }) Expect(err).NotTo(HaveOccurred()) - // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. - // Example: If you expect a certain status condition after reconciliation, verify it here. }) }) }) diff --git a/internal/controller/sbom_controller.go b/internal/controller/sbom_controller.go new file mode 100644 index 0000000..e19262f --- /dev/null +++ b/internal/controller/sbom_controller.go @@ -0,0 +1,19 @@ +package controller + +// ownerRef := metav1.GetControllerOf(&image) +// if ownerRef == nil { +// return ctrl.Result{}, errors.New("image does not have a Registry owner") +// } + +// if ownerRef.Kind != "Registry" { +// return ctrl.Result{}, errors.New("image owner is not a Registry") +// } + +// var registry v1alpha1.Registry +// err := r.Get(ctx, client.ObjectKey{ +// Namespace: req.Namespace, +// Name: ownerRef.Name, +// }, ®istry) +// if err != nil { +// return ctrl.Result{}, fmt.Errorf("unable to fetch Registry: %w", err) +// } diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index 777bd90..5b7e724 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -31,6 +31,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" + storagev1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" "github.com/rancher/sbombastic/api/v1alpha1" // +kubebuilder:scaffold:imports ) @@ -78,6 +79,9 @@ var _ = BeforeSuite(func() { err = v1alpha1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) + err = storagev1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + // +kubebuilder:scaffold:scheme k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) diff --git a/internal/messaging/types.go b/internal/messaging/types.go index b04709e..f45bdd2 100644 --- a/internal/messaging/types.go +++ b/internal/messaging/types.go @@ -12,3 +12,12 @@ type CreateCatalog struct { func (m *CreateCatalog) MessageType() string { return "CreateCatalog" } + +type CreateSBOM struct { + ImageName string `json:"imageName"` + ImageNamespace string `json:"imageNamespace"` +} + +func (m *CreateSBOM) MessageType() string { + return "CreateSBOM" +} diff --git a/pkg/generated/applyconfiguration/storage/v1alpha1/sbom.go b/pkg/generated/applyconfiguration/storage/v1alpha1/sbom.go new file mode 100644 index 0000000..e31c828 --- /dev/null +++ b/pkg/generated/applyconfiguration/storage/v1alpha1/sbom.go @@ -0,0 +1,225 @@ +/* +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. +*/ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + storagev1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// SBOMApplyConfiguration represents a declarative configuration of the SBOM type for use +// with apply. +type SBOMApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + Spec *SBOMSpecApplyConfiguration `json:"spec,omitempty"` + Status *storagev1alpha1.SBOMStatus `json:"status,omitempty"` +} + +// SBOM constructs a declarative configuration of the SBOM type for use with +// apply. +func SBOM(name, namespace string) *SBOMApplyConfiguration { + b := &SBOMApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("SBOM") + b.WithAPIVersion("storage.sbombastic.rancher.io/v1alpha1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithKind(value string) *SBOMApplyConfiguration { + b.TypeMetaApplyConfiguration.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithAPIVersion(value string) *SBOMApplyConfiguration { + b.TypeMetaApplyConfiguration.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithName(value string) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithGenerateName(value string) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithNamespace(value string) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithUID(value types.UID) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithResourceVersion(value string) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithGeneration(value int64) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithCreationTimestamp(value metav1.Time) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ObjectMetaApplyConfiguration.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *SBOMApplyConfiguration) WithLabels(entries map[string]string) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.ObjectMetaApplyConfiguration.Labels == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.ObjectMetaApplyConfiguration.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *SBOMApplyConfiguration) WithAnnotations(entries map[string]string) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.ObjectMetaApplyConfiguration.Annotations == nil && len(entries) > 0 { + b.ObjectMetaApplyConfiguration.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.ObjectMetaApplyConfiguration.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *SBOMApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.ObjectMetaApplyConfiguration.OwnerReferences = append(b.ObjectMetaApplyConfiguration.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *SBOMApplyConfiguration) WithFinalizers(values ...string) *SBOMApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.ObjectMetaApplyConfiguration.Finalizers = append(b.ObjectMetaApplyConfiguration.Finalizers, values[i]) + } + return b +} + +func (b *SBOMApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithSpec sets the Spec field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Spec field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithSpec(value *SBOMSpecApplyConfiguration) *SBOMApplyConfiguration { + b.Spec = value + return b +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *SBOMApplyConfiguration) WithStatus(value storagev1alpha1.SBOMStatus) *SBOMApplyConfiguration { + b.Status = &value + return b +} + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *SBOMApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.ObjectMetaApplyConfiguration.Name +} diff --git a/pkg/generated/applyconfiguration/storage/v1alpha1/sbomspec.go b/pkg/generated/applyconfiguration/storage/v1alpha1/sbomspec.go new file mode 100644 index 0000000..1ebd06d --- /dev/null +++ b/pkg/generated/applyconfiguration/storage/v1alpha1/sbomspec.go @@ -0,0 +1,42 @@ +/* +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. +*/ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// SBOMSpecApplyConfiguration represents a declarative configuration of the SBOMSpec type for use +// with apply. +type SBOMSpecApplyConfiguration struct { + Data *runtime.RawExtension `json:"data,omitempty"` +} + +// SBOMSpecApplyConfiguration constructs a declarative configuration of the SBOMSpec type for use with +// apply. +func SBOMSpec() *SBOMSpecApplyConfiguration { + return &SBOMSpecApplyConfiguration{} +} + +// WithData sets the Data field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Data field is set to the value of the last call. +func (b *SBOMSpecApplyConfiguration) WithData(value runtime.RawExtension) *SBOMSpecApplyConfiguration { + b.Data = &value + return b +} diff --git a/pkg/generated/applyconfiguration/utils.go b/pkg/generated/applyconfiguration/utils.go index 07bc304..fc33b90 100644 --- a/pkg/generated/applyconfiguration/utils.go +++ b/pkg/generated/applyconfiguration/utils.go @@ -31,6 +31,10 @@ import ( func ForKind(kind schema.GroupVersionKind) interface{} { switch kind { // Group=storage.sbombastic.rancher.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithKind("SBOM"): + return &storagev1alpha1.SBOMApplyConfiguration{} + case v1alpha1.SchemeGroupVersion.WithKind("SBOMSpec"): + return &storagev1alpha1.SBOMSpecApplyConfiguration{} case v1alpha1.SchemeGroupVersion.WithKind("ScanResult"): return &storagev1alpha1.ScanResultApplyConfiguration{} case v1alpha1.SchemeGroupVersion.WithKind("ScanResultSpec"): diff --git a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/fake/fake_sbom.go b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/fake/fake_sbom.go new file mode 100644 index 0000000..25547af --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/fake/fake_sbom.go @@ -0,0 +1,196 @@ +/* +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. +*/ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + context "context" + json "encoding/json" + fmt "fmt" + + v1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" + storagev1alpha1 "github.com/rancher/sbombastic/pkg/generated/applyconfiguration/storage/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeSBOMs implements SBOMInterface +type FakeSBOMs struct { + Fake *FakeStorageV1alpha1 + ns string +} + +var sbomsResource = v1alpha1.SchemeGroupVersion.WithResource("sboms") + +var sbomsKind = v1alpha1.SchemeGroupVersion.WithKind("SBOM") + +// Get takes name of the sBOM, and returns the corresponding sBOM object, and an error if there is any. +func (c *FakeSBOMs) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.SBOM, err error) { + emptyResult := &v1alpha1.SBOM{} + obj, err := c.Fake. + Invokes(testing.NewGetActionWithOptions(sbomsResource, c.ns, name, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha1.SBOM), err +} + +// List takes label and field selectors, and returns the list of SBOMs that match those selectors. +func (c *FakeSBOMs) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.SBOMList, err error) { + emptyResult := &v1alpha1.SBOMList{} + obj, err := c.Fake. + Invokes(testing.NewListActionWithOptions(sbomsResource, sbomsKind, c.ns, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.SBOMList{ListMeta: obj.(*v1alpha1.SBOMList).ListMeta} + for _, item := range obj.(*v1alpha1.SBOMList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested sBOMs. +func (c *FakeSBOMs) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchActionWithOptions(sbomsResource, c.ns, opts)) + +} + +// Create takes the representation of a sBOM and creates it. Returns the server's representation of the sBOM, and an error, if there is any. +func (c *FakeSBOMs) Create(ctx context.Context, sBOM *v1alpha1.SBOM, opts v1.CreateOptions) (result *v1alpha1.SBOM, err error) { + emptyResult := &v1alpha1.SBOM{} + obj, err := c.Fake. + Invokes(testing.NewCreateActionWithOptions(sbomsResource, c.ns, sBOM, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha1.SBOM), err +} + +// Update takes the representation of a sBOM and updates it. Returns the server's representation of the sBOM, and an error, if there is any. +func (c *FakeSBOMs) Update(ctx context.Context, sBOM *v1alpha1.SBOM, opts v1.UpdateOptions) (result *v1alpha1.SBOM, err error) { + emptyResult := &v1alpha1.SBOM{} + obj, err := c.Fake. + Invokes(testing.NewUpdateActionWithOptions(sbomsResource, c.ns, sBOM, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha1.SBOM), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeSBOMs) UpdateStatus(ctx context.Context, sBOM *v1alpha1.SBOM, opts v1.UpdateOptions) (result *v1alpha1.SBOM, err error) { + emptyResult := &v1alpha1.SBOM{} + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceActionWithOptions(sbomsResource, "status", c.ns, sBOM, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha1.SBOM), err +} + +// Delete takes name of the sBOM and deletes it. Returns an error if one occurs. +func (c *FakeSBOMs) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(sbomsResource, c.ns, name, opts), &v1alpha1.SBOM{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeSBOMs) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionActionWithOptions(sbomsResource, c.ns, opts, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.SBOMList{}) + return err +} + +// Patch applies the patch and returns the patched sBOM. +func (c *FakeSBOMs) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.SBOM, err error) { + emptyResult := &v1alpha1.SBOM{} + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceActionWithOptions(sbomsResource, c.ns, name, pt, data, opts, subresources...), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha1.SBOM), err +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied sBOM. +func (c *FakeSBOMs) Apply(ctx context.Context, sBOM *storagev1alpha1.SBOMApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.SBOM, err error) { + if sBOM == nil { + return nil, fmt.Errorf("sBOM provided to Apply must not be nil") + } + data, err := json.Marshal(sBOM) + if err != nil { + return nil, err + } + name := sBOM.Name + if name == nil { + return nil, fmt.Errorf("sBOM.Name must be provided to Apply") + } + emptyResult := &v1alpha1.SBOM{} + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceActionWithOptions(sbomsResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha1.SBOM), err +} + +// ApplyStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). +func (c *FakeSBOMs) ApplyStatus(ctx context.Context, sBOM *storagev1alpha1.SBOMApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha1.SBOM, err error) { + if sBOM == nil { + return nil, fmt.Errorf("sBOM provided to Apply must not be nil") + } + data, err := json.Marshal(sBOM) + if err != nil { + return nil, err + } + name := sBOM.Name + if name == nil { + return nil, fmt.Errorf("sBOM.Name must be provided to Apply") + } + emptyResult := &v1alpha1.SBOM{} + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceActionWithOptions(sbomsResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha1.SBOM), err +} diff --git a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/fake/fake_storage_client.go b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/fake/fake_storage_client.go index abc6681..e3790b4 100644 --- a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/fake/fake_storage_client.go +++ b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/fake/fake_storage_client.go @@ -27,6 +27,10 @@ type FakeStorageV1alpha1 struct { *testing.Fake } +func (c *FakeStorageV1alpha1) SBOMs(namespace string) v1alpha1.SBOMInterface { + return &FakeSBOMs{c, namespace} +} + func (c *FakeStorageV1alpha1) ScanResults(namespace string) v1alpha1.ScanResultInterface { return &FakeScanResults{c, namespace} } diff --git a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/generated_expansion.go index 39c3dec..9f1344b 100644 --- a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/generated_expansion.go @@ -17,4 +17,6 @@ limitations under the License. package v1alpha1 +type SBOMExpansion interface{} + type ScanResultExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/sbom.go b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/sbom.go new file mode 100644 index 0000000..b144d43 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/sbom.go @@ -0,0 +1,72 @@ +/* +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. +*/ +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + context "context" + + storagev1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" + applyconfigurationstoragev1alpha1 "github.com/rancher/sbombastic/pkg/generated/applyconfiguration/storage/v1alpha1" + scheme "github.com/rancher/sbombastic/pkg/generated/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" +) + +// SBOMsGetter has a method to return a SBOMInterface. +// A group's client should implement this interface. +type SBOMsGetter interface { + SBOMs(namespace string) SBOMInterface +} + +// SBOMInterface has methods to work with SBOM resources. +type SBOMInterface interface { + Create(ctx context.Context, sBOM *storagev1alpha1.SBOM, opts v1.CreateOptions) (*storagev1alpha1.SBOM, error) + Update(ctx context.Context, sBOM *storagev1alpha1.SBOM, opts v1.UpdateOptions) (*storagev1alpha1.SBOM, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, sBOM *storagev1alpha1.SBOM, opts v1.UpdateOptions) (*storagev1alpha1.SBOM, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*storagev1alpha1.SBOM, error) + List(ctx context.Context, opts v1.ListOptions) (*storagev1alpha1.SBOMList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *storagev1alpha1.SBOM, err error) + Apply(ctx context.Context, sBOM *applyconfigurationstoragev1alpha1.SBOMApplyConfiguration, opts v1.ApplyOptions) (result *storagev1alpha1.SBOM, err error) + // Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). + ApplyStatus(ctx context.Context, sBOM *applyconfigurationstoragev1alpha1.SBOMApplyConfiguration, opts v1.ApplyOptions) (result *storagev1alpha1.SBOM, err error) + SBOMExpansion +} + +// sBOMs implements SBOMInterface +type sBOMs struct { + *gentype.ClientWithListAndApply[*storagev1alpha1.SBOM, *storagev1alpha1.SBOMList, *applyconfigurationstoragev1alpha1.SBOMApplyConfiguration] +} + +// newSBOMs returns a SBOMs +func newSBOMs(c *StorageV1alpha1Client, namespace string) *sBOMs { + return &sBOMs{ + gentype.NewClientWithListAndApply[*storagev1alpha1.SBOM, *storagev1alpha1.SBOMList, *applyconfigurationstoragev1alpha1.SBOMApplyConfiguration]( + "sboms", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *storagev1alpha1.SBOM { return &storagev1alpha1.SBOM{} }, + func() *storagev1alpha1.SBOMList { return &storagev1alpha1.SBOMList{} }), + } +} diff --git a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/storage_client.go b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/storage_client.go index d16b934..603df57 100644 --- a/pkg/generated/clientset/versioned/typed/storage/v1alpha1/storage_client.go +++ b/pkg/generated/clientset/versioned/typed/storage/v1alpha1/storage_client.go @@ -27,6 +27,7 @@ import ( type StorageV1alpha1Interface interface { RESTClient() rest.Interface + SBOMsGetter ScanResultsGetter } @@ -35,6 +36,10 @@ type StorageV1alpha1Client struct { restClient rest.Interface } +func (c *StorageV1alpha1Client) SBOMs(namespace string) SBOMInterface { + return newSBOMs(c, namespace) +} + func (c *StorageV1alpha1Client) ScanResults(namespace string) ScanResultInterface { return newScanResults(c, namespace) } diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index 20d355c..1cfadc2 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -52,6 +52,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=storage.sbombastic.rancher.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("sboms"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Storage().V1alpha1().SBOMs().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("scanresults"): return &genericInformer{resource: resource.GroupResource(), informer: f.Storage().V1alpha1().ScanResults().Informer()}, nil diff --git a/pkg/generated/informers/externalversions/storage/v1alpha1/interface.go b/pkg/generated/informers/externalversions/storage/v1alpha1/interface.go index 5c43ab9..58c6cbe 100644 --- a/pkg/generated/informers/externalversions/storage/v1alpha1/interface.go +++ b/pkg/generated/informers/externalversions/storage/v1alpha1/interface.go @@ -23,6 +23,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // SBOMs returns a SBOMInformer. + SBOMs() SBOMInformer // ScanResults returns a ScanResultInformer. ScanResults() ScanResultInformer } @@ -38,6 +40,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// SBOMs returns a SBOMInformer. +func (v *version) SBOMs() SBOMInformer { + return &sBOMInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // ScanResults returns a ScanResultInformer. func (v *version) ScanResults() ScanResultInformer { return &scanResultInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/generated/informers/externalversions/storage/v1alpha1/sbom.go b/pkg/generated/informers/externalversions/storage/v1alpha1/sbom.go new file mode 100644 index 0000000..40d6faa --- /dev/null +++ b/pkg/generated/informers/externalversions/storage/v1alpha1/sbom.go @@ -0,0 +1,89 @@ +/* +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. +*/ +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + context "context" + time "time" + + apistoragev1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" + versioned "github.com/rancher/sbombastic/pkg/generated/clientset/versioned" + internalinterfaces "github.com/rancher/sbombastic/pkg/generated/informers/externalversions/internalinterfaces" + storagev1alpha1 "github.com/rancher/sbombastic/pkg/generated/listers/storage/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// SBOMInformer provides access to a shared informer and lister for +// SBOMs. +type SBOMInformer interface { + Informer() cache.SharedIndexInformer + Lister() storagev1alpha1.SBOMLister +} + +type sBOMInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewSBOMInformer constructs a new informer for SBOM type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewSBOMInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredSBOMInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredSBOMInformer constructs a new informer for SBOM type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredSBOMInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.StorageV1alpha1().SBOMs(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.StorageV1alpha1().SBOMs(namespace).Watch(context.TODO(), options) + }, + }, + &apistoragev1alpha1.SBOM{}, + resyncPeriod, + indexers, + ) +} + +func (f *sBOMInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredSBOMInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *sBOMInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apistoragev1alpha1.SBOM{}, f.defaultInformer) +} + +func (f *sBOMInformer) Lister() storagev1alpha1.SBOMLister { + return storagev1alpha1.NewSBOMLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/listers/storage/v1alpha1/expansion_generated.go b/pkg/generated/listers/storage/v1alpha1/expansion_generated.go index 9c923cd..67f9a6b 100644 --- a/pkg/generated/listers/storage/v1alpha1/expansion_generated.go +++ b/pkg/generated/listers/storage/v1alpha1/expansion_generated.go @@ -17,6 +17,14 @@ limitations under the License. package v1alpha1 +// SBOMListerExpansion allows custom methods to be added to +// SBOMLister. +type SBOMListerExpansion interface{} + +// SBOMNamespaceListerExpansion allows custom methods to be added to +// SBOMNamespaceLister. +type SBOMNamespaceListerExpansion interface{} + // ScanResultListerExpansion allows custom methods to be added to // ScanResultLister. type ScanResultListerExpansion interface{} diff --git a/pkg/generated/listers/storage/v1alpha1/sbom.go b/pkg/generated/listers/storage/v1alpha1/sbom.go new file mode 100644 index 0000000..452be0e --- /dev/null +++ b/pkg/generated/listers/storage/v1alpha1/sbom.go @@ -0,0 +1,69 @@ +/* +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. +*/ +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + storagev1alpha1 "github.com/rancher/sbombastic/api/storage/v1alpha1" + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" +) + +// SBOMLister helps list SBOMs. +// All objects returned here must be treated as read-only. +type SBOMLister interface { + // List lists all SBOMs in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*storagev1alpha1.SBOM, err error) + // SBOMs returns an object that can list and get SBOMs. + SBOMs(namespace string) SBOMNamespaceLister + SBOMListerExpansion +} + +// sBOMLister implements the SBOMLister interface. +type sBOMLister struct { + listers.ResourceIndexer[*storagev1alpha1.SBOM] +} + +// NewSBOMLister returns a new SBOMLister. +func NewSBOMLister(indexer cache.Indexer) SBOMLister { + return &sBOMLister{listers.New[*storagev1alpha1.SBOM](indexer, storagev1alpha1.Resource("sbom"))} +} + +// SBOMs returns an object that can list and get SBOMs. +func (s *sBOMLister) SBOMs(namespace string) SBOMNamespaceLister { + return sBOMNamespaceLister{listers.NewNamespaced[*storagev1alpha1.SBOM](s.ResourceIndexer, namespace)} +} + +// SBOMNamespaceLister helps list and get SBOMs. +// All objects returned here must be treated as read-only. +type SBOMNamespaceLister interface { + // List lists all SBOMs in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*storagev1alpha1.SBOM, err error) + // Get retrieves the SBOM from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*storagev1alpha1.SBOM, error) + SBOMNamespaceListerExpansion +} + +// sBOMNamespaceLister implements the SBOMNamespaceLister +// interface. +type sBOMNamespaceLister struct { + listers.ResourceIndexer[*storagev1alpha1.SBOM] +} diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index bc6a138..35c6b71 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -28,6 +28,10 @@ import ( func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ + "github.com/rancher/sbombastic/api/storage/v1alpha1.SBOM": schema_sbombastic_api_storage_v1alpha1_SBOM(ref), + "github.com/rancher/sbombastic/api/storage/v1alpha1.SBOMList": schema_sbombastic_api_storage_v1alpha1_SBOMList(ref), + "github.com/rancher/sbombastic/api/storage/v1alpha1.SBOMSpec": schema_sbombastic_api_storage_v1alpha1_SBOMSpec(ref), + "github.com/rancher/sbombastic/api/storage/v1alpha1.SBOMStatus": schema_sbombastic_api_storage_v1alpha1_SBOMStatus(ref), "github.com/rancher/sbombastic/api/storage/v1alpha1.ScanResult": schema_sbombastic_api_storage_v1alpha1_ScanResult(ref), "github.com/rancher/sbombastic/api/storage/v1alpha1.ScanResultList": schema_sbombastic_api_storage_v1alpha1_ScanResultList(ref), "github.com/rancher/sbombastic/api/storage/v1alpha1.ScanResultSpec": schema_sbombastic_api_storage_v1alpha1_ScanResultSpec(ref), @@ -88,6 +92,134 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA } } +func schema_sbombastic_api_storage_v1alpha1_SBOM(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "SBOM represents a Software Bill of Materials of an OCI artifact", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + 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{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + 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{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/rancher/sbombastic/api/storage/v1alpha1.SBOMSpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/rancher/sbombastic/api/storage/v1alpha1.SBOMStatus"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/rancher/sbombastic/api/storage/v1alpha1.SBOMSpec", "github.com/rancher/sbombastic/api/storage/v1alpha1.SBOMStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_sbombastic_api_storage_v1alpha1_SBOMList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "SBOMList contains a list of Sbom", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + 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{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + 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{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/rancher/sbombastic/api/storage/v1alpha1.ScanResult"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "github.com/rancher/sbombastic/api/storage/v1alpha1.ScanResult", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_sbombastic_api_storage_v1alpha1_SBOMSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "SBOMSpec defines the desired state of a SBOM", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "data": { + SchemaProps: spec.SchemaProps{ + Ref: ref("k8s.io/apimachinery/pkg/runtime.RawExtension"), + }, + }, + }, + Required: []string{"data"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/runtime.RawExtension"}, + } +} + +func schema_sbombastic_api_storage_v1alpha1_SBOMStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "SBOMStatus defines the observed state of SBOM", + Type: []string{"object"}, + }, + }, + } +} + func schema_sbombastic_api_storage_v1alpha1_ScanResult(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{