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

[PR-156 follow-up] Generate endpoints hostnames if go-template is specified #160

Merged
merged 17 commits into from
Apr 18, 2017

Conversation

ideahitme
Copy link

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 18, 2017
@ideahitme ideahitme self-assigned this Apr 18, 2017
@ideahitme
Copy link
Author

@UnsignedLong @linki please take a look

@@ -81,5 +82,6 @@ func (cfg *Config) ParseFlags(args []string) error {
flags.StringVar(&cfg.Registry, "registry", "noop", "type of registry for ownership: <noop|txt>")
flags.StringVar(&cfg.RecordOwnerID, "record-owner-id", "", "id for keeping track of the managed records")
flags.StringVar(&cfg.TXTPrefix, "txt-prefix", "", `prefix assigned to DNS name of the associated TXT record; e.g. for --txt-prefix=abc_ [CNAME example.org] <-> [TXT abc_example.org]`)
flags.StringVar(&cfg.FqdnTemplate, "fqdn-template", "", "template to create FQDN")
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add example template usage here

Copy link
Author

Choose a reason for hiding this comment

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

done

@hjacobs
Copy link
Contributor

hjacobs commented Apr 18, 2017

LGTM

@hjacobs hjacobs added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 18, 2017
@@ -17,6 +17,10 @@ limitations under the License.
package source

import (
"bytes"
"html/template"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not text/template?

@@ -48,23 +68,49 @@ func (sc *ingressSource) Endpoints() ([]*endpoint.Endpoint, error) {
endpoints := []*endpoint.Endpoint{}

for _, ing := range ingresses.Items {
// Check controller annotation to see if we are responsible.
controller, exists := ing.Annotations[controllerAnnotationKey]
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of "exists" use "ok", it's the normal pattern used in the go community

Copy link
Author

Choose a reason for hiding this comment

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

I just copy pasted this :D but yeah ok is more standard

return endpoints
var buf bytes.Buffer

if sc.fqdntemplate.Execute(&buf, ing) == nil { //TODO(ideahitme): if error is present skip or abort ?
Copy link
Contributor

@szuecs szuecs Apr 18, 2017

Choose a reason for hiding this comment

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

Log the error, return the error or handle the error, but not silently ignore it.
A user will do errors and should be able to understand that it's a wrong go template which could not be rendered.

Copy link
Author

Choose a reason for hiding this comment

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

yes, that's why there is TODO, we are lacking logging where it should be logged in multiple places, but I will add the logging here :)

@@ -17,6 +17,10 @@ limitations under the License.
package source

import (
"bytes"
"html/template"
Copy link
Contributor

Choose a reason for hiding this comment

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

use text/template instead

}

// NewServiceSource creates a new serviceSource with the given client and namespace scope.
func NewServiceSource(client kubernetes.Interface, namespace string, compatibility bool) Source {
func NewServiceSource(client kubernetes.Interface, namespace string, compatibility bool, fqdntemplate string) (Source, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I would like to have the signature

func NewServiceSource(client kubernetes.Interface, namespace, fqdntemplate string, compatibility bool) (Source, error) {

Copy link
Author

Choose a reason for hiding this comment

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

yeah makes sense :)

return nil
var buf bytes.Buffer

if sc.fqdntemplate.Execute(&buf, svc) == nil { //TODO(ideahitme): if error is present skip or abort ?
Copy link
Contributor

Choose a reason for hiding this comment

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

as above please log or handle the error not silently drop it

@ideahitme
Copy link
Author

@hjacobs @szuecs thanks for valuable comments. please take a look again

@szuecs
Copy link
Contributor

szuecs commented Apr 18, 2017

👍

@hjacobs hjacobs merged commit 25eef91 into master Apr 18, 2017
@@ -1,5 +1,5 @@
Features:

- Generate DNS Name from template for services/ingress if annotation is missing but `--fqdntemplate` is specified
Copy link
Contributor

Choose a reason for hiding this comment

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

Flag is missing a - :)

@ideahitme ideahitme deleted the pr-156-follow-up branch April 19, 2017 18:08
ffledgling pushed a commit to ffledgling/external-dns that referenced this pull request Jan 18, 2018
…cified (kubernetes-sigs#160)

* add --fqdn-template

* add missing ,

* gofmt

* no endpoint creation on empty fqdntemplate

* improve test coverage

* gofmt simple on service_test.go and ingress_test.go

* import package order changed

* gofmt

* refactor to generate template in the source init

* refactor for err handling

* fix service tests

* fix wrong check, check for priorities, mate > template

* fix tests, check for controller annotation in the right place

* add to changelog

* add flag description, improve testing, reorganize imports

* review changes: log the error, use text/template, change func interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants