Skip to content

Commit

Permalink
Bucket Notifications - Add bucketNotifications field to noobaa CRD, a…
Browse files Browse the repository at this point in the history
…dapt reconcile.

Signed-off-by: Amit Prinz Setter <[email protected]>
  • Loading branch information
alphaprinz committed Nov 18, 2024
1 parent b62bb7e commit 559f1d5
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 41 deletions.
36 changes: 36 additions & 0 deletions deploy/crds/noobaa.io_noobaas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,42 @@ spec:
- guaranteed - much more reliable but need to provide a storage class that supports RWX PVs
type: string
type: object
bucketNotifications:
description: BucketNotifications (optional) controls bucket notification
options
properties:
connections:
description: |-
Connections - A list of secrets' names that are used by the notifications configrations
(in the TopicArn field).
items:
description: |-
SecretReference represents a Secret Reference. It has enough information to retrieve secret
in any namespace
properties:
name:
description: name is unique within a namespace to reference
a secret resource.
type: string
namespace:
description: namespace defines the space within which the
secret name must be unique.
type: string
type: object
x-kubernetes-map-type: atomic
type: array
enabled:
description: Enabled - whether bucket notifications is enabled
type: boolean
pvc:
description: |-
PVC (optional) specifies the name of the Persistent Volume Claim (PVC) to be used
for holding pending notifications files.
For ODF - If not provided, the default CepthFS storage class will be used to create the PVC.
type: string
required:
- enabled
type: object
cleanupPolicy:
description: CleanupPolicy (optional) Indicates user's policy for
deletion
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/noobaa/v1alpha1/noobaa_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ type NooBaaSpec struct {
// BucketLogging sets the configuration for bucket logging
// +optional
BucketLogging BucketLoggingSpec `json:"bucketLogging,omitempty"`

// BucketNotifications (optional) controls bucket notification options
// +optional
BucketNotifications BucketNotificationsSpec `json:"bucketNotifications,omitempty"`
}

// AutoscalerSpec defines different actoscaling spec such as autoscaler type and prometheus namespace
Expand Down Expand Up @@ -258,6 +262,22 @@ type BucketLoggingSpec struct {
BucketLoggingPVC *string `json:"bucketLoggingPVC,omitempty"`
}

//BucketNotificationsSpec controls bucket notification configuration
type BucketNotificationsSpec struct {
// Enabled - whether bucket notifications is enabled
Enabled bool `json:"enabled"`

//PVC (optional) specifies the name of the Persistent Volume Claim (PVC) to be used
//for holding pending notifications files.
//For ODF - If not provided, the default CepthFS storage class will be used to create the PVC.
// +optional
PVC *string `json:"pvc,omitempty"`

//Connections - A list of secrets' names that are used by the notifications configrations
//(in the TopicArn field).
Connections []corev1.SecretReference `json:"connections,omitempty"`
}

// LoadBalancerSourceSubnetSpec defines the subnets that will be allowed to access the NooBaa services
type LoadBalancerSourceSubnetSpec struct {
// S3 is a list of subnets that will be allowed to access the Noobaa S3 service
Expand Down
27 changes: 27 additions & 0 deletions pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 37 additions & 1 deletion pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ spec:
status: {}
`

const Sha256_deploy_crds_noobaa_io_noobaas_yaml = "3f88c800238f25e5dd26f3f1bf19028571cc646e3aea0f868bfd2ff600ee3ed1"
const Sha256_deploy_crds_noobaa_io_noobaas_yaml = "e862d263d097ed43f774784eaaf9a616967746b67608fadbe4ca71d93b220ab6"

const File_deploy_crds_noobaa_io_noobaas_yaml = `---
apiVersion: apiextensions.k8s.io/v1
Expand Down Expand Up @@ -2447,6 +2447,42 @@ spec:
- guaranteed - much more reliable but need to provide a storage class that supports RWX PVs
type: string
type: object
bucketNotifications:
description: BucketNotifications (optional) controls bucket notification
options
properties:
connections:
description: |-
Connections - A list of secrets' names that are used by the notifications configrations
(in the TopicArn field).
items:
description: |-
SecretReference represents a Secret Reference. It has enough information to retrieve secret
in any namespace
properties:
name:
description: name is unique within a namespace to reference
a secret resource.
type: string
namespace:
description: namespace defines the space within which the
secret name must be unique.
type: string
type: object
x-kubernetes-map-type: atomic
type: array
enabled:
description: Enabled - whether bucket notifications is enabled
type: boolean
pvc:
description: |-
PVC (optional) specifies the name of the Persistent Volume Claim (PVC) to be used
for holding pending notifications files.
For ODF - If not provided, the default CepthFS storage class will be used to create the PVC.
type: string
required:
- enabled
type: object
cleanupPolicy:
description: CleanupPolicy (optional) Indicates user's policy for
deletion
Expand Down
35 changes: 21 additions & 14 deletions pkg/system/phase1_verifying.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ func (r *Reconciler) ReconcilePhaseVerifying() error {
}

if r.NooBaa.Spec.BucketLogging.LoggingType == nbv1.BucketLoggingTypeGuaranteed {
if err := r.checkBucketLoggingPVC(); err != nil {
if err := r.checkPersistentLoggingPVC(r.NooBaa.Spec.BucketLogging.BucketLoggingPVC, r.BucketLoggingPVC, "InvalidBucketLoggingConfiguration"); err != nil {
return err
}
}

if r.NooBaa.Spec.BucketNotifications.Enabled {
if err := r.checkPersistentLoggingPVC(r.NooBaa.Spec.BucketNotifications.PVC, r.BucketNotificationsPVC, "InvalidBucketNotificationConfiguration"); err != nil {
return err
}
}
Expand Down Expand Up @@ -266,10 +272,11 @@ func (r *Reconciler) checkExternalPg(postgresDbURL string) error {
}

// checkBucketLoggingPVC validates the configuration of bucket logging pvc
func (r *Reconciler) checkBucketLoggingPVC() error {
// Rejecting if 'BucketLoggingPVC' is not provided for 'guaranteed' logging and
// also the operator is not running in the ODF environment.
if r.NooBaa.Spec.BucketLogging.BucketLoggingPVC == nil {
func (r *Reconciler) checkPersistentLoggingPVC(
pvcName *string,
pvc *corev1.PersistentVolumeClaim,
errorName string) error {
if pvc == nil {
sc := &storagev1.StorageClass{
TypeMeta: metav1.TypeMeta{Kind: "StorageClass"},
ObjectMeta: metav1.ObjectMeta{Name: "ocs-storagecluster-cephfs"},
Expand All @@ -278,29 +285,29 @@ func (r *Reconciler) checkBucketLoggingPVC() error {
if util.KubeCheck(sc) {
return nil
}
return util.NewPersistentError("InvalidBucketLoggingConfiguration",
return util.NewPersistentError(errorName,
"'Guaranteed' BucketLogging requires a Persistent Volume Claim (PVC) with ReadWriteMany (RWX) access mode. Please specify the 'BucketLoggingPVC' to ensure guaranteed logging")
}

// Check if pvc exists in the cluster
BucketLoggingPVC := &corev1.PersistentVolumeClaim{
PersistentLoggingPVC := &corev1.PersistentVolumeClaim{
TypeMeta: metav1.TypeMeta{Kind: "PersistenVolumeClaim"},
ObjectMeta: metav1.ObjectMeta{
Name: *r.NooBaa.Spec.BucketLogging.BucketLoggingPVC,
Name: *pvcName,
Namespace: r.Request.Namespace,
},
}
if !util.KubeCheck(BucketLoggingPVC) {
return util.NewPersistentError("InvalidBucketLoggingConfiguration",
fmt.Sprintf("The specified BucketLoggingPVC '%s' was not found", BucketLoggingPVC.Name))
if !util.KubeCheck(PersistentLoggingPVC) {
return util.NewPersistentError(errorName,
fmt.Sprintf("The specified persistent logging pvc '%s' was not found", *pvcName))
}

// Check if pvc supports RWX access mode
for _, accessMode := range BucketLoggingPVC.Spec.AccessModes {
for _, accessMode := range PersistentLoggingPVC.Spec.AccessModes {
if accessMode == corev1.ReadWriteMany {
return nil
}
}
return util.NewPersistentError("InvalidBucketLoggingConfiguration",
fmt.Sprintf("The specified BucketLoggingPVC '%s' does not support RWX access mode", BucketLoggingPVC.Name))
return util.NewPersistentError(errorName,
fmt.Sprintf("The specified persistent logging pvc '%s' does not support RWX access mode", *pvcName))
}
Loading

0 comments on commit 559f1d5

Please sign in to comment.