ops-itop/cmdbApi

patch service失败

annProg opened this issue · 1 comments

maclof/kubernetes-client#27

use strategic-merge-patch+json can not patch service when change service ports

# kubectl --v=7 -n dev patch service app1 --patch '{"spec":{"ports":[{"port":805,"targetPort":805}]}}'
I1119 18:30:55.204013    7361 loader.go:357] Config loaded from file /root/.kube/config
I1119 18:30:55.216967    7361 round_trippers.go:414] GET https://10.112.35.104/api/v1/namespaces/dev/services/app1
I1119 18:30:55.216990    7361 round_trippers.go:421] Request Headers:
I1119 18:30:55.217001    7361 round_trippers.go:424]     Accept: application/json
I1119 18:30:55.217010    7361 round_trippers.go:424]     User-Agent: kubectl/v1.9.5 (linux/amd64) kubernetes/f01a2bf
I1119 18:30:55.243264    7361 round_trippers.go:439] Response Status: 200 OK in 26 milliseconds
I1119 18:30:55.244290    7361 round_trippers.go:414] PATCH https://10.112.35.104/api/v1/namespaces/dev/services/app1
I1119 18:30:55.244311    7361 round_trippers.go:421] Request Headers:
I1119 18:30:55.244322    7361 round_trippers.go:424]     Accept: application/json
I1119 18:30:55.244333    7361 round_trippers.go:424]     Content-Type: application/strategic-merge-patch+json
I1119 18:30:55.244344    7361 round_trippers.go:424]     User-Agent: kubectl/v1.9.5 (linux/amd64) kubernetes/f01a2bf
I1119 18:30:55.247526    7361 round_trippers.go:439] Response Status: 422 Unprocessable Entity in 3 milliseconds
F1119 18:30:55.247793    7361 helpers.go:119] The Service "app1" is invalid: 
* spec.ports[0].name: Required value
* spec.ports[1].name: Required value

use --type merge, Content-Type is Content-Type: application/merge-patch+json, can patch successful.

# kubectl --v=7 -n dev patch service app1 --patch '{"spec":{"ports":[{"port":804,"targetPort":804}]}}' --type merge
I1119 18:28:17.370216    6169 loader.go:357] Config loaded from file /root/.kube/config
I1119 18:28:17.388940    6169 round_trippers.go:414] GET https://10.112.35.104/api/v1/namespaces/dev/services/app1
I1119 18:28:17.388971    6169 round_trippers.go:421] Request Headers:
I1119 18:28:17.388983    6169 round_trippers.go:424]     Accept: application/json
I1119 18:28:17.388994    6169 round_trippers.go:424]     User-Agent: kubectl/v1.9.5 (linux/amd64) kubernetes/f01a2bf
I1119 18:28:17.415048    6169 round_trippers.go:439] Response Status: 200 OK in 26 milliseconds
I1119 18:28:17.416141    6169 round_trippers.go:414] PATCH https://10.112.35.104/api/v1/namespaces/dev/services/app1
I1119 18:28:17.416164    6169 round_trippers.go:421] Request Headers:
I1119 18:28:17.416175    6169 round_trippers.go:424]     Accept: application/json
I1119 18:28:17.416186    6169 round_trippers.go:424]     Content-Type: application/merge-patch+json
I1119 18:28:17.416226    6169 round_trippers.go:424]     User-Agent: kubectl/v1.9.5 (linux/amd64) kubernetes/f01a2bf
I1119 18:28:17.422360    6169 round_trippers.go:439] Response Status: 200 OK in 6 milliseconds
service "app1" patched

so can we make this header configurable?

kubernetes/kubernetes#28225