Version: 5.3

Profiles: Strategic Merge

Strategic Merge patches are a way to perform specific overrides to the configuration without having to create a completely separate config file. They are very similar to merge patches and kubernetes strategic patches with the distinct difference that special keys will be merged differently as in a standard merge patch. Especially changes to a single deployment are easier to realize with a strategic merge patch.

Example

Strategic Merge patches are ideal for reflecting changes between different environments, e.g. dev, staging and production.

images:
backend:
image: john/devbackend
backend-debugger:
image: john/debugger
deployments:
- name: backend
helm:
componentChart: true
values:
service:
ports:
- port: 3000
containers:
- image: john/devbackend
- image: john/debugger
- name: untouched-deployment
helm:
componentChart: true
values:
containers:
- image: untouched/deployment
profiles:
- name: production
strategicMerge:
images:
# Change the backend image
backend:
image: john/prodbackend
# Delete the backend-debugger image
backend-debugger: null
# Override backend deployment and leave others
deployments:
- name: backend
helm:
values:
containers:
- image: john/prodbackend

Explanation:

  • The above example defines 1 profile: production
  • When using the profile production, the config is merged with the given strategic merge patch at profiles[0].strategicMerge.
  • Strategic Merge patches follow the same rules as merge patches, but are merged for special keys differently:
    • Array items will mostly be merged instead of replaced (depends on the key). For example, if you define an deployments array in a strategic merge patch, the array items will be matched by name and added to the array instead of replacing the complete deployments section.
  • The resulting config used in-memory when the profile production is used would look like this (you can check via devspace print -p production):
# In-Memory Config After Applying Merge Patches For Profile `production`
images:
backend:
image: john/prodbackend
deployments:
- name: backend
helm:
componentChart: true
values:
containers:
- image: john/prodbackend
service:
ports:
- port: 3000
- name: untouched-deployment
helm:
componentChart: true
values:
containers:
- image: untouched/deployment