-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Conversation
@UnsignedLong @linki please take a look |
pkg/apis/externaldns/types.go
Outdated
@@ -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") |
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.
maybe add example template usage here
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.
done
LGTM |
source/ingress.go
Outdated
@@ -17,6 +17,10 @@ limitations under the License. | |||
package source | |||
|
|||
import ( | |||
"bytes" | |||
"html/template" |
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 not text/template?
source/ingress.go
Outdated
@@ -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] |
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.
instead of "exists" use "ok", it's the normal pattern used in the go community
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 just copy pasted this :D but yeah ok
is more standard
source/ingress.go
Outdated
return endpoints | ||
var buf bytes.Buffer | ||
|
||
if sc.fqdntemplate.Execute(&buf, ing) == nil { //TODO(ideahitme): if error is present skip or abort ? |
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.
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.
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, 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 :)
source/service.go
Outdated
@@ -17,6 +17,10 @@ limitations under the License. | |||
package source | |||
|
|||
import ( | |||
"bytes" | |||
"html/template" |
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.
use text/template instead
source/service.go
Outdated
} | ||
|
||
// 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) { |
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.
Personally I would like to have the signature
func NewServiceSource(client kubernetes.Interface, namespace, fqdntemplate string, compatibility bool) (Source, 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.
yeah makes sense :)
source/service.go
Outdated
return nil | ||
var buf bytes.Buffer | ||
|
||
if sc.fqdntemplate.Execute(&buf, svc) == nil { //TODO(ideahitme): if error is present skip or abort ? |
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.
as above please log or handle the error not silently drop it
👍 |
@@ -1,5 +1,5 @@ | |||
Features: | |||
|
|||
- Generate DNS Name from template for services/ingress if annotation is missing but `--fqdntemplate` is specified |
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.
Flag is missing a -
:)
…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
#156
@UnsignedLong