title: Openshift/Kubernetes - oc patch all elements of array
body: <p>I'm trying to convert an openshift service from <code>LoadBalancer</code> to <code>ClusterIP</code> using the <code>oc patch</code> command, which requires removing a few elements:</p>
  
  <pre><code>oc -n default patch svc router --type json -p '[\
  { "op" : "remove", "path" : "/spec/externalIPs" },\
  { "op" : "remove", "path" : "/spec/ports/0/nodePort" },\
  { "op" : "replace", "path" : "/spec/type", "value" : "ClusterIP" }]'
  </code></pre>
  
  <p>This works fine for services with a single <code>.spec.ports</code> entry, however when there are multiple, this fails to remove them all, and the patch operation fails.</p>
  
  <p>Specifically, it fails in this part <code>"op" : "remove", "path" : "/spec/ports/0/nodePort"</code> since I'm only specifying index 0.</p>
  
  <p><strong>What would be the proper syntax to patch all elements of the <code>.spec.ports</code> array?</strong> </p>
  
  <p>What kind of path language is this? It seems related to <code>yamlpath</code> but it only accepts a limited form of forward slash notation.</p>
  
  <p>I've tried multiple variants, which always ends with an error message like <code>Error from server: jsonpatch remove operation does not apply: doc is missing path: /spec/ports/*/nodePort</code>.</p>
  
  <p>One possible solution would be to explicitly remove each array index, up to some sufficiently high value, but that's awful.</p>
  
  <pre><code>oc -n default patch svc router --type json -p '[\
  { "op" : "remove", "path" : "/spec/externalIPs" },\
  { "op" : "remove", "path" : "/spec/ports/0/nodePort" },\
  { "op" : "remove", "path" : "/spec/ports/1/nodePort" },\
  { "op" : "remove", "path" : "/spec/ports/2/nodePort" },\
  { "op" : "remove", "path" : "/spec/ports/3/nodePort" },\
  ...
  { "op" : "remove", "path" : "/spec/ports/99/nodePort" },\
  { "op" : "replace", "path" : "/spec/type", "value" : "ClusterIP" }]'
  </code></pre>
  
  <p>Sample service YAML:</p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    annotations:
      prometheus.openshift.io/password: OhsPYf5Ae3
      prometheus.openshift.io/username: admin
      service.alpha.openshift.io/serving-cert-generation-error: secret/router-certs
        references serviceUID , which does not match 9ce61b57-9f35-11e9-af68-0050569ec26d
      service.alpha.openshift.io/serving-cert-generation-error-num: "10"
      service.alpha.openshift.io/serving-cert-secret-name: router-certs
    creationTimestamp: 2019-07-05T15:00:22Z
    labels:
      bah: bah
      router: router
    name: router
    namespace: default
    resourceVersion: "56450329"
    selfLink: /api/v1/namespaces/default/services/router
    uid: 9ce61b57-9f35-11e9-af68-0050569ec26d
  spec:
    clusterIP: 172.31.122.90
    externalIPs:
    - 10.66.11.44
    - 10.66.11.41
    externalTrafficPolicy: Cluster
    ports:
    - name: 80-tcp
      nodePort: 31380
      port: 80
      protocol: TCP
      targetPort: 80
    - name: 443-tcp
      nodePort: 30816
      port: 443
      protocol: TCP
      targetPort: 443
    - name: 1936-tcp
      nodePort: 32677
      port: 1936
      protocol: TCP
      targetPort: 1936
    selector:
      router: router
    sessionAffinity: None
    type: LoadBalancer
  status:
    loadBalancer:
      ingress:
      - ip: 10.66.11.41
  </code></pre>