<p>I would like to validate deployments based on custom logic before scale.
I created an admission webhook to do that, but unfortunately the scale operation is undetected by the webook.</p>
<pre><code>apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: deployment-validator
webhooks:
  - admissionReviewVersions:
      - v1
    clientConfig:
      service:
        name: example-name
        namespace: example-namespace
        path: /validate-deployment
        port: 9443
    failurePolicy: Ignore
    matchPolicy: Equivalent
    name: validation.deploy.example-domain.com
    namespaceSelector: {}
    objectSelector: {}
    rules:
      - apiGroups:
          - apps
        apiVersions:
          - v1
        operations:
          - '*'
        resources:
          - deployment
        scope: '*'
    sideEffects: None
    timeoutSeconds: 10

</code></pre>
<p>If I CREATE or UPDATE the deployment, the action is detected by the webhook server, also if I PATCH (kubectl patch ...).
Unfortunately if I use kubectl scale ..., the webhook server does not detect the action, and I'm unable to validate the request.</p>
<p>How can I resolve this issue?</p>

Miklós
<p>When you run <code>kubectl scale</code> you are not actually patching the <code>Deployment</code> resource, but you are editing a subresource named <code>Scale</code> instead.</p>
<p>This is the API doc entry of the scale call: <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#replace-scale-deployment-v1-apps" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#replace-scale-deployment-v1-apps</a></p>
<pre><code>PUT /apis/apps/v1/namespaces/{namespace}/deployments/{name}/scale
</code></pre>
<p>Also, I think you need the plural name for your resouce.
So you might have to change the rule in your admission controller like this:</p>
<pre><code>    rules:
      - apiGroups:
          - apps
        apiVersions:
          - v1
        operations:
          - '*'
        resources:
          - deployments/scale
        scope: '*'
</code></pre>
<p>and that should work.</p>
