kubeslice / worker-operator

Kubeslice Worker Operator Opensource Repository: The KubeSlice Worker Operator is a Kubernetes operator that manages the lifecycle of KubeSlice worker clusters.
Apache License 2.0
58 stars 19 forks source link

fix(): Initialize labels field as an empty map #267

Closed Rahul-D78 closed 1 year ago

Rahul-D78 commented 1 year ago

This PR fixes nil pointer dereference issues if label field for object is empty.

Issue was observed with the following error message: Error from server (InternalError): error when creating "/private/var/folders/79/1qpw4sq56h93prvrqhmj6p7m0000gn/T/1ae182ebc8f383cb5affcef7da4a38fa/resource.yaml": Internal error occurred: failed calling webhook "webhook.kubeslice.io": failed to call webhook: Post "https://kubeslice-webhook-service.kubeslice-system.svc:443/mutate-webhook?timeout=10s": EOF

This was due to trying to de-reference a nil object in the webhook code. Fixes issues with pod,deployment,statefulset and daemonset objects having no labels (i.e nil Label object)