Local Testing (No GPU Required)

Test the CastSlice webhook mutation logic on a local KinD or Minikube cluster with no physical NVIDIA GPU. You'll mock GPU capacity on the node and verify that the annotation-triggered rewrite works end-to-end.

ℹ️

This guide requires CastSlice to already be installed. If you haven't done that yet, follow the Getting Started guide first.

Step 1 — Mock a Node with nvidia.com/gpu capacity

Kubernetes does not allow kubectl patch to add arbitrary extended resources to status.capacity directly because the status sub-resource is guarded by the API server. The standard workaround is to PATCH the node directly via the raw API through kubectl proxy.

⚠️

This modifies node status in your cluster. Only do this in a development or local cluster — never in production.

1
Find your node name and start kubectl proxy
bash
# Get the first (or only) node name $ NODE=$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}') $ echo "Patching node: $NODE" Patching node: kind-control-plane # Start proxy in background, save PID $ kubectl proxy & $ PROXY_PID=$! Starting to serve on 127.0.0.1:8001
2
Patch the node status to add fake GPU capacity
bash
$ curl -s -X PATCH \ -H "Content-Type: application/json-patch+json" \ "http://localhost:8001/api/v1/nodes/${NODE}/status" \ --data '[ {"op":"add","path":"/status/capacity/nvidia.com~1gpu","value":"4"}, {"op":"add","path":"/status/allocatable/nvidia.com~1gpu","value":"4"} ]' # Stop the proxy $ kill $PROXY_PID

After this, the node advertises 4 fake nvidia.com/gpu resources. Kubernetes will schedule Pods requesting GPU resources against this node.

3
Verify fake capacity is visible
bash
$ kubectl describe node ${NODE} | grep -A 8 "Capacity:" Capacity: nvidia.com/gpu: 4 cpu: 8 memory: 16316112Ki pods: 110 Allocatable: nvidia.com/gpu: 4
Node now reports 4 × nvidia.com/gpu available

Step 2 — Apply the Test Pod

The repository includes a pre-built test Pod at docs/test-pod.yaml that requests a GPU and includes the castops.io/optimize: "true" annotation.

4
Create the test Pod
bash
$ kubectl apply -f docs/test-pod.yaml pod/gpu-test-pod created

The Pod spec requests nvidia.com/gpu: 1 and has the opt-in annotation. CastSlice intercepts the CREATE admission request and rewrites it before it is persisted.

Step 3 — Verify the Mutation

Inspect the actual resource spec that was stored — this is what CastSlice wrote, not what you applied.

5
Check the stored resource limits
bash
$ kubectl get pod gpu-test-pod \ -o jsonpath='{.spec.containers[0].resources}' | jq . { "limits": { "nvidia.com/gpu-shared": "1", "memory": "4Gi" }, "requests": { "memory": "4Gi" } }
nvidia.com/gpu is gone — nvidia.com/gpu-shared: 1 took its place

Mutation confirmed. The webhook intercepted the CREATE request, detected the opt-in annotation, and rewrote the resource limits via JSON Patch before the Pod was persisted to etcd.

Troubleshooting

Pod stays Pending after apply

If the fake node doesn’t also have the nvidia.com/gpu-shared resource, the Pod won’t be schedulable (it’s waiting for a resource that doesn’t exist on any node). For purely testing webhook mutation, you can check the stored spec immediately after kubectl apply — the Pod doesn’t need to reach Running state to verify the mutation happened.

bash — check webhook logs if mutation didn't happen
$ kubectl logs -n cast-slice deploy/cast-slice

Webhook is not mutating

Check that:

curl: (7) Failed to connect to localhost:8001

kubectl proxy may have already been killed or the port is different. Re-run kubectl proxy & and check the port it reports.