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

Adds ingress annotation support for alt-names #6190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/controller/certificate-shim/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func translateAnnotations(crt *cmapi.Certificate, ingLikeAnnotations map[string]
crt.Spec.CommonName = commonName
}

if altNames, found := ingLikeAnnotations[cmapi.AltNamesAnnotationKey]; found {
crt.Spec.DNSNames = strings.Split(altNames, ",")
}

if emailAddresses, found := ingLikeAnnotations[cmapi.EmailsAnnotationKey]; found {
crt.Spec.EmailAddresses = strings.Split(emailAddresses, ",")
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/certificate-shim/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func Test_translateAnnotations(t *testing.T) {
cmapi.SubjectStreetAddressesAnnotationKey: `"1725 Slough Avenue, Suite 200, Scranton Business Park","1800 Slough Avenue, Suite 200, Scranton Business Park"`,
cmapi.SubjectPostalCodesAnnotationKey: "ABC123",
cmapi.SubjectSerialNumberAnnotationKey: "123456",
cmapi.AltNamesAnnotationKey: "www.example.com,example.com,test.example.com",
}
}

Expand All @@ -77,6 +78,15 @@ func Test_translateAnnotations(t *testing.T) {
joinedAddresses, joinErr := cmutil.JoinWithEscapeCSV(crt.Spec.Subject.StreetAddresses)
a.Equal(nil, joinErr)
a.Equal(`"1725 Slough Avenue, Suite 200, Scranton Business Park","1800 Slough Avenue, Suite 200, Scranton Business Park"`, joinedAddresses)

splitAltNames, splitErr := cmutil.SplitWithEscapeCSV("www.example.com,example.com,test.example.com")
a.Equal(nil, splitErr)
a.Equal(splitAltNames, crt.Spec.DNSNames)

joinedAltNames, joinErr := cmutil.JoinWithEscapeCSV(crt.Spec.DNSNames)
a.Equal(nil, joinErr)
a.Equal("www.example.com,example.com,test.example.com", joinedAltNames)

},
},
"success rsa private key algorithm": {
Expand Down
9 changes: 8 additions & 1 deletion test/e2e/suite/conformance/certificates/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ func (s *Suite) Define() {
}
var certName string
domain := e2eutil.RandomSubdomain(s.DomainSuffix)
altNames := strings.Join([]string{
domain,
e2eutil.RandomSubdomain(s.DomainSuffix),
e2eutil.RandomSubdomain(domain),
}, ",")
duration := time.Hour * 999
renewBefore := time.Hour * 111
revisionHistoryLimit := pointer.Int32(7)
Expand All @@ -805,6 +810,7 @@ func (s *Suite) Define() {
"cert-manager.io/issuer-kind": issuerRef.Kind,
"cert-manager.io/issuer-group": issuerRef.Group,
"cert-manager.io/common-name": domain,
"cert-manager.io/alt-names": altNames,
"cert-manager.io/duration": duration.String(),
"cert-manager.io/renew-before": renewBefore.String(),
"cert-manager.io/revision-history-limit": strconv.FormatInt(int64(*revisionHistoryLimit), 10),
Expand All @@ -828,6 +834,7 @@ func (s *Suite) Define() {
"cert-manager.io/issuer-kind": issuerRef.Kind,
"cert-manager.io/issuer-group": issuerRef.Group,
"cert-manager.io/common-name": domain,
"cert-manager.io/alt-names": altNames,
"cert-manager.io/duration": duration.String(),
"cert-manager.io/renew-before": renewBefore.String(),
"cert-manager.io/revision-history-limit": strconv.FormatInt(int64(*revisionHistoryLimit), 10),
Expand Down Expand Up @@ -857,7 +864,7 @@ func (s *Suite) Define() {
err = f.Helper().ValidateCertificate(
cert,
func(certificate *cmapi.Certificate, _ *corev1.Secret) error {
Expect(certificate.Spec.DNSNames).To(ConsistOf(domain))
Expect(certificate.Spec.DNSNames).To(ConsistOf(strings.Split(altNames, ",")))
Expect(certificate.Spec.CommonName).To(Equal(domain))
Expect(certificate.Spec.Duration.Duration).To(Equal(duration))
Expect(certificate.Spec.RenewBefore.Duration).To(Equal(renewBefore))
Expand Down