Repository navigation
add new field 'Domain' to kcert spec - #747
Conversation
|
Skipping CI for Draft Pull Request. |
bc8d755 to
1cadfa6
Compare
Codecov ReportBase: 94.75% // Head: 94.80% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #747 +/- ##
==========================================
+ Coverage 94.75% 94.80% +0.04%
==========================================
Files 41 41
Lines 1221 1231 +10
==========================================
+ Hits 1157 1167 +10
Misses 52 52
Partials 12 12
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
I started with making the Domain field required, but many tests fail. I think this is because net-certmanager tests don't know about it yet. I don't know how to make it required and make the tests pass. Making it optional gets the tests to pass, but I don't know if that is the best end state. |
|
It might become set after an upgrade during reconciliation of the existing resources, but we can't assume that it's set on a currently-live cluster, so we need to have a plan for it not being present (even if the plan is "behaves the same as today"). |
|
/assign |
|
@evankanderson thanks for explaining, it makes sense why it should be optional then. So, I added the |
evankanderson
left a comment
There was a problem hiding this comment.
You may want to add a check that spec.domain is a suffix of at least one domain when it is set. See here if you want to enforce that:
f3c04ea to
2ef1447
Compare
| if spec.Domain != "" && len(spec.DNSNames) != 0 { | ||
| valid := false | ||
| for _, dnsName := range spec.DNSNames { | ||
| if strings.HasSuffix(dnsName, fmt.Sprintf(".%s", spec.Domain)) { |
There was a problem hiding this comment.
Rather than calling fmt.Sprintf() in the loop, do it once outside the loop.
Also, you should be able to use string +, rather than needing to pull in the fmt module:
if spec.Domain != "" { // Already added an error for missing dnsNames
domainSuffix := "." + spec.Domain
err := apis.ErrInvalidValue(...)
for _, dnsName := range spec.DNSNames {
if strings.HasSuffix(dnsName, domainSuffix) {
err = nil
break
}
}
all = all.Also(err) // nil FieldError is a no-op
}There was a problem hiding this comment.
ah right, I'll fix that
| name: "valid", | ||
| cs: &CertificateSpec{ | ||
| DNSNames: []string{"host.example"}, | ||
| Domain: "example", |
There was a problem hiding this comment.
Do you need a case without Domain set? (I think you do)
2ef1447 to
0cac5bb
Compare
* make sure at least one dnsName has the domain as a suffix
0cac5bb to
803a44c
Compare
evankanderson
left a comment
There was a problem hiding this comment.
/lgtm
/approve
Thanks for the iterations!
| }, { | ||
| name: "valid-with-domain", | ||
| cs: &CertificateSpec{ | ||
| DNSNames: []string{"host.example"}, |
There was a problem hiding this comment.
Not strictly necessary; you could add "host.foo" to DNSNames to test both paths through the loop, but I'm pretty confident with the coverage overall.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: evankanderson, KauzClay The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
/kind api-change
Part of Fix for knative-extensions/net-certmanager#214
Release Note
Docs