One object level suggestion is you shouldn't be doing string formatting manipulation to construct valid YAML objects as part of your ops pipeline; instead, do it all with actual data structures and then just render the result. Yes, I know that Helm directly encourages text templating — it's bad and wrong.
Beyond that, this a too-long essay about a deeply poisonous and discouraging worldview. I regret having read it. At least it wasn't written by AI!