Replace reflect.DeepEqual with crtEqual

This commit is contained in:
Louis Taylor 2018-03-12 14:00:16 +00:00
parent 801888f0f0
commit 2e5619b1d5
No known key found for this signature in database
GPG Key ID: 8E81A6DAE13E7098
2 changed files with 35 additions and 4 deletions

View File

@ -3,7 +3,6 @@ package controller
import (
"context"
"fmt"
"reflect"
"strconv"
"github.com/golang/glog"
@ -62,7 +61,7 @@ func (c *Controller) Sync(ctx context.Context, ing *extv1beta1.Ingress) error {
if err != nil {
return err
}
c.Recorder.Eventf(ing, corev1.EventTypeNormal, "CreateCertificate", "Successfully updated Certificate %q", crt.Name)
c.Recorder.Eventf(ing, corev1.EventTypeNormal, "UpdateCertificate", "Successfully updated Certificate %q", crt.Name)
}
return nil
@ -117,7 +116,7 @@ func (c *Controller) buildCertificates(ing *extv1beta1.Ingress) (new, update []*
if existingCrt != nil {
glog.Infof("Certificate %q for ingress %q already exists", tls.SecretName, ing.Name)
if reflect.DeepEqual(existingCrt.Spec, crt.Spec) && existingCrt.Name == crt.Name {
if crtEqual(existingCrt, crt) {
glog.Infof("Certificate %q for ingress %q is up to date", tls.SecretName, ing.Name)
continue
}
@ -136,6 +135,37 @@ func (c *Controller) buildCertificates(ing *extv1beta1.Ingress) (new, update []*
return newCrts, updateCrts, nil
}
// crtEqual checks and returns true if two Certificates are equal
func crtEqual(a, b *v1alpha1.Certificate) bool {
if a.Name != b.Name {
return false
}
if len(a.Spec.DNSNames) != len(b.Spec.DNSNames) {
return false
}
for i := range a.Spec.DNSNames {
if a.Spec.DNSNames[i] != b.Spec.DNSNames[i] {
return false
}
}
if a.Spec.SecretName != b.Spec.SecretName {
return false
}
if a.Spec.IssuerRef.Name != b.Spec.IssuerRef.Name {
return false
}
if a.Spec.IssuerRef.Kind != b.Spec.IssuerRef.Kind {
return false
}
return true
}
func (c *Controller) setIssuerSpecificConfig(crt *v1alpha1.Certificate, issuer v1alpha1.GenericIssuer, ing *extv1beta1.Ingress, tls extv1beta1.IngressTLS) error {
ingAnnotations := ing.Annotations
if ingAnnotations == nil {

View File

@ -339,7 +339,8 @@ func TestBuildCertificates(t *testing.T) {
Name: "ingress-name",
Namespace: "ingress-namespace",
Annotations: map[string]string{
issuerNameAnnotation: "issuer-name",
issuerNameAnnotation: "issuer-name",
acmeIssuerChallengeTypeAnnotation: "http01",
},
},
Spec: extv1beta1.IngressSpec{