digitalocean / clusterlint

A best practices checker for Kubernetes clusters. 🤠
Apache License 2.0
542 stars 45 forks source link

Fix reference to loop variables in doks admission controller checks #90

Closed SpencerSharkey closed 4 years ago

SpencerSharkey commented 4 years ago

The admission controller checks for the DOKS suite were returning errors for webhook configurations that were indeed correct. You can reproduce it with a cluster w/ multiple namespaces and admission webhook configs.

Turns out, it was reporting the wrong kube object metadata due to using a reference to a range loop value, which will produce weird references past the loop iteration's lifetime (in this case, it returned object data from other webhooks).

This fix clones the data before interacting with it in each loop block.

MattIPv4 commented 4 years ago

Hey, @SpencerSharkey - Thanks a ton for this sweet PR! 😄

Would you please shoot me an email when you get a chance? mcowley at digitalocean dot com 🎉