kozmo
kozmo

Reputation: 4491

Kubernetes (OpenShift) 👉 kubectl (oc - OpenShift CLI) `patch` return the error: cannot unmarshal array into Go value of type map[string]interface {}

I try to patch a service (add port declaration):

kind: Service
apiVersion: v1
metadata:
  name: istio-ingressgateway
  namespace: istio-system
  labels:
    app: istio-ingressgateway
    istio: ingressgateway
    release: istio
spec:
  ports:
    - name: status-port
      protocol: TCP
      port: 15021
      targetPort: 15021
      nodePort: 30805
    - name: http2
      protocol: TCP
      port: 80
      targetPort: 8080
      nodePort: 32130
    - name: https
      protocol: TCP
      port: 443
      targetPort: 8443
      nodePort: 30720
    - name: tls
      protocol: TCP
      port: 15443
      targetPort: 15443
      nodePort: 31202
  selector:
    app: istio-ingressgateway
    istio: ingressgateway
  clusterIP: 172.30.62.239
  type: LoadBalancer
  sessionAffinity: None
  externalTrafficPolicy: Cluster
status:
  loadBalancer: {}

using kubectl or oc patch-command

kubectl patch service istio-ingressgateway -n istio-system --patch - <<EOF
spec:
  ports:
    - name: gw
      protocol: TCP
      port: 3080
      targetPort: 3080
      nodePort: 31230
EOF

, but get an error

Error from server (BadRequest): json: cannot unmarshal array into Go value of type map[string]interface {}

👉🏻 under the hood, k8s/openshift use GoLang to parse yaml 👉 I tried to find same solutions in go - failed...

What's wrong?

Upvotes: 1

Views: 702

Answers (1)

dante
dante

Reputation: 46

try to use json to patch

oc patch service/simple-server -p \
'{ "spec": { "ports": [ { "name": "gw", "protocol": "TCP", "port": 1234,"targetPort": 1234 } ] } }'

Upvotes: 3

Related Questions