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

Add support for ServiceAccount auth to kubeletstats #324

Merged
merged 11 commits into from
Jun 17, 2020
Merged

Add support for ServiceAccount auth to kubeletstats #324

merged 11 commits into from
Jun 17, 2020

Conversation

pmcollins
Copy link
Member

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.

@pmcollins pmcollins requested a review from a team June 15, 2020 15:01
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 15, 2020

CLA Check
The committers are authorized under a signed CLA.

  • ✅ Pablo Collins (249f4489efd20ad8400e525e35a9ee9319746db9)

@codecov
Copy link

codecov bot commented Jun 15, 2020

Codecov Report

Merging #324 into master will increase coverage by 0.33%.
The diff coverage is 87.27%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
receiver/kubeletstatsreceiver/kubelet/cert.go 69.23% <50.00%> (+69.23%) ⬆️
receiver/kubeletstatsreceiver/kubelet/client.go 92.85% <88.67%> (+41.63%) ⬆️
receiver/carbonreceiver/transport/tcp_server.go 65.71% <0.00%> (-1.91%) ⬇️
receiver/kubeletstatsreceiver/factory.go 64.10% <0.00%> (+5.12%) ⬆️

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 a304ef1...d41a754. Read the comment docs.

Copy link
Member

@dmitryax dmitryax left a 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
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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"
Copy link
Member

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

Copy link
Member Author

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).

Copy link
Member

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.

Copy link
Member

@dmitryax dmitryax Jun 16, 2020

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

Copy link
Member Author

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
Copy link
Member

@dmitryax dmitryax left a 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

@pmcollins
Copy link
Member Author

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.

@dmitryax
Copy link
Member

@pmcollins could you check the linter issue please?

@flands flands added this to the 0.5.0 milestone Jun 17, 2020
Copy link
Member

@dmitryax dmitryax left a 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?

@tigrannajaryan tigrannajaryan merged commit 4ca134c into open-telemetry:master Jun 17, 2020
wyTrivail referenced this pull request in mxiamxia/opentelemetry-collector-contrib Jul 13, 2020
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.
ljmsc referenced this pull request in ljmsc/opentelemetry-collector-contrib Feb 21, 2022
bogdandrutu pushed a commit that referenced this pull request May 12, 2022
* 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>
codeboten pushed a commit that referenced this pull request Nov 23, 2022
codeboten pushed a commit that referenced this pull request Nov 23, 2022
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.

4 participants