tumblr / k8s-sidecar-injector

Kubernetes sidecar injection service
Apache License 2.0
345 stars 75 forks source link

Adding sidecar configuration versioning and inheritance #36

Closed byxorna closed 4 years ago

byxorna commented 4 years ago

What and why?

We add 2 features to the sidecar injector to make use at scale more ergonomic. 1) versioned configurations and 2) inheritance.

Versioning

We found ourselves suffixing the names of sidecars with versioning information, so we could make improvements to sidecars without breaking legacy consumers of a given sidecar. For example, we would name configs name: some-sidecar-v3. To codify this behavior without changing the request interface, we add support for versioned sidecar configurations, similar to how Docker images work.

By changing nothing in your configs, each sidecar configuration now has a Version() which is derived by splitting off the last field after :. By default, this is latest. Here are some examples of name: fields, and the derived version.

This change allows you to maintain versioned configs, as well as "symlink" consumers to the latest version of a sidecar, via :latest.

Inheritance

In addition to versioning, we have found that a lot of our sidecar configurations are actually quite similar, and tend to have only a few differences. This brought us to build inheritance functionality into the configs. By introducing an inherits: field to configs loaded from disk (not ConfigMaps!), we support a config using a base, and merging in any fields from the child as necessary.

Note: some (most) fields in the config format are sets, so we must perform merging in a manner that provides set uniqueness by name field.

For example, a config like the following would load another.yaml, and then add 2 env vars to it. If EXISTING_VAR exists in another.yaml, it will be replaced. NEW_VAR, if not appearing in the env list, will be appended. All configs referenced via inherits: are relative to the directory of the parent file, and cannot traverse upwards in the directory.

name: example:v1
inherits: another.yaml
env:
- name: EXISTING_VAR
  value: overridden
- name: NEW_VAR
  value: new

Testing Steps

Reviewers

Required reviewers: @byxorna Request reviews from other people you want to review this PR in the "Reviewers" section on the right.

:warning: this PR must have at least 2 thumbs from the MAINTAINERS.md of the project before merging!