Remove defaulting behaviour
Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
This commit is contained in:
parent
33b59460d1
commit
9844658e73
@ -308,28 +308,10 @@ func (c *controller) setIssuerSpecificConfig(crt *cmapi.Certificate, ing *extv1b
|
||||
}
|
||||
|
||||
func (c *controller) setCommonName(crt *cmapi.Certificate, ing *extv1beta1.Ingress, tls extv1beta1.IngressTLS) {
|
||||
ingAnnotations := ing.Annotations
|
||||
if ingAnnotations == nil {
|
||||
ingAnnotations = map[string]string{}
|
||||
}
|
||||
|
||||
// if annotation is set use that as CN
|
||||
if ingAnnotations[cmapi.CommonNameAnnotationKey] != "" {
|
||||
crt.Spec.CommonName = ingAnnotations[cmapi.CommonNameAnnotationKey]
|
||||
return
|
||||
if ing.Annotations != nil && ing.Annotations[cmapi.CommonNameAnnotationKey] != "" {
|
||||
crt.Spec.CommonName = ing.Annotations[cmapi.CommonNameAnnotationKey]
|
||||
}
|
||||
|
||||
// if not set pick the first DNS name that is less than 64 characters
|
||||
// this is the length limit of the CN
|
||||
// if none if found we leave the CN empty
|
||||
for _, host := range tls.Hosts {
|
||||
if len(host) < 64 {
|
||||
crt.Spec.CommonName = host
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// shouldSync returns true if this ingress should have a Certificate resource
|
||||
|
||||
@ -195,60 +195,6 @@ func TestSync(t *testing.T) {
|
||||
"awaytoolongdomainnameforthecommonnamefielstoballowedinsoithastopicktheotherone.example.org",
|
||||
"example.com",
|
||||
},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
Kind: "ClusterIssuer",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "return a single Certificate for an ingress with all hosts over the CM length limit",
|
||||
Issuer: acmeClusterIssuer,
|
||||
Ingress: &extv1beta1.Ingress{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "ingress-name",
|
||||
Namespace: gen.DefaultTestNamespace,
|
||||
Labels: map[string]string{
|
||||
"my-test-label": "should be copied",
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
cmapi.IngressClusterIssuerNameAnnotationKey: "issuer-name",
|
||||
},
|
||||
UID: types.UID("ingress-name"),
|
||||
},
|
||||
Spec: extv1beta1.IngressSpec{
|
||||
TLS: []extv1beta1.IngressTLS{
|
||||
{
|
||||
Hosts: []string{
|
||||
"awaytoolongdomainnameforthecommonnamefielstoballowedinsoithastopicktheotherone.example.com",
|
||||
"awaytoolongdomainnameforthecommonnamefielstoballowedinsoithastopicktheotherone.example.org",
|
||||
},
|
||||
SecretName: "example-com-tls",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ClusterIssuerLister: []runtime.Object{acmeClusterIssuer},
|
||||
ExpectedEvents: []string{`Normal CreateCertificate Successfully created Certificate "example-com-tls"`},
|
||||
ExpectedCreate: []*cmapi.Certificate{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "example-com-tls",
|
||||
Namespace: gen.DefaultTestNamespace,
|
||||
Labels: map[string]string{
|
||||
"my-test-label": "should be copied",
|
||||
},
|
||||
OwnerReferences: buildOwnerReferences("ingress-name", gen.DefaultTestNamespace),
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{
|
||||
"awaytoolongdomainnameforthecommonnamefielstoballowedinsoithastopicktheotherone.example.com",
|
||||
"awaytoolongdomainnameforthecommonnamefielstoballowedinsoithastopicktheotherone.example.org",
|
||||
},
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -301,7 +247,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -354,7 +299,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -396,7 +340,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -439,7 +382,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -486,7 +428,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -530,7 +471,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -573,7 +513,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -618,7 +557,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com", "www.example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "example-com-tls",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -724,7 +662,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "existing-crt",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -883,7 +820,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "existing-crt",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -925,7 +861,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "existing-crt",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -958,7 +893,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "existing-crt",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
@ -977,7 +911,6 @@ func TestSync(t *testing.T) {
|
||||
},
|
||||
Spec: cmapi.CertificateSpec{
|
||||
DNSNames: []string{"example.com"},
|
||||
CommonName: "example.com",
|
||||
SecretName: "existing-crt",
|
||||
IssuerRef: cmmeta.ObjectReference{
|
||||
Name: "issuer-name",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user