Skip to content

Conversation

@derekwaynecarr
Copy link
Member

@derekwaynecarr derekwaynecarr commented Nov 14, 2016

Add support for the ability to configure the quota system to identify specific resources that are limited by default. A limited resource means its consumption is denied absent a covering quota. This is in contrast to the current behavior where consumption is unlimited absent a covering quota. Intended use case is to allow operators to restrict consumption of high-cost resources by default.

Example configuration:

admission-control-config-file.yaml

apiVersion: apiserver.k8s.io/v1alpha1
kind: AdmissionConfiguration
plugins:
- name: "ResourceQuota"
  configuration:
    apiVersion: resourcequota.admission.k8s.io/v1alpha1
    kind: Configuration
    limitedResources:
    - resource: pods
      matchContains:
      - pods
      - requests.cpu
    - resource: persistentvolumeclaims
      matchContains:
      - .storageclass.storage.k8s.io/requests.storage

In the above configuration, if a namespace lacked a quota for any of the following:

  • cpu
  • any pvc associated with particular storage class

The attempt to consume the resource is denied with a message stating the user has insufficient quota for the matching resources.

$ kubectl create -f pvc-gold.yaml 
Error from server: error when creating "pvc-gold.yaml": insufficient quota to consume: gold.storageclass.storage.k8s.io/requests.storage
$ kubectl create quota quota --hard=gold.storageclass.storage.k8s.io/requests.storage=10Gi
$ kubectl create -f pvc-gold.yaml 
... created

@derekwaynecarr
Copy link
Member Author

@eparis @erinboyd @deads2k -- this is WIP and is not yet functional, opening here to track its completion for kube 1.6.

@bgrant0607 -- this was the general idea we discussed at kubecon for allowing quota to identify resources that are limited by default instead of unlimited.

@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels Nov 14, 2016
@derekwaynecarr derekwaynecarr force-pushed the quota-precious-resources branch from d7453f2 to c00857d Compare December 15, 2016 23:07
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 15, 2016
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 15, 2016
@derekwaynecarr derekwaynecarr force-pushed the quota-precious-resources branch from c00857d to 80f8d3f Compare December 19, 2016 17:11
@derekwaynecarr
Copy link
Member Author

In putting this together, it's come to my attention that we do not pass versioned configuration to admission controllers in Kubernetes today. As a result, I think I need to fix-up existing admission plug-ins first, and codify the model for how versioned config is handled before finishing this out.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 4, 2017
@derekwaynecarr derekwaynecarr force-pushed the quota-precious-resources branch from 80f8d3f to 8036a20 Compare January 9, 2017 03:06
@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/new-api size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 9, 2017
@derekwaynecarr derekwaynecarr force-pushed the quota-precious-resources branch 2 times, most recently from 9f336e0 to f2f952a Compare January 9, 2017 19:16
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 11, 2017
@derekwaynecarr derekwaynecarr force-pushed the quota-precious-resources branch from f2f952a to 0f3252b Compare January 13, 2017 16:09
@derekwaynecarr derekwaynecarr changed the title WIP: Ability to identify resources that are precious in quota Ability to have ResourceQuota configure resources limited by default Jan 13, 2017
@derekwaynecarr derekwaynecarr changed the title Ability to have ResourceQuota configure resources limited by default ResourceQuota has ability to identified default limited resources Jan 13, 2017
@derekwaynecarr derekwaynecarr changed the title ResourceQuota has ability to identified default limited resources ResourceQuota ability to support default limited resources Jan 13, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@derekwaynecarr derekwaynecarr force-pushed the quota-precious-resources branch from 0f3252b to 810ca05 Compare January 13, 2017 17:44
@derekwaynecarr derekwaynecarr removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 13, 2017
@derekwaynecarr
Copy link
Member Author

its a belated xmas miracle, the bots are all happy.

@smarterclayton @deads2k - ptal.

// the value would be "persistentvolumeclaims".
// If the resource exists in a named API group, the name must be
// fully qualified, i.e. "deployments.extensions"
APIGroupResource string `json:"apiGroupResource"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is consistent with RBAC, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

RBAC has the following:

type PolicyRule struct {
	// Verbs is a list of Verbs that apply to ALL the ResourceKinds and AttributeRestrictions contained in this rule.  VerbAll represents all kinds.
	Verbs []string

	// APIGroups is the name of the APIGroup that contains the resources.
	// If multiple API groups are specified, any action requested against one of the enumerated resources in any API group will be allowed.
	APIGroups []string
	// Resources is a list of resources this rule applies to.  ResourceAll represents all resources.
	Resources []string
	// ResourceNames is an optional white list of names that the rule applies to.  An empty set means that everything is allowed.
	ResourceNames []string

	// NonResourceURLs is a set of partial urls that a user should have access to.  *s are allowed, but only as the full, final step in the path
	// If an action is not a resource API request, then the URL is split on '/' and is checked against the NonResourceURLs to look for a match.
	// Since non-resource URLs are not namespaced, this field is only applicable for ClusterRoles referenced from a ClusterRoleBinding.
	// Rules can either apply to API resources (such as "pods" or "secrets") or non-resource URL paths (such as "/api"),  but not both.
	NonResourceURLs []string
}

It splits APIGroup from Resource. Unlike Policy, I don't think there is meaning if both are not supplied on this item. For example, I don't think we would want to support that a particular constraint applies to all resources in an APIGroup for ResourceQuota.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I'm okay with it.

@smarterclayton
Copy link
Contributor

For alpha is sufficiently compact. API looks ok to me.

}
if len(quotas) == 0 {
// if limited resources are disabled, we can just return safely when there are no quotas.
limitedResourcesDisabled := len(e.config.LimitedResources) == 0
Copy link
Contributor

Choose a reason for hiding this comment

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

if e.config must be non-nil, why do you allow a nil to be passed through the New function?

Copy link
Member Author

Choose a reason for hiding this comment

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

i modified new to allow nil, but default to empty config.

// track the cumulative set of resources that were required across all quotas
// this is needed to know if we have satisfied any constraints where consumption
// was limited by default.
requiredResourcesSet := sets.String{}
Copy link
Contributor

Choose a reason for hiding this comment

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

It took me a long time to puzzle out what this was. This is the list of resources that are restricted by quota applied to this object, right? Maybe restrictedResources?

internalClientset := internalclientset.NewForConfigOrDie(&restclient.Config{QPS: -1, Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &api.Registry.GroupOrDie(v1.GroupName).GroupVersion}})
admission, err := resourcequota.NewResourceQuota(quotainstall.NewRegistry(nil, nil), 5, admissionCh)
config := &resourcequotaapi.Configuration{}
admission, err := resourcequota.NewResourceQuota(quotainstall.NewRegistry(nil, nil), config, 5, admissionCh)
Copy link
Contributor

@deads2k deads2k Feb 16, 2017

Choose a reason for hiding this comment

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

Seems like this feature is worth an integration test.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

test added

// the value would be "persistentvolumeclaims".
// If the resource exists in a named API group, the name must be
// fully qualified, i.e. "deployments.extensions"
APIGroupResource string
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not a separate Group and Resource field?

Copy link
Member Author

Choose a reason for hiding this comment

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

i am perfectly happy to separate. it appears we lack a consensus decision on how to handle this.

see: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/kubernetes-sig-api-machinery/fzmH1gqLuOQ/73H2NJJQBQAJ

to follow the policy convention, is that APIGroup and Resource?

Copy link
Contributor

Choose a reason for hiding this comment

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

to follow the policy convention, is that APIGroup and Resource?

I'd like that.

@deads2k
Copy link
Contributor

deads2k commented Feb 16, 2017

minor comments

@derekwaynecarr
Copy link
Member Author

@deads2k -- thanks for the review pass, i will look to update.

@derekwaynecarr derekwaynecarr force-pushed the quota-precious-resources branch from 552e8e5 to 3fad0cb Compare February 18, 2017 17:10
@derekwaynecarr
Copy link
Member Author

@k8s-bot cvm gke e2e test this

@derekwaynecarr
Copy link
Member Author

@deads2k updates addressed, ptal

@deads2k
Copy link
Contributor

deads2k commented Feb 20, 2017

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

@deads2k: you can't LGTM a PR unless you are an assignee.

Details

In response to this comment:

/lgtm
/approve

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

The following people have approved this PR: deads2k, derekwaynecarr

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 20, 2017
@derekwaynecarr
Copy link
Member Author

@deads2k -- added you as an assignee, care to tag again so bot is happy?

@deads2k deads2k added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 20, 2017
@deads2k
Copy link
Contributor

deads2k commented Feb 20, 2017

@deads2k -- added you as an assignee, care to tag again so bot is happy?

Tagged, though I don't think anyone would have dinged you for fixing it up yourself.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 41421, 41440, 36765, 41722)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants