Can I limit the number of my own custom resources that can be created with a ResourceQuota?

6/5/2019

If I have a custom resource definition like this:

$ kubectl get crd unifiedpushservers.push.aerogear.org
NAME                                   CREATED AT
unifiedpushservers.push.aerogear.org   2019-06-05T13:39:23Z

Is it possible to create a ResourceQuota that would limit the count of this type of custom resource to 1, refusing attempts to create additional ones?

Here's what I've tried so far:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: unifiedpushservers-limit
spec:
  hard:
    count/unifiedpushservers.push.aerogear.org: 1

While this get accepted and created, it seems like the counting doesn't work and I'm able to create more than one instance.


Edit: If I quote the integer value of the field in the spec, like this:

apiVersion: v1
kind: ResourceQuota
metadata:
  name: unifiedpushservers-limit
spec:
  hard:
    count/unifiedpushservers.push.aerogear.org: "1"

then I get the following error message when trying to create even one instance:

Error from server (Forbidden): error when creating "./deploy/crds/push_v1alpha1_unifiedpushserver_cr.yaml": unifiedpushservers.push.aerogear.org "example-unifiedpushserver" is forbidden: status unknown for quota: unifiedpushservers-limit

That feels like progress, but I might be getting further away, I'm not sure.

Also, I should mention that I'm trying this on an OpenShift v3.11 cluster, which returns the following Kubernetes version info:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.0+d4cacc0", GitCommit:"d4cacc0", GitTreeState:"clean", BuildDate:"2018-10-10T16:38:01Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.0+d4cacc0", GitCommit:"d4cacc0", GitTreeState:"clean", BuildDate:"2018-11-09T15:12:26Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
-- Gerard Ryan
kubernetes
openshift

1 Answer

6/20/2019

Since kubernetes 1.15 Object count quota is now supported for namespaced custom resources using the count/<resource>.<group> syntax

For example, to create a quota on a widgets custom resource in the example.com API group, use count/widgets.example.com.

object-count-quota

-- Suresh Vishnoi
Source: StackOverflow