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

Change default metadata endpoint handling #49

Merged

Conversation

mmlb
Copy link
Contributor

@mmlb mmlb commented Nov 5, 2020

Description

Change the handling the /metadata endpoint so the data returned is of the same content as the /meta-data EC2 style endpoint.

Why is this needed

Hegel is meant as a replacement for what is used in EM Production today (Kant). The response from /metadata and /meta-data Kant returns is the same content. Its also arguably confusing to have 2 similarly named endpoints return very different data. This confusion is in part due to not having an Instance object yet expecting instance data somewhere. This should be cleaned up/made to make sense by tinkerbell/proposals#25.

How Has This Been Tested?

Unit tests still pass.

How are existing users impacted? What migration steps/scripts do we need?

This is a bc-break. If any users were using the /metadata endpoint in its default configuration their workflow would be broken. I'd like to wait and see if thats the case before prematurely having any workarounds.

@mmlb mmlb added the breaking-change Denotes a PR that introduces potentially breaking changes that require user action. label Nov 5, 2020
@mmlb mmlb requested review from kqdeng and a team November 5, 2020 18:30
@mmlb mmlb force-pushed the change-default-metadata-endpoint-handling branch 2 times, most recently from 41a4be5 to a132fc1 Compare November 5, 2020 18:31
@codecov
Copy link

codecov bot commented Nov 5, 2020

Codecov Report

Merging #49 (4970c17) into master (0cec86e) will increase coverage by 0.45%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #49      +/-   ##
==========================================
+ Coverage   23.95%   24.40%   +0.45%     
==========================================
  Files           5        5              
  Lines         501      504       +3     
==========================================
+ Hits          120      123       +3     
  Misses        359      359              
  Partials       22       22              
Impacted Files Coverage Δ
http_server.go 0.00% <0.00%> (ø)
mock.go 72.22% <ø> (ø)
main.go 9.00% <38.46%> (+2.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0cec86e...4970c17. Read the comment docs.

main.go Outdated
return errors.Wrap(err, "error in parsing custom endpoints")
err = errors.Wrap(err, "error in parsing custom endpoints")
logger.Fatal(err)
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are both Fatal and panic used here? I thought fatal already exits the program?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, thats left over from when I copy/pasted. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, PTAL

defer os.Setenv("CUSTOM_ENDPOINTS", customEndpoints)
os.Setenv("CUSTOM_ENDPOINTS", `{"/metadata":".metadata.instance","/components":".metadata.components","/userdata":".metadata.userdata"}`)

customEndPoints := map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

super nitpicky i know, but can you lower case the the p here (customEndpoints)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, PTAL

status: 404,
error: "error in parsing custom endpoints: invalid character ':' after top-level value",
json: tinkerbellDataModel,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the reasoning for removing these two cases?
shouldn't we have a case that tests the default? and the second one is for covering the bases of all the possible invalid envvar formats

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had originally done the CUSTOM_ENDPOINTS parsing in func main() and so removed it. But I didn't want to affect codecoverage too much so put it behind the func we have now. But I forgot to bring this test back in. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, PTAL. I left the default one out as thats done in func main() now, as it should be :D.

@kqdeng
Copy link
Contributor

kqdeng commented Nov 5, 2020

With this change, would it make sense that we add in a CUSTOM_ENDPOINTS: '{"/metadata":".metadata"}' in tink's docker-compose file? (I think James @splaspood also mentioned this earlier but I could be wrong.)

I understand the reasoning behind this change but I'm still a little e_e.
But with this^ we can omit the envvar when we bring up hegel, but for the open source community who (I assume) mostly use the docker compose file, they can "default" to "/metadata": ".metadata"? What do you think?

@mmlb
Copy link
Contributor Author

mmlb commented Nov 5, 2020

Yeah that is a good option. I kind of would rather merge this as is though and see if there are any problems with it. I'm not sure if any workflows are even using hegel/metadata (https://deploy-preview-162--suspicious-jackson-6c9a73.netlify.app/blog/2020/10/provisioning-flatcar-container-linux-with-tinkerbell/ just embeds the ignition straight into the template). So I'd rather err on the side of /metadata is same as /meta-data unless we need to come up with a work around.

@mmlb mmlb force-pushed the change-default-metadata-endpoint-handling branch from a132fc1 to a2fe424 Compare November 5, 2020 23:01
@mmlb mmlb requested a review from kqdeng November 5, 2020 23:02
@mmlb mmlb force-pushed the change-default-metadata-endpoint-handling branch from a2fe424 to c2383c7 Compare November 6, 2020 19:31
@mmlb
Copy link
Contributor Author

mmlb commented Nov 6, 2020

alrighty @kdeng3849 I think everything should all set now.

kqdeng
kqdeng previously approved these changes Nov 6, 2020
@mmlb mmlb added the ready-to-merge Signal to Mergify to merge the PR. label Nov 6, 2020
@mmlb mmlb removed the request for review from a team November 6, 2020 21:19
mmlb added 7 commits November 6, 2020 16:19
Signed-off-by: Manuel Mendez <[email protected]>
This is more concise.

Signed-off-by: Manuel Mendez <[email protected]>
This is easier to track down failures with.

Signed-off-by: Manuel Mendez <[email protected]>
main is the correct place to parse out env vars and command line flags.

Signed-off-by: Manuel Mendez <[email protected]>
So we have nicely aligned and sorted json.

Signed-off-by: Manuel Mendez <[email protected]>
…nterface{}

When the default handling for /metadata changes in an upcoming commit
unmarshalling the json to packet.Metadata is not going to work. So we
change the unmarshalling destination here instead so the next commit
is doing only one thing.

Signed-off-by: Manuel Mendez <[email protected]>
This is so we can avoid confusion when taking into account the handling
of /meta-data. In EM Production today (Kant) /meta-data and /metadata
both have the same output data. Making Hegel match by default is in line
with the goal of Hegel as a Kant replacement.

This is a bc-break and there's no current way to fetch the full
hardware.metadata json field, but I'm ok with that. This should all go
away when the Instance Proposal is implemented.

Signed-off-by: Manuel Mendez <[email protected]>
@mmlb mmlb force-pushed the change-default-metadata-endpoint-handling branch from c2383c7 to 4970c17 Compare November 6, 2020 21:19
@mmlb mmlb requested a review from kqdeng November 6, 2020 21:20
@mergify mergify bot merged commit 1583c90 into tinkerbell:master Nov 6, 2020
@mmlb mmlb deleted the change-default-metadata-endpoint-handling branch November 6, 2020 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Denotes a PR that introduces potentially breaking changes that require user action. ready-to-merge Signal to Mergify to merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants