Skip to content

Commit

Permalink
Merge pull request #209 from vshn/objbucket/del_prot
Browse files Browse the repository at this point in the history
Add deletionProtection for ObjectBuckets
  • Loading branch information
TheBigLee authored Jul 31, 2024
2 parents ea9d906 + 2500a00 commit 2768c5d
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 218 deletions.
16 changes: 16 additions & 0 deletions apis/v1/objectstorage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
// BucketDeletionPolicy determines how buckets should be deleted when a Bucket is deleted.
type BucketDeletionPolicy string

//go:generate yq -i e ../generated/appcat.vshn.io_objectbuckets.yaml --expression "with(.spec.versions[]; .schema.openAPIV3Schema.properties.spec.properties.parameters.properties.security.default={})"

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Bucket Name",type="string",JSONPath=".spec.parameters.bucketName"
// +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".spec.parameters.region"
Expand Down Expand Up @@ -60,6 +62,9 @@ type ObjectBucketParameters struct {
// `DeleteIfEmpty` only deletes the bucket if the bucket is empty.
// `DeleteAll` recursively deletes all objects in the bucket and then removes it.
BucketDeletionPolicy BucketDeletionPolicy `json:"bucketDeletionPolicy,omitempty"`

// Security defines the security of a service
Security Security `json:"security,omitempty"`
}

// ObjectBucketStatus reflects the observed state of a ObjectBucket.
Expand Down Expand Up @@ -96,3 +101,14 @@ type NamespacedName struct {
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
}

// Security defines the security of a service
type Security struct {
// DeletionProtection blocks the deletion of the instance if it is enabled (enabled by default)
// +kubebuilder:default=true
DeletionProtection bool `json:"deletionProtection,omitempty"`
}

func (v *ObjectBucket) GetSecurity() *Security {
return &v.Spec.Parameters.Security
}
16 changes: 16 additions & 0 deletions apis/v1/zz_generated.deepcopy.go

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

7 changes: 6 additions & 1 deletion cmd/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ func setupWebhooks(mgr manager.Manager, withQuota bool) error {
return err
}

err = webhooks.SetupObjectbucketCDeletionProtectionHandlerWithManager(mgr)
err = webhooks.SetupXObjectbucketCDeletionProtectionHandlerWithManager(mgr)
if err != nil {
return err
}

err = webhooks.SetupObjectbucketDeletionProtectionHandlerWithManager(mgr)
if err != nil {
return err
}
Expand Down
19 changes: 19 additions & 0 deletions config/controller/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ webhooks:
resources:
- namespaces
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
service:
name: webhook-service
namespace: system
path: /validate-appcat-vshn-io-v1-objectbucket
failurePolicy: Fail
name: objectbuckets.vshn.appcat.vshn.io
rules:
- apiGroups:
- appcat.vshn.io
apiVersions:
- v1
operations:
- DELETE
resources:
- objectbuckets
sideEffects: None
- admissionReviewVersions:
- v1
clientConfig:
Expand Down
Loading

0 comments on commit 2768c5d

Please sign in to comment.