<p>I am new to kustomize and trying to figure out how to patch my ingress that is running via OpenShift Container Platform.</p>
<p>The base config works fine and the overlay was working until I introduced my ingress overlay patch. For reference the patch-service overlay does work so I am pretty sure my structure and links are all good, however the error I get on my project when syncronising to OpenShift (via ArgoCD) is:</p>
<p><code>one or more objects failed to apply, reason: Ingress in version &quot;v1&quot; cannot be handled as a Ingress: json: cannot unmarshal number into Go struct field IngressServiceBackend.spec.defaultBackend.service.port of type v1.ServiceBackendPort (retried 5 times).</code></p>
<p><strong>Application Repo Structure</strong></p>
<pre><code>|mssql-example
├── base
│   ├── deployment.yaml
│   ├── ingress.yaml
│   ├── kustomization.yaml
│   ├── storage.yaml
│   └── service.yaml
└── overlays
    ├── nprd-dev
    │   ├── **patch-ingress.yaml**
    │   ├── patch-service.yaml
    │   └── kustomization.yaml
    ├── nprd-sit
    │   ├── patch-ingress.yaml
    │   ├── patch-service.yaml
    │   └── kustomization.yaml
    └── nprd-uat
    │   ├── patch-ingress.yaml
    │   ├── patch-service.yaml
    │   └── kustomization.yaml
</code></pre>
<p><strong>mssql-example\base\ingress.yaml</strong></p>
<pre><code>---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: mssql-example-adc
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: '1433'
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
spec:
  defaultBackend:
    service:
      name: mssql-service
      port:
        number: 31433
</code></pre>
<p><strong>mssql-example\overlays\nprd-dev\kustomization.yaml</strong></p>
<pre><code>---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ops-example-dev
resources:
  - ../../base
patches:
  - path: patch-ingress.yaml
    target:
      kind: Ingress
      version: v1
      name: mssql-example-adc
  - path: patch-service.yaml
    target:
      kind: Service
      version: v1
      name: mssql-example-tcp
</code></pre>
<p><strong>mssql-example\overlays\nprd-dev\patch-ingress.yaml</strong></p>
<pre><code>---
- op: replace
  path: /metadata/name
  value: mssql-example-ingress-dev
- op: replace
  path: /spec/defaultBackend/service/port
  value: 31434
</code></pre>
<p>I think my path may be wrong, but I can't seem to work out how to correctly identify the replacement path for the spec when it is defaultBackend. I tried the path as /spec/defaultBackend/0/service/port and /spec/0/defaultBackend/service/port incase it was an array.</p>

Daryl
<p>The error is telling you everything you need to know:</p>
<pre><code>cannot unmarshal number into Go struct field
</code></pre>
<p>First, look at the format of your initial Ingress manifest:</p>
<pre><code>kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: mssql-example-adc
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: '1433'
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
spec:
  defaultBackend:
    service:
      name: mssql-service
      port:
        number: 31433
</code></pre>
<p>Pay particular attention to the structure of <code>spec.defaultBackend.service.port</code>.</p>
<p>Now, look at the output generated by your patch:</p>
<pre><code>$ kustomize build
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: &quot;1433&quot;
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
  name: mssql-example-ingress-dev
spec:
  defaultBackend:
    service:
      name: mssql-service
      port: 31434
</code></pre>
<p>Do you see the difference? You've replaced a structured value:</p>
<pre><code>port:
  number: 31433
</code></pre>
<p>With an integer:</p>
<pre><code>port: 31434
</code></pre>
<p>Just update your patch to target <code>...service/port/number</code> instead:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ingress.yaml

patches:
  - target:
      name: mssql-example-adc
    patch: |
      - op: replace
        path: /metadata/name
        value: mssql-example-ingress-dev
      - op: replace
        path: /spec/defaultBackend/service/port/number
        value: 31434
</code></pre>
<p>Which results in:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: &quot;1433&quot;
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
  name: mssql-example-ingress-dev
spec:
  defaultBackend:
    service:
      name: mssql-service
      port:
        number: 31434
</code></pre>
