Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PATCH verb (and add Content-Type header for all PATCH requests) #27

Merged
merged 1 commit into from
Apr 13, 2018

Conversation

leonboot
Copy link
Contributor

@leonboot leonboot commented Apr 13, 2018

Kubernetes supports patching objects. A partial model may be presented to the API, with only the data that should be updated. For instance: change the image for the pod spec of a Deployment to perform a rolling update.
The only catch for PATCH requests is that the Content-Type request header needs to be set to an exotic MIME type (application/strategic-merge-patch+json). This is done in the Client::sendRequest() method if $method equals PATCH.

@maclof
Copy link
Owner

maclof commented Apr 13, 2018

Very nice mate, thank you! 👍

@maclof maclof merged commit 4aa815e into maclof:master Apr 13, 2018
@annProg
Copy link
Contributor

annProg commented Nov 19, 2018

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?

@leonboot leonboot deleted the feature/patch-support branch June 11, 2021 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants