Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hostpath):enforce xfs quota on the hostpath #78

Merged
merged 5 commits into from
Aug 30, 2021

Conversation

almas33
Copy link
Contributor

@almas33 almas33 commented Aug 8, 2021

feat(hostpath):enforce xfs quota on the hostpath

Issue no. - #13

To test:-

  1. Follow documentation of task 1 - https://docs.google.com/document/d/1Vs-8Xv4fm_B5-qp4I7dYEVYfO4hEVY7KMV9uhAgdZfk/edit# to setup xfs fs in the basepath.
  2. Use my image almas33/openebs-pv in place of openebs/provisioner-localpv and almas33/xfs-quota in place of openebs/linux-utils
  3. Add type:enforceXfsQuota , bsoft as soft limit and bhard as hard limit in the parameters in storage class.yaml
  4. Run pod as done normally.

@almas33 almas33 changed the title hostpath_enfoece_quota hostpath_enforce_quota Aug 8, 2021
@Ab-hishek Ab-hishek requested a review from kmova August 9, 2021 04:41
@Ab-hishek Ab-hishek self-requested a review August 9, 2021 04:41
@Ab-hishek Ab-hishek added this to RC2 - Due: Aug 8 2021 in 2.12 Release Tracker - Due Aug 15th. Aug 9, 2021
@Ab-hishek Ab-hishek requested a review from akhilerm August 9, 2021 04:42
@Ab-hishek Ab-hishek moved this from RC2 - Due: Aug 8 2021 to Pre-commits and Designs - Due: July 31 2021 in 2.12 Release Tracker - Due Aug 15th. Aug 9, 2021
@codecov-commenter
Copy link

codecov-commenter commented Aug 9, 2021

Codecov Report

Merging #78 (1b00e61) into develop (46ac0ac) will decrease coverage by 0.49%.
The diff coverage is 20.58%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #78      +/-   ##
===========================================
- Coverage    33.99%   33.49%   -0.50%     
===========================================
  Files           29       29              
  Lines         2518     2618     +100     
===========================================
+ Hits           856      877      +21     
- Misses        1618     1697      +79     
  Partials        44       44              
Impacted Files Coverage Δ
...md/provisioner-localpv/app/provisioner_hostpath.go 0.00% <0.00%> (ø)
cmd/provisioner-localpv/app/helper_hostpath.go 13.54% <30.43%> (+13.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9884bd9...1b00e61. Read the comment docs.

Copy link
Member

@Ab-hishek Ab-hishek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@almas33 Given some comments for changes.

cmd/provisioner-localpv/app/helper_hostpath.go Outdated Show resolved Hide resolved
cmd/provisioner-localpv/app/provisioner_hostpath.go Outdated Show resolved Hide resolved
cmd/provisioner-localpv/app/provisioner_hostpath.go Outdated Show resolved Hide resolved
cmd/provisioner-localpv/app/quota_hostpath.go Outdated Show resolved Hide resolved
cmd/provisioner-localpv/app/quota_hostpath.go Outdated Show resolved Hide resolved
Comment on lines 76 to 79
lastPid := "PID=`xfs_quota -x -c 'report -h' /data | tail -2 | awk 'NR==1{print substr ($1,2)}+0'` ;"
newPid := "PID=`expr $PID + 1` ;"
initializeProject := "xfs_quota -x -c 'project -s -p " + filepath.Join("/data/", config.volumeDir) + " '$PID /data ;"
setQuota := "xfs_quota -x -c 'limit -p bsoft=" + config.bsoft + " bhard=" + config.bhard + " '$PID /data"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether this will work on only system as while testing myself I was not able to run these commands without the root access. So, I feel better to give this pod root access. cc: @kmova @akhilerm .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in this way, if one commands fails then what's the point of running the subsequent commands. I feel rather than passing these commands like this better to create a shell script for all these commands(with proper error or successful logs) but still the logs in the pod won't be of much help as the pod will be deleted after few seconds and pass them as configmap volumes to the helper pod and execute the script. cc: @kmova @akhilerm .

cmd/provisioner-localpv/app/quota_hostpath.go Outdated Show resolved Hide resolved
cmd/provisioner-localpv/app/quota_hostpath.go Outdated Show resolved Hide resolved
@prateekpandey14 prateekpandey14 moved this from Pre-commits and Designs - Due: July 31 2021 to RC2 - Due: Aug 8 2021 in 2.12 Release Tracker - Due Aug 15th. Aug 10, 2021
@prateekpandey14 prateekpandey14 moved this from RC2 - Due: Aug 8 2021 to Pushed to Next release due to WIP in 2.12 Release Tracker - Due Aug 15th. Aug 10, 2021
@prateekpandey14 prateekpandey14 moved this from Pushed to Next release due to WIP to RC2 - Due: Aug 8 2021 in 2.12 Release Tracker - Due Aug 15th. Aug 10, 2021
@almas33 almas33 requested a review from Ab-hishek August 11, 2021 13:36
Comment on lines 99 to 114
bsoft := opts.StorageClass.Parameters[Bsoft]
bhard := opts.StorageClass.Parameters[Bhard]

podOpts := &HelperPodOptions{
name: name,
path: path,
nodeAffinityLabelKey: nodeAffinityKey,
nodeAffinityLabelValue: nodeAffinityValue,
serviceAccountName: saName,
selectedNodeTaints: taints,
imagePullSecrets: imagePullSecrets,
bsoft: bsoft,
bhard: bhard,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these can be performed outside of this if condition. If the fields are not filled by the user then they will remain empty. And for if condition you can check for:

Suggested change
bsoft := opts.StorageClass.Parameters[Bsoft]
bhard := opts.StorageClass.Parameters[Bhard]
podOpts := &HelperPodOptions{
name: name,
path: path,
nodeAffinityLabelKey: nodeAffinityKey,
nodeAffinityLabelValue: nodeAffinityValue,
serviceAccountName: saName,
selectedNodeTaints: taints,
imagePullSecrets: imagePullSecrets,
bsoft: bsoft,
bhard: bhard,
}
if scType == "enforceXfsQuota" && (len(Bsoft) != 0 || len(Bhard) != 0)

And then have proper error handling checks too.

Copy link
Contributor Author

@almas33 almas33 Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should check like this if scType == "enforceXfsQuota" && (len(Bsoft) != 0 || len(Bhard) != 0) because if user has given type enforceXfsQuota that means he wants to set quota , then we should try to create quota pod , but while pod creation the error both limits can't be 0 will be displayed and it will fail but doing like the way you suggested there will be no error displayed

Copy link
Contributor Author

@almas33 almas33 Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to remove redeclaration of podOpts we can declare value of bsoft and bhard while sending it to helper pod , it will be empty anyways ( values are not provided in parameters )as variable is declared in podOpts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@almas33 - it is quite possible to misconfigure the parameters or provide incorrect parameters by users - while they are learning how to use the solution. The code should handle this via:

  • Sane defaults
  • Catch errors

Copy link
Contributor Author

@almas33 almas33 Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kmova - does that mean there will be some default limits applied if there is error in limits entered in parameter . Error handling of incorrect parameters are already taken care in convertToK()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@almas33, let us get back to this comment after the changes suggested in the design doc for storage class parameters are updated. The validation will change.

@Ab-hishek Ab-hishek changed the title hostpath_enforce_quota feat(hostpath):enforce xfs quota on the hostpath Aug 13, 2021
@kmova kmova added this to Pre-commits and Designs - Due: Aug 30 2021 in 3.0 Release Tracker - Released Sept 24th. Aug 15, 2021
@kmova kmova moved this from RC2 - Due: Aug 8 2021 to Pushed to Next release due to WIP in 2.12 Release Tracker - Due Aug 15th. Aug 15, 2021
@almas33 almas33 requested a review from Ab-hishek August 18, 2021 19:17
@almas33 almas33 requested a review from Ab-hishek August 19, 2021 10:56
go.mod Outdated Show resolved Hide resolved
@Ab-hishek
Copy link
Member

The PR looks good to me. @kmova can you review it once.

@Ab-hishek Ab-hishek requested a review from kmova August 19, 2021 12:24
@Ab-hishek
Copy link
Member

I'll try to add integration tests in the same PR. Or else, we can take that up in a separate PR.

@niladrih
Copy link
Member

@almas33 Could you please rebase your branch with 'develop' once? Thanks.

@kmova kmova merged commit 0b57dff into openebs:develop Aug 30, 2021
2.12 Release Tracker - Due Aug 15th. automation moved this from Pushed to Next release due to WIP to Done Aug 30, 2021
3.0 Release Tracker - Released Sept 24th. automation moved this from Pre-commits and Designs - Due: Aug 30 2021 to Done Aug 30, 2021
@almas33 almas33 deleted the 13-enforce-quota-hostpath branch September 19, 2021 08:20
niladrih pushed a commit that referenced this pull request Jun 28, 2024
Initial implementation to enforce quota on the XFS volumes. 
- The feature is controlled by specifying the quota parameter in the StorageClass along with specifying the values for limits.

Note: Additional PRs will be raised to refactor the implementation and add integration tests. 

Signed-off-by : Almas Ahmad <ahmadalmas.786.aa@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants