Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the order in which the patches are defined matter? #727

Closed
sheldonkwok opened this issue Jan 25, 2019 · 5 comments
Closed

Does the order in which the patches are defined matter? #727

sheldonkwok opened this issue Jan 25, 2019 · 5 comments

Comments

@sheldonkwok
Copy link

I'm trying to create an overrides patch to be applied last. It works a majority of the time but sometimes fails. This is leading me to believe that patches are not applied in order.

@Liujingfang1
Copy link
Contributor

@sheldonkwok The patches are not applied in order. If there are several patches for the same object and one of the patch need to be applied last, this can be achieved by organizing the patches into different base/overlays. The patch to be applied last is put in an overlay while other patches are put in a base.

@sheldonkwok
Copy link
Author

Thank you!

@monopole
Copy link
Contributor

FWIW, order now maintained within particular kustomizations - so it could matter.
#1154

@gdoctor
Copy link

gdoctor commented Feb 17, 2021

What disadvantage(s) would applying the patches in order have?

The scenario I am trying to implement is:

  1. Update the name of my deployment resource from busybox to busybox-2.
  2. After updating the name, I want apply a patch to the newly named resource busybox-2.

If the patches are applied in a "random" order, the second patch would fail if applied prior to #1.

@monopole
Copy link
Contributor

There are two notions of ordering.

First, there's an implicit ordering in a depth-first traversal of overlays and bases. A base is always "inflated" before being considered in an overlay, so patches at the bottom are applied first. This is what one would expect.

Second, in a given kustomization file, there are list fields describing patches

  • patchesStrategicMerge
  • patchesJson6902
  • patches

For the latter two fields, it's simple: patchesJson6902[0] is applied before patchesJson6902[1], likewise for patches.

In the case of patchesStrategicMerge, the patches necessarily self-identify their target, so if one wants to patch a deployment named Bob, the patch has to effectively be a partial resource declaration describing a deployment named Bob.

If there are multiple patches targeting a deployment named Bob in one kust file, they are applied to each other, in the given order (i.e. patch 1 is applied to patch 0, then patch 2 is applied to the result of that, etc.), before being applied to the target as one patch.

Order matters, because, for example, one patch could insert into a pod's container list, while another patch could replace the pod's container list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants