<p>I have a use case where I want to apply different default memory and CPU for containers running with low priority class attached. I have followed the <a href="https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/" rel="nofollow noreferrer">documentation</a> but it applies on namespace level and hence on all the containers in namespace, I want it to make it conditional if container is having priority class then different limitrange object should get applied?</p>

<p>I have tried </p>

<pre><code>limitRangeList:
  - name: image-builder
    spec:
      limits:
        - default:
            cpu: 200m
            memory: 1Gi
          defaultRequest:
            cpu: 200m
            memory: 1Gi
          type: Container
      scopeSelector:
        matchExpressions:
          - operator: In
            scopeName: PriorityClass
            values: ["imagebuild-priority"]

  - name: default
    spec:
      limits:
      - default:
          cpu: {{ limitrange_default_limits_cpu }}
          memory: {{ limitrange_default_limits_memory }}
        defaultRequest:
          cpu: {{ limitrange_default_requests_cpu }}
          memory: {{ limitrange_default_requests_memory }}
        type: Container
</code></pre>

prashant
<p>Looking at the API reference (<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#limitrangeitem-v1-core" rel="nofollow noreferrer">limitrangeitem</a>, <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#limitrangespec-v1-core" rel="nofollow noreferrer">limitrangespec</a>), it looks like you can't apply a limit range to a subset of Pods in a namespace.</p>

<p>I would recommend you look at <a href="https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/" rel="nofollow noreferrer">admission webhooks</a> instead. As specified in the documentation:</p>

<blockquote>
  <p>Mutating admission Webhooks [...] can modify objects
  sent to the API server to enforce custom defaults.</p>
</blockquote>

<p>What you can do is make a mutating admission webhook that intercepts all Pod creations and applies default limits and requests based on the labels specified in the Pod.</p>
