Skip to content

add new field 'Domain' to kcert spec - #747

Merged
knative-prow[bot] merged 2 commits into
knative:mainfrom
KauzClay:ck-include-domain-in-kcert
Jan 12, 2023
Merged

knative-prow[bot] merged 2 commits into
knative:mainfrom
KauzClay:ck-include-domain-in-kcert

Conversation

@KauzClay

@KauzClay KauzClay commented Jan 3, 2023 •

Copy link
Copy Markdown
Contributor

Changes

/kind api-change

Part of Fix for knative-extensions/net-certmanager#214

Release Note

N/A

Docs

N/A

@knative-prow

knative-prow Bot commented Jan 3, 2023

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@knative-prow knative-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 3, 2023
@knative-prow
knative-prow Bot requested review from andrew-su and shashwathi January 3, 2023 22:03
@KauzClay
KauzClay marked this pull request as ready for review January 3, 2023 22:53
@knative-prow knative-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 3, 2023
@knative-prow
knative-prow Bot requested a review from tcnghia January 3, 2023 22:53
@KauzClay
KauzClay force-pushed the ck-include-domain-in-kcert branch 2 times, most recently from bc8d755 to 1cadfa6 Compare January 6, 2023 16:33
@codecov

codecov Bot commented Jan 6, 2023 •

Copy link
Copy Markdown

Codecov Report

Base: 94.75% // Head: 94.80% // Increases project coverage by +0.04% 🎉

Coverage data is based on head (803a44c) compared to base (f1db313).
Patch coverage: 100.00% of modified lines in pull request are covered.

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              
Impacted Files Coverage Δ
pkg/apis/networking/v1alpha1/certificate_types.go 100.00% <ø> (ø)
...apis/networking/v1alpha1/certificate_validation.go 100.00% <100.00%> (ø)

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@KauzClay

KauzClay commented Jan 6, 2023

Copy link
Copy Markdown
Contributor Author

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.

@KauzClay KauzClay changed the title add new field domain to kcert add new field 'Domain' to kcert spec Jan 6, 2023
@evankanderson

Copy link
Copy Markdown
Member

CertificateSpec.Domain needs to be optional, because it's probably not set on any of the existing KIngress resources in existing clusters.

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

@evankanderson

Copy link
Copy Markdown
Member

/assign

@KauzClay

Copy link
Copy Markdown
Contributor Author

@evankanderson thanks for explaining, it makes sense why it should be optional then.

So, I added the // +optional and omitempty to the json tag. Is there anything else that needs to happen?

@evankanderson evankanderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

func (spec *CertificateSpec) Validate(ctx context.Context) (all *apis.FieldError) {

@knative-prow knative-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 12, 2023
@KauzClay
KauzClay force-pushed the ck-include-domain-in-kcert branch from f3c04ea to 2ef1447 Compare January 12, 2023 21:18
if spec.Domain != "" && len(spec.DNSNames) != 0 {
valid := false
for _, dnsName := range spec.DNSNames {
if strings.HasSuffix(dnsName, fmt.Sprintf(".%s", spec.Domain)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah right, I'll fix that

name: "valid",
cs: &CertificateSpec{
DNSNames: []string{"host.example"},
Domain: "example",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you need a case without Domain set? (I think you do)

@KauzClay
KauzClay force-pushed the ck-include-domain-in-kcert branch from 2ef1447 to 0cac5bb Compare January 12, 2023 22:06
* make sure at least one dnsName has the domain as a suffix
@KauzClay
KauzClay force-pushed the ck-include-domain-in-kcert branch from 0cac5bb to 803a44c Compare January 12, 2023 22:35

@evankanderson evankanderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks for the iterations!

}, {
name: "valid-with-domain",
cs: &CertificateSpec{
DNSNames: []string{"host.example"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@knative-prow knative-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2023
@knative-prow

knative-prow Bot commented Jan 12, 2023

Copy link
Copy Markdown

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 12, 2023
@knative-prow
knative-prow Bot merged commit 68f0fa7 into knative:main Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants