There is a NetworkPolicy Object which I want to update during Argo's PreSync using annotation argocd.argoproj.io/hook: PreSync and update it again during PostSync using annotation argocd.argoproj.io/hook: PostSync. How to include both these operations because kustomize build will finally keep only one operation.
Asked
Active
Viewed 226 times
0
-
Can you show us what you have tried so far? – larsks Mar 02 '23 at 15:27
1 Answers
0
To make kustomize builds consider both operation presync and postsync while updating a networkpolicy object, you can use the patch field
in the kustomization.yaml
file. This allows you to specify patches that should be applied before or after the sync operation.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- networkpolicy.yaml
patches:
- path: patch-presync.yaml
target:
kind: NetworkPolicy
name: my-network-policy
options:
create: true
- path: patch-postsync.yaml
target:
kind: NetworkPolicy
name: my-network-policy
apiVersion: networking.k8s.io/v1beta1
kind: NetworkPolicy
metadata:
name: my-network-policy
spec:
ingress:
- from:
- podSelector:
matchLabels:
app.kubernetes.io/name: nginx
You can find more information in a blog by Karim Elatov , If you want to patch multiple objects then follow this doc.

Sai Chandra Gadde
- 2,242
- 1
- 3
- 15
-
Hi Sai thanks for the reply. I checked this one. Before Argo Sync when kustomize build command is run, it will create a single NetworkPolicy Yaml file with only postSync configuration. PreSync is not present that single file. – Vishwanath Joshi Mar 01 '23 at 15:30