-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add support for ServiceAccount auth to kubeletstats #324
Add support for ServiceAccount auth to kubeletstats #324
Conversation
Codecov Report
@@ Coverage Diff @@
## master #324 +/- ##
==========================================
+ Coverage 83.04% 83.38% +0.33%
==========================================
Files 167 167
Lines 8900 8943 +43
==========================================
+ Hits 7391 7457 +66
+ Misses 1185 1161 -24
- Partials 324 325 +1
Continue to review full report at Codecov.
|
Kubeletstats receiver only supported TLS auth. This change adds support for ServiceAccount auth as well. Addresses issue #311.
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.
Overall looks good to me. Just minor comments
func newServiceAccountClient(endpoint string, caCertPath string, tokenPath string, logger *zap.Logger) (*clientImpl, error) { | ||
rootCAs, err := systemCertPoolPlusPath(caCertPath) | ||
if err != nil { | ||
return nil, err |
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.
Should we provide more details by wrapping this 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.
Good point. Done.
} | ||
tok, err := ioutil.ReadFile(tokenPath) | ||
if err != nil { | ||
return nil, err |
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.
Same here. It might be not clear to the end user why do we try to read this file
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.
Agree. Fixed.
InsecureSkipVerify: insecureSkipVerify, | ||
} | ||
return &tlsClient{ | ||
if endpoint == "" { | ||
endpoint = defaultEndpoint(logger) |
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 would put a log entry here like (maybe warning?): kubelet endpoint is not provided, using hostname "..." by default.
I think usually it's not going to work so it would be good to let user know about it, in case if they just forgot to set the endpoint config.
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 functionality is borrowed from the Smart Agent and I agree it's not obvious. If you set hostNetwork to true in the pod spec, the pod has access to the node's loopback device. I have added a comment to explain, have added a log warning, and updated the readme.
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.
Cool. Thank you!
hostname, err := os.Hostname() | ||
if err != nil { | ||
logger.Error("unable to get hostname", zap.Error(err)) | ||
endpoint = "localhost" |
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.
Not sure if there is a case when this would work in k8s, but let's keep it if you think it can work
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.
Should work with hostNetwork, but I've removed falling back to localhost since getting the hostname shouldn't error out (and smart agent doesn't do this either).
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.
Yes, I was talking about localhost in this comment
Improved logging and explained hostNetwork usage.
is running to be used as the endpoint. If the hostNetwork flag is set, and the | ||
collector is running in a pod, this hostname will resolve to the node's network | ||
namespace. | ||
|
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.
Can we add a serviceAccount
usage example here with downward API?
If I understand correctly it should be:
kubeletstats:
authType: serviceAccount
endpoint: https://${K8S_NODE_NAME}:10250
Another note:
Make sure that it's set using the downward API in the collector pod spec as follows:
env:
- name: K8S_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
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.
Yeah, that's a good idea. Done.
Update README with service account example
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.
Looks good to me. I'm not sure if we need to hit 95% coverage here. Probably only NewClient
, where case k8sconfig.AuthTypeServiceAccount:
looks like still not covered
Thanks for the review Dmitrii. I haven't added coverage for those two lines because they require secrets to be mounted. I'll have to make some tweaks to make this unit-testable. |
@pmcollins could you check the linter issue please? |
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.
LGTM. @tigrannajaryan @bogdandrutu the diff has pretty good coverage. I don't think we gain a lot by reaching 95% here. Could you take a look if we can merge it?
Kubeletstats receiver only supported TLS auth. This change adds support for ServiceAccount auth as well. **Link to tracking Issue:** #311 **Testing:** Manual testing of ServiceAccount auth was done in GKE. **Documentation:** ServiceAccount config is already in the README.
* Added a configuration options for csv lazy quotes (embedded) quotes Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com> * Updated csv_parser docs with lazy_quotes option Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>
Description: Kubeletstats receiver only supported TLS auth. This change adds support
for ServiceAccount auth as well.
Link to tracking Issue: #311
Testing: Manual testing of ServiceAccount auth was done in GKE.
Documentation: ServiceAccount config is already in the README.