<p>Here is my ingress.yaml file that I'm trying to patch.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: notesapp-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
    cert-manager.io/cluster-issuer: letsencrypt
    nginx.ingress.kubernetes.io/proxy-body-size: 100m
    cert-manager.io/issue-temporary-certificate: &quot;true&quot;
    acme.cert-manager.io/http01-edit-in-place: &quot;true&quot;
spec:
  tls:
  - hosts:
    - notesapp.plan.com
    secretName: tls-secret
  rules:
  - host: notesapp.plan.com
    http: 
        paths: 
        - backend:
            service:
              name: notesapp-service
              port: 
                  number: 4000
          path: /
          pathType: Prefix 
</code></pre>
<p>I want to patch <strong>spec.tls[0].hosts</strong> url to custom url and patched like following.
Here is ingress-patch.yaml file.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: notesapp-ingress
  namespace: default
spec:
  tls:
  - hosts:
    - staging.notesapp.plan.com
  rules:
    - host: staging.notesapp.plan.com
</code></pre>
<p>But after flux reconciled this patch, I see this error.</p>
<p>Here, Look.</p>
<p><strong>kubectl describe ingress notesapp-ingress</strong></p>
<pre><code>Events:
  Type     Reason     Age                From                       Message
  ----     ------     ----               ----                       -------
  Warning  BadConfig  54m (x2 over 55m)  cert-manager-ingress-shim  Skipped a TLS block: spec.tls[0].secretName: Required value
  Normal   Sync       54m (x2 over 55m)  nginx-ingress-controller   Scheduled for sync
</code></pre>
<p>It looks like spec.tls[0] element was completely replaced with my patch instead of patching only spec.tls[0].hosts.
How can I patch only spec.tls[0].hosts?</p>
<p><strong>The problem:</strong>
Imagine there are many other key-values in spec.tls[0] object(just like when I want to patch spec.rules[0].host). Then it would cause code duplication.
For example, when I patch spec.rules[0].host value, I have to add this code, where it's not necessary for me.</p>
<pre><code>   http: 
    paths: 
    - backend:
        service:
          name: notesapp-service
          port: 
              number: 4000
      path: /
      pathType: Prefix 
</code></pre>

Alex Pankratov
<p>You are currently replacing the list and not only a single item.</p>
<p>you can use the patch replace operation to target list item replacement, be careful when mixing with other operations like delete or add as index can change in such szenarios!</p>
<pre class="lang-yaml prettyprint-override"><code>---
# yaml-language-server: $schema=https://json.schemastore.org/kustomization
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ingress.yaml
patches:
  - patch: |
      - op: replace
        path: /spec/tls/0/hosts/0
        value: staging.notesapp.plan.com
      - op: replace
        path: /spec/rules/0/host
        value: staging.notesapp.plan.com
    target:
      kind: Ingress
      version: v1
      name: notesapp-ingress
</code></pre>
<p>As flux kustomization is using kustomize under the hood you can add this to a flux kustomization aswel.</p>
