Admission webhook should not reject workloads with only resource limits set #4802
Description
Report
I'm unable to create/update ScaleObjects with either CPU; memory; or both scalers, if the underlying workload assigns only resource limits and does not set any requests.
Expected Behavior
Based on Kubernetes documentation (I brought the quote below from here), users can assign only resource limits to their containers, so the ScaledObject admission webhook should also consider the resource limits during workload resources validation.
Note: If you specify a limit for a resource, but do not specify any request, and no admission-time mechanism has applied a default request for that resource, then Kubernetes copies the limit you specified and uses it as the requested value for the resource.
Actual Behavior
Workloads that only set resource limits are rejected by the admission webhook.
Steps to Reproduce the Problem
- Create a Deployment that assigns only resource limits (e.g CPU limits):
# Filename: deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: echo-server
image: jmalloc/echo-server:latest
resources:
limits:
cpu: 500m
kubectl apply -f ./deploy.yaml
- Create a ScaledObject with CPU scaler defined and points to the above Deployment:
# Filename: scaledobject.yaml
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: my-app-so
spec:
maxReplicaCount: 5
minReplicaCount: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
triggers:
- metadata:
value: "80"
metricType: Utilization
type: cpu
kubectl apply -f ./scaledobject.yaml
- Got the message from Kubernetes API Server:
admission webhook \"vscaledobject.kb.io\" denied the request: the scaledobject has a cpu trigger but the container echo-server doesn't have the cpu request defined
Logs from KEDA operator
No response
KEDA Version
2.11.1
Kubernetes Version
None
Platform
Any
Scaler Details
CPU, memory
Anything else?
No response
Metadata
Assignees
Type
Projects
Status
Done