3

In Kubernetes I have a base kustomize package, and two patches to it, each patch adjusting a different aspect of the base - one for large deployment, and another to use a legacy image rather than the current one. Is there a way I can create a "combined" patch -- the one that has both changes, without copying large & legacy patch content?

- base/
- large-deployment-patch/
- legacy-image-patch/

When I tried to simply use both patches as bases in the combined patch, I get an error like this:

Error: ../legacy: id '"~G_v1_ConfigMap|~X|~P|pg-database|~S"' already used

Yuri Astrakhan
  • 8,808
  • 6
  • 63
  • 97
  • 1
    It looks like `large-deployment-patch` and `legacy-image-patch` are `overlay`s rather than `patch`es in kustomize terminology. Can you confirm? – Jamie Oct 05 '19 at 17:02
  • Assuming they are overlays, what is the base for each overlay? – Jamie Oct 05 '19 at 17:03
  • @Jamie it's a bit more complex -- one is an image label change (stored in kustomize.yaml itself), another is a patch, but they both change aspects of the same base object (stored in the base dir). In my case I actually have two more aspects that needs changing, so I end up with a dir for each combination of changes - which is very hard to manage. – Yuri Astrakhan Oct 08 '19 at 22:01

1 Answers1

3

As @Jamie mentioned in his comment, if any of the two "Patches" contains a kustomization.yaml file that include your base/ directory as a resource, it will be an overlay. Each overlay generates a copy of all the resources in your base and modify them.

If your base creates a ConfigMap called pg-database and none of your overlays modifies the name of this resource, you will end-up with two ConfigMaps called pg-database.

So to sum-up: each overlay creates a copy of the resources and you can't have two resources of the same kind with the same name in the same namespace.

It's common practice to add a namePrefix or nameSuffix transformer in your overlays to avoid collisions and give more meaningful names to your resources.

ITChap
  • 4,057
  • 1
  • 21
  • 46