0

I would like to create component reused in many deployments. It has monitoring sidecar same for all applications. My problem is that I would like to apply strategic merge patch from this component but it only works when I'm using name of specific deployment

#------deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-deploy
spec:
  template:
    metadata:
      labels:
        app: sample-app
    spec:
      containers:
      - name: sample-container
#--------kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yaml

components:
- ../../../.k8s/components/monitor-sidecar
#------kustomization.yaml (component)
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

patches:
- deployment-sidecar.yaml
#-------deployment-sidecar.yaml
apiVersion: apps/v1
kind: Deployment
# metadata:
#   name: sample-deploy <-I have to uncoment this but it attach component to one deployment
spec:
  template:
    spec:
      containers:
      - name: monitor-sidecar
        image: MONITOR-SIDECAR.IMG
   

When I skip the name (name: sample-deploy in examle) I have an error "missing metadata.name in object". How can I create generic component without attaching it to specific deployment name? I would like to init component when it is used and not define such things in definision.

dnf
  • 1,659
  • 2
  • 16
  • 29
  • Can you please add a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) so community can try and help you out? Also which `kustomize` version is used? – moonkotte Dec 01 '21 at 16:28
  • 1
    I have updated the sample - I hope it is clear now? – dnf Dec 01 '21 at 18:38

1 Answers1

1

I missed the target section - with this it works. I still have to use some name in patch but it is ignored

- path: patch.yaml
  target:
    kind: Deployment
dnf
  • 1,659
  • 2
  • 16
  • 29