refactor logic and check for error

This commit is contained in:
Tony Li 2017-02-03 17:23:40 -05:00
parent 7e354fe3fc
commit 172206c32b

View file

@ -352,32 +352,33 @@ func (l *L7) deleteOldSSLCert() (err error) {
} }
func (l *L7) checkSSLCert() (err error) { func (l *L7) checkSSLCert() (err error) {
// TODO: Currently, GCE only supports a single certificate per static IP certName := l.runtimeInfo.TLSName
// so we don't need to bother with disambiguation. Naming the cert after
// the loadbalancer is a simplification.
namedCert := l.runtimeInfo.TLSName
// Use the named GCE cert when it is specified by the annotation. // Use the named GCE cert when it is specified by the annotation.
if namedCert != "" { if certName != "" {
certName := namedCert // Use the targetHTTPSProxy's cert name if it already has one set.
// Use the targetHTTPSProxy's cert name if one already exists.
if l.sslCert != nil { if l.sslCert != nil {
certName = l.sslCert.Name certName = l.sslCert.Name
} }
cert, _ := l.cloud.GetSslCertificate(certName)
if cert != nil { // Ask GCE for the cert, checking for problems and existence.
glog.Infof("Using existing sslCertificate %v for %v", certName, l.Name) cert, err := l.cloud.GetSslCertificate(certName)
if err != nil {
l.sslCert = cert return err
return nil }
if cert == nil {
return fmt.Errorf("Cannot find existing sslCertificate %v for %v", certName, l.Name)
} }
return fmt.Errorf("Cannot find existing sslCertificate %v for %v", certName, l.Name) glog.Infof("Using existing sslCertificate %v for %v", certName, l.Name)
l.sslCert = cert
return nil
} }
// TODO: Currently, GCE only supports a single certificate per static IP
// so we don't need to bother with disambiguation. Naming the cert after
// the loadbalancer is a simplification.
ingCert := l.runtimeInfo.TLS.Cert ingCert := l.runtimeInfo.TLS.Cert
ingKey := l.runtimeInfo.TLS.Key ingKey := l.runtimeInfo.TLS.Key
@ -387,7 +388,7 @@ func (l *L7) checkSSLCert() (err error) {
// TODO: Clean this code up into a ring buffer. // TODO: Clean this code up into a ring buffer.
primaryCertName := l.namer.Truncate(fmt.Sprintf("%v-%v", sslCertPrefix, l.Name)) primaryCertName := l.namer.Truncate(fmt.Sprintf("%v-%v", sslCertPrefix, l.Name))
secondaryCertName := l.namer.Truncate(fmt.Sprintf("%v-%d-%v", sslCertPrefix, 1, l.Name)) secondaryCertName := l.namer.Truncate(fmt.Sprintf("%v-%d-%v", sslCertPrefix, 1, l.Name))
certName := primaryCertName certName = primaryCertName
if l.sslCert != nil { if l.sslCert != nil {
certName = l.sslCert.Name certName = l.sslCert.Name
} }