It’s been a while since I blogged about something tech related, but I had some
free time today.
Recently, I’ve been trying to refactor an internal Spotify deployment tool my
team built and maintains. This deployment tool takes Kubernetes (k8s) YAML
manifests, changes them, and essentially runs
kubectl apply. We add metadata
to the k8s manifests like labels.
Right now this tool receives the input YAML as strings, converts them to
Jackson ObjectNodes, and manipulates those ObjectNodes. The disadvantage of
this is that there’s no k8s type-safety. We might accidentally add a field to a
Deployment that isn’t valid or remove something from a Service that’s required.
My refactor uses upstream k8s model classes from kubernetes-client/java
which are themselves generated from the official Swagger spec. Here’s a
helpful Yaml utility class that deserializes YAML strings into concrete classes
and can also serialize them back into YAML strings. So helpful.
Unfortunately, there’s some bugs in the YAML (de)serialization that prevent me
from finishing this effort.
Nonetheless, it’ll be much nicer to change k8s resources in a type-safe way
instead of parsing and rewriting raw YAML strings.