Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@bakins
Copy link
Contributor

@bakins bakins commented Nov 2, 2017

This PR is an idea in code form.

1. What does this pull request do?

This adds an option to use the name of a pod as the hostname rather the hostname for lookups when pods mode is set to insecure or verified for the Kubernetes plugin.

2. Which issues (if any) are related?

kubernetes/kubernetes#47992 - I did not find a related coredns issue doing a quick issue search.

We are also using airflow and this change enables DNS for pod FQDNs without settinghostname in the pod specs. As we use deployments, we do not want each pod to have the same hostname.

3. Which documentation changes (if any) need to be made?

We would need to document the additional, optional, argument to pods in the Kubernetes plugin.

I was unsure if this should be a separate option or part of the pods mode.

As I said, this is to capture an idea in code form. It is fairly simple and has tests that pass.

@miekg
Copy link
Member

miekg commented Nov 2, 2017

Reading through that whole thread, this seems a reasonable request.

@chrisohaver
Copy link
Member

chrisohaver commented Nov 2, 2017

This seems like a reasonable option. This follows the endpoint naming spec, since the pod name is unique in the namespace.

To clarify, this is "Adding option to use pod name rather than IP address for k8s endpoint fqdns" ...
It's changing the way we name endpoints. The default behavior is to use the pod hostname, the optional behavior being added here is to use the pod name.

For example: my-pod-12341234-abc123.my-service.namespace.svc.cluster.local instead of the default 1-2-3-4.my-service.namespace.svc.cluster.local

This does not change the way pod lookups function.
For example: 1-2-3-4.namespace.pod.cluster.local
This does not allow you to look up a pod using for example an query such as my-pod-12341234-abc123.namespace.pod.cluster.local

As far as option name goes: I think "endpointNameMode" might be a slightly better/clearer option name than "podNameMode".

Copy link
Member

@miekg miekg left a comment

Choose a reason for hiding this comment

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

Few nit comments and the Travis failures need a fx.
And this needs to be documented in 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.

Can you make "name" a constant, similar to add podMode ones

Copy link
Member

Choose a reason for hiding this comment

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

default is just not setting this? I.e. no need for "default"?

@johnbelamaric
Copy link
Member

This changes the endpoint records; ie, with svc not pod type in the name. The pods config option is for the pod records. Maybe we need an endpoints config option instead.

@bakins bakins closed this Nov 2, 2017
@bakins bakins reopened this Nov 2, 2017
@bakins
Copy link
Contributor Author

bakins commented Nov 2, 2017

Changes made. I added an endpoints config option, as I agree that reflects its actual usage better.
I added documentation - I'd appreciate feedback on it.

I can squash the commits if/when ready to merge.

@codecov-io
Copy link

codecov-io commented Nov 2, 2017

Codecov Report

Merging #1190 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1190      +/-   ##
=========================================
+ Coverage   49.05%   49.1%   +0.05%     
=========================================
  Files         165     165              
  Lines        9669    9679      +10     
=========================================
+ Hits         4743    4753      +10     
  Misses       4627    4627              
  Partials      299     299
Impacted Files Coverage Δ
plugin/kubernetes/kubernetes.go 56.25% <100%> (+0.46%) ⬆️
plugin/kubernetes/setup.go 63.47% <100%> (+1.59%) ⬆️
plugin/kubernetes/reverse.go 70.37% <100%> (ø) ⬆️

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 6bea4cd...906c6a6. Read the comment docs.

Copy link
Member

Choose a reason for hiding this comment

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

This should work regardless of the pods setting, I believe. We always watch endpoints, and we respond to their hostname records regardless of whether pod types are enabled.

We could add an option to pods verified that enables pod-name.namespace.pod.cluster.local.

Copy link
Member

Choose a reason for hiding this comment

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

But that would be a separate PR...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@johnbelamaric you are correct, it works if pods is disabled. Updating doc.

Copy link
Member

Choose a reason for hiding this comment

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

Normally if the endpoint has a hostname then these will resolve. This change just makes them use the pod name if it exists and the hostname doesn't. I think that needs to be made clearer here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"If hostname is set on a pod, then it always has precedence." - is that enough?

Copy link
Member

Choose a reason for hiding this comment

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

Actually now that I think some more; endpointNameMode is just a boolean, no need to carry a string with us all time and to a string compare - this is either on or off.

Copy link
Member

Choose a reason for hiding this comment

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

Please create a new parse test for just this option; this adds a whole bunch of empty strings for no purpose at all in this test.

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 reverse this and not use a switch:

if len(args) != 1 { 
     return nil, opts. c.ArgErr()
}
if args[0] != endpointNameModeName {
    return nil, opts. fmt.Errorf("wrong value for endpoints: %s")
}

@bakins
Copy link
Contributor Author

bakins commented Nov 3, 2017

Changes made. Writing docs is the hardest part of any project for me, so let me know what you think.

Copy link
Member

@chrisohaver chrisohaver 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. I've proposed an alternate documentation entry.

Copy link
Member

Choose a reason for hiding this comment

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

How about this instead...

  • endpoints ENDPOINT-MODE sets the mode for naming endpoint A
    records, e.g. endpoint-name.my-service.namespace.svc.cluster.local. in A 1.2.3.4
    By default, the endpoint-name is set to the hostname of the endpoint, or if hostname is not set, the dashed form of the endpoint ip address (e.g. 1-2-3-4.my-service.namespace.svc.cluster.local.)

    Valid values for ENDPOINT-MODE:

    • name: If the endpoint hostname is not set, use the pod name of the pod targeted by the endpoint. If there is no pod targeted by the endpoint, use the dashed ip address form.

Copy link
Member

Choose a reason for hiding this comment

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

ok, but as @miekg said, since there is only one value for endpoints-mode, maybe we should just say that the whole directive is endpoints pod names or similar. That will simplify the config and docs a bit. I don't want to just say endpoints because it's not clear enough how it changes the behavior.

Questions:

  • Will it still respond to the dashed-ip name even if this is set? That is, is this an additional name or a replacement name? Should we pick one as the A record and have a CNAME for the other?
  • Which name shows up in the SRV record for the service?

Copy link
Member

@chrisohaver chrisohaver Nov 3, 2017

Choose a reason for hiding this comment

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

Per my understanding of the code...

Is this an additional name or a replacement name?

This is a replacement name, not an additional name.

Which name shows up in the SRV record for the service?

SRV targets will point to the A records of the endpoints.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed ... here is a "boolean" directive version...

  • endpoint_pod_names Use the pod name of the pod targeted by the endpoint as the endpoint name in A records, e.g. endpoint-name.my-service.namespace.svc.cluster.local. in A 1.2.3.4
    By default, the endpoint-name name selection is as follows: Use the hostname of the endpoint, or if hostname is not set, use the dashed form of the endpoint ip address (e.g. 1-2-3-4.my-service.namespace.svc.cluster.local.)
    If this directive is included, then name selection for endpoints changes as follows: Use the hostname of the endpoint, or if hostname is not set, use the pod name of the pod targeted by the endpoint. If there is no pod targeted by the endpoint, use the dashed ip address form.

Copy link
Member

Choose a reason for hiding this comment

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

👍 now @bakins please update the code to match :)

Copy link
Member

@miekg miekg 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 from code standpoint.

@chrisohaver
Copy link
Member

/integration (kicking off k8s integration tests)

@coredns-cibot
Copy link

coredns-cibot commented Nov 3, 2017

Integration test PASS. Run time 129 seconds. View Log

Pass Fail
Tests 8 0
Subtests 37 0

@miekg
Copy link
Member

miekg commented Nov 3, 2017

think we fleshed out what needs to be done here. Shall we wait with 0.9.10 so this can go in?

@johnbelamaric
Copy link
Member

No, let's just get 0.9.10 out ASAP.

@coredns-cibot
Copy link

coredns-cibot commented Nov 3, 2017 via email

@bakins
Copy link
Contributor Author

bakins commented Nov 3, 2017

Changes made. Let me know if this all looks good and I'll squash.

@johnbelamaric
Copy link
Member

/integration

@coredns-cibot
Copy link

coredns-cibot commented Nov 3, 2017

Integration test PASS. Run time 137 seconds. View Log

Pass Fail
Tests 8 0
Subtests 37 0

Copy link
Member

Choose a reason for hiding this comment

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

We can remove endpointNameModeName now...

@bakins
Copy link
Contributor Author

bakins commented Nov 3, 2017

Okay, pushed hopefully the last change - removed endpointNameModeName. Let me know and I will squash, if that's what you want.

@miekg
Copy link
Member

miekg commented Nov 3, 2017 via email

Change to use a new 'endpoints' directive and use a constant

Add initial docs for 'endpoints' directive

Add tests to Kubernetes setup for endpoints

Changes based on PR feedback

endpoint_pod_names is a boolean config option. Chahanged docs to reflect this.

Add a test when endpoints_pod_names is not set

Update README.md

Remove endpointNameModeName as it is no longer used
@bakins bakins force-pushed the add-kubernetes-podNameMode branch from 7d577eb to 906c6a6 Compare November 3, 2017 21:32
@bakins
Copy link
Contributor Author

bakins commented Nov 3, 2017

squashed and pushed.

@miekg
Copy link
Member

miekg commented Nov 8, 2017

@johnbelamaric are you happy w/ this?

@johnbelamaric johnbelamaric merged commit 3527be6 into coredns:master Nov 8, 2017
@tomplus
Copy link

tomplus commented Nov 27, 2017

When are you going to release next version with this feature ? I'm looking forward to use it. Thanks.

@johnbelamaric
Copy link
Member

Yes, 1.0.0 will be released this week or early next week.

@tomplus
Copy link

tomplus commented Dec 8, 2017

Thank you, it works like a charm !

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.

7 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.