ceph: add support for update() from lib-bucket-provisioner

Recently lib-bucket-provisioner add support for update() API.
Include that on the obc implementation since it can be used to
update quota for OBC.

Fixes: #7146

Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
This commit is contained in:
Jiffin Tony Thottan committed 2021-08-19 23:57:11 +05:30
1 parent 67acab94dd
commit f4bb47e440
6 files changed
+104 -10

No files matched your search

+68 -2
View File
@@ -554,8 +554,8 @@ func (p *Provisioner) deleteOBCResourceLogError(bucketname string) {
// Check for additional options mentioned in OBC and set them accordingly
func (p Provisioner) setAdditionalSettings(options *apibkt.BucketOptions) error {
quotaEnabled := true
maxObjects := MaxObjectQuota(options)
maxSize := MaxSizeQuota(options)
maxObjects := MaxObjectQuota(options.ObjectBucketClaim.Spec.AdditionalConfig)
maxSize := MaxSizeQuota(options.ObjectBucketClaim.Spec.AdditionalConfig)
if maxObjects == "" && maxSize == "" {
return nil
}
@@ -665,3 +665,69 @@ func (p *Provisioner) setAdminOpsAPIClient() error {
return nil
}
func (p Provisioner) updateAdditionalSettings(ob *bktv1alpha1.ObjectBucket) error {
var maxObjectsInt64 int64
var maxSizeInt64 int64
var err error
var quotaEnabled bool
maxObjects := MaxObjectQuota(ob.Spec.Endpoint.AdditionalConfigData)
maxSize := MaxSizeQuota(ob.Spec.Endpoint.AdditionalConfigData)
if maxObjects != "" {
maxObjectsInt, err := strconv.Atoi(maxObjects)
if err != nil {
return errors.Wrap(err, "failed to convert maxObjects to integer")
}
maxObjectsInt64 = int64(maxObjectsInt)
}
if maxSize != "" {
maxSizeInt64, err = maxSizeToInt64(maxSize)
if err != nil {
return errors.Wrapf(err, "failed to parse maxSize quota for user %q", p.cephUserName)
}
}
objectUser, err := p.adminOpsClient.GetUser(context.TODO(), admin.User{ID: ob.Spec.Connection.AdditionalState[cephUser]})
if err != nil {
return errors.Wrapf(err, "failed to fetch user %q", p.cephUserName)
}
if *objectUser.UserQuota.Enabled &&
(maxObjects == "" || maxObjectsInt64 < 0) &&
(maxSize == "" || maxSizeInt64 < 0) {
quotaEnabled = false
err = p.adminOpsClient.SetUserQuota(context.TODO(), admin.QuotaSpec{UID: p.cephUserName, Enabled: &quotaEnabled})
if err != nil {
return errors.Wrapf(err, "failed to disable quota to user %q", p.cephUserName)
}
return nil
}
quotaEnabled = true
quotaSpec := admin.QuotaSpec{UID: p.cephUserName, Enabled: &quotaEnabled}
//MaxObject is modified
if maxObjects != "" && (maxObjectsInt64 != *objectUser.UserQuota.MaxObjects) {
quotaSpec.MaxObjects = &maxObjectsInt64
}
//MaxSize is modified
if maxSize != "" && (maxSizeInt64 != *objectUser.UserQuota.MaxSize) {
quotaSpec.MaxSize = &maxSizeInt64
}
err = p.adminOpsClient.SetUserQuota(context.TODO(), quotaSpec)
if err != nil {
return errors.Wrapf(err, "failed to update quota to user %q", p.cephUserName)
}
return nil
}
// Update is sent when only there is modification to AdditionalConfig field in OBC
func (p Provisioner) Update(ob *bktv1alpha1.ObjectBucket) error {
logger.Debugf("Update event for OB: %+v", ob)
err := p.initializeDeleteOrRevoke(ob)
if err != nil {
return err
}
return p.updateAdditionalSettings(ob)
}
+4 -5
View File
@@ -23,7 +23,6 @@ import (
"github.com/coreos/pkg/capnslog"
bktv1alpha1 "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1"
"github.com/kube-object-storage/lib-bucket-provisioner/pkg/provisioner"
apibkt "github.com/kube-object-storage/lib-bucket-provisioner/pkg/provisioner/api"
"github.com/pkg/errors"
storagev1 "k8s.io/api/storage/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
@@ -117,10 +116,10 @@ func randomString(n int) string {
return string(b)
}
func MaxObjectQuota(options *apibkt.BucketOptions) string {
return options.ObjectBucketClaim.Spec.AdditionalConfig["maxObjects"]
func MaxObjectQuota(AdditionalConfig map[string]string) string {
return AdditionalConfig["maxObjects"]
}
func MaxSizeQuota(options *apibkt.BucketOptions) string {
return options.ObjectBucketClaim.Spec.AdditionalConfig["maxSize"]
func MaxSizeQuota(AdditionalConfig map[string]string) string {
return AdditionalConfig["maxSize"]
}