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

Fix parsing the media type in GameServerAllocation #1749

Merged

Conversation

aLekSer
Copy link
Collaborator

@aLekSer aLekSer commented Aug 13, 2020

Add a call to filter out optional parameters send in an HTTP header.

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespace from that line:

/kind breaking

/kind bug

What this PR does / Why we need it:
There are parameters like charset which would coexist in Content-Type header. That's lead runtime.SerializerInfoForMediaType to fail, because unexpected parameter was provided.

Which issue(s) this PR fixes:

Closes #1748 .

Special notes for your reviewer:
Thanks @markmandel for providing the solution in the issue comment

Steps to reproduce:
Proof of the fix:

export APISERVER=localhost:8001
$ kubectl proxy &
$ curl -X POST -H 'Content-Type: application/json; charset=utf-8' --data '
{
   "apiVersion": "allocation.agones.dev/v1",
   "kind": "GameServerAllocation",
   "spec": {
      "required": {
         "matchLabels": {
            "agones.dev/fleet": "simple-udp"
         }
      }
   }
}
' ${APISERVER}/apis/allocation.agones.dev/v1/namespaces/default/gameserverallocations
{"kind":"GameServerAllocation","apiVersion":"allocation.agones.dev/v1","metadata":{"name":"simple-udp-xv6d5-g4zsd","namespace":"default","creationTimestamp":"2020-08-13T09:05:15Z"},"spec":{"multiClusterSetting":{"policySelector":{}},"required":{"matchLabels":{"agones.dev/fleet":"simple-udp"}},"scheduling":"Packed","metadata":{}},"status":{"state":"Allocated","gameServerName":"simple-udp-xv6d5-g4zsd","ports":[{"name":"default","port":7870}],"address":"34.82.245.95","nodeName":"gke-test-cluster-default-dfffabe4-t97g"}}

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 45774ee4-5914-41d3-9c79-d5c00056d229

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/1749/head:pr_1749 && git checkout pr_1749
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.8.0-a3bd965

info, ok := k8sruntime.SerializerInfoForMediaType(mediaTypes, r.Header.Get("Content-Type"))
mt, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return gsa, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we errors.Wrapf(....) this error message before passing it back out, so we can capture context?

Outside of that, this looks good to go.

Add a call to filter out optional parameters send in an HTTP header.
@aLekSer aLekSer force-pushed the fix/parse-allocation-media-type branch from a3bd965 to ac94465 Compare August 13, 2020 17:00
@aLekSer
Copy link
Collaborator Author

aLekSer commented Aug 13, 2020

Tested latest version:

 curl -X POST -H 'Content-Type: application/json; charset=utf-8' --data '
{
   "apiVersion": "allocation.agones.dev/v1",
   "kind": "GameServerAllocation",
   "spec": {
      "required": {
         "matchLabels": {
            "agones.dev/fleet": "simple-udp"
         }
      }
   }
}
' ${APISERVER}/apis/allocation.agones.dev/v1/namespaces/default/gameserverallocations
{"kind":"GameServerAllocation","apiVersion":"allocation.agones.dev/v1","metadata":{"name":"simple-udp-pb8kx-v4fq8","namespace":"default","creationTimestamp":"2020-08-13T17:11:29Z"},"spec":{"multiClusterSetting":{"policySelector":{}},"required":{"matchLabels":{"agones.dev/fleet":"simple-udp"}},"scheduling":"Packed","metadata":{}},"status":{"state":"Allocated","gameServerName":"simple-udp-pb8kx-v4fq8","ports":[{"name":"default","port":7042}],"address":"34.82.245.95","nodeName":"gke-test-cluster-default-dfffabe4-t97g"}}

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a61ac52f-5d59-4072-9e53-0f0ddf02e5d9

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/googleforgames/agones.git pull/1749/head:pr_1749 && git checkout pr_1749
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.8.0-ac94465

info, ok := k8sruntime.SerializerInfoForMediaType(mediaTypes, r.Header.Get("Content-Type"))
mt, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return gsa, errors.Wrap(err, "error parsing mediatype from a request header")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic!

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aLekSer, markmandel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@markmandel markmandel added area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc kind/bug These are bugs. and removed approved labels Aug 13, 2020
@markmandel markmandel added this to the 1.8.0 milestone Aug 13, 2020
@markmandel markmandel merged commit d343d98 into googleforgames:master Aug 13, 2020
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Add a call to filter out optional parameters send in an HTTP header.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc cla: yes kind/bug These are bugs. lgtm size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content-Type: application/json; charset=utf-8 results in "Could not find deserializer"
5 participants