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
Decompress GZIP'd user data #1762
base: main
Are you sure you want to change the base?
Conversation
176e80f
to
706489f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the change LGTM. doesn't seem like we are going to adopt decompressing individual parts, so can we do a doc update before merging?
706489f
to
3fceead
Compare
3fceead
to
d741996
Compare
@ndbaker1 latest rev adds support for this, PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote the unit tests for this config provider; they're more verbose but I think being explicit about the input is more clear and lets us more easily add test cases in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do any integration testing here? Or is that covered by the existing integration tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like the change, thanks for skipping over the junk to setup mime documents and testing the actual provider interface
type userDataConfigProvider struct { | ||
userDataProvider userDataProvider | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this wrapper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for testing, it allows us to mock out the IMDS calls
return &userDataConfigProvider{} | ||
return &userDataConfigProvider{ | ||
userDataProvider: &imdsUserDataProvider{}, | ||
} | ||
} | ||
|
||
func (ics *userDataConfigProvider) Provide() (*internalapi.NodeConfig, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is ics
the name for userDataConfigProvider
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's an artifact from when it was something like imdsConfigProvider
? 🤣
maybe we could just generally name the config provider references cp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh i like just calling it this
but that's a Java-ism that gophers detest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha. Let's change it to something that makes sense :P
if part.Header.Get(contentEncodingHeader) == "gzip" { | ||
decompressedNodeConfigPart, err := decompressIfGZIP(nodeConfigPart) | ||
if err != nil { | ||
return nil, err | ||
} | ||
nodeConfigPart = decompressedNodeConfigPart | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to make a check that it's gzip
and then gracefully handle it not being gzip
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't just calling decompressIfGZIP
in all cases work better since its fallible in constant time and safe either way?
To not hit this branch you'd have to set the nodeConfig mediaType but forget to add the gzip encoding header, which im sure would only happen on accident. maybe handling it explicitly is more "proper", but not sure if its necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MIME semantics dictate that if the section is GZIP'd, this header needs to be there. If a user (or library) is creating MIME documents that use GZIP but omit this header, that should fail because it's not conformant to the spec.
Generally, folks are only using GZIP compression via a library which should implement this properly -- folks aren't hand-writing and hand-compressing their MIME docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do any integration testing here? Or is that covered by the existing integration tests?
if part.Header.Get(contentEncodingHeader) == "gzip" { | ||
decompressedNodeConfigPart, err := decompressIfGZIP(nodeConfigPart) | ||
if err != nil { | ||
return nil, err | ||
} | ||
nodeConfigPart = decompressedNodeConfigPart | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't just calling decompressIfGZIP
in all cases work better since its fallible in constant time and safe either way?
To not hit this branch you'd have to set the nodeConfig mediaType but forget to add the gzip encoding header, which im sure would only happen on accident. maybe handling it explicitly is more "proper", but not sure if its necessary
return &userDataConfigProvider{} | ||
return &userDataConfigProvider{ | ||
userDataProvider: &imdsUserDataProvider{}, | ||
} | ||
} | ||
|
||
func (ics *userDataConfigProvider) Provide() (*internalapi.NodeConfig, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's an artifact from when it was something like imdsConfigProvider
? 🤣
maybe we could just generally name the config provider references cp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like the change, thanks for skipping over the junk to setup mime documents and testing the actual provider interface
type userDataProvider interface { | ||
GetUserData() ([]byte, error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice way to make testing the provider interface easier 👍
/ci |
@cartermckinnon roger that! I've dispatched a workflow. 👍 |
@cartermckinnon the workflow that you requested has completed. 🎉
|
One flake:
Not related |
Issue #, if available:
Fixes #1734
Description of changes:
Adds support for GZIP-compressed user data.
The following scenarios are supported:
NodeConfig
that is compressed with GZIP.Content-Encoding: gzip
header).By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.