Skip to content

Commit 456bb4b

Browse files
committed
Cleanup comments, log delete failed message as a warning and fix exported
names as per @{pravisankar,Miciah,knobunc} review comments.
1 parent f7a7227 commit 456bb4b

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

pkg/router/template/certmanager.go

+15-19
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ import (
1414

1515
// certificateFile represents a certificate file.
1616
type certificateFile struct {
17-
CertDir string
18-
ID string
19-
Contents []byte
17+
certDir string
18+
id string
2019
}
2120

22-
// certificateFileTag generates a certificate file tag/name. This is used to
23-
// index into the map of deleted certificates.
21+
// Tag generates a certificate file tag/name. This is used to index into the
22+
// the map of deleted certificates.
2423
func (cf certificateFile) Tag() string {
25-
return filepath.Join(cf.CertDir, cf.ID+".pem")
24+
return filepath.Join(cf.certDir, cf.id+".pem")
2625
}
2726

2827
// simpleCertificateManager is the default implementation of a certificateManager
@@ -96,7 +95,7 @@ func (cm *simpleCertificateManager) WriteCertificatesForConfig(config *ServiceAl
9695
buffer.Write([]byte(caCertObj.Contents))
9796
}
9897

99-
certFile := certificateFile{CertDir: cm.cfg.certDir, ID: certObj.ID}
98+
certFile := certificateFile{certDir: cm.cfg.certDir, id: certObj.ID}
10099
delete(cm.deletedCertificates, certFile.Tag())
101100
if err := cm.w.WriteCertificate(cm.cfg.certDir, certObj.ID, buffer.Bytes()); err != nil {
102101
return err
@@ -109,7 +108,7 @@ func (cm *simpleCertificateManager) WriteCertificatesForConfig(config *ServiceAl
109108
destCert, ok := config.Certificates[destCertKey]
110109

111110
if ok {
112-
destCertFile := certificateFile{CertDir: cm.cfg.caCertDir, ID: destCert.ID}
111+
destCertFile := certificateFile{certDir: cm.cfg.caCertDir, id: destCert.ID}
113112
delete(cm.deletedCertificates, destCertFile.Tag())
114113
if err := cm.w.WriteCertificate(cm.cfg.caCertDir, destCert.ID, []byte(destCert.Contents)); err != nil {
115114
return err
@@ -131,7 +130,7 @@ func (cm *simpleCertificateManager) DeleteCertificatesForConfig(config *ServiceA
131130
certObj, ok := config.Certificates[certKey]
132131

133132
if ok {
134-
certFile := certificateFile{CertDir: cm.cfg.certDir, ID: certObj.ID}
133+
certFile := certificateFile{certDir: cm.cfg.certDir, id: certObj.ID}
135134
cm.deletedCertificates[certFile.Tag()] = certFile
136135
}
137136
}
@@ -141,8 +140,7 @@ func (cm *simpleCertificateManager) DeleteCertificatesForConfig(config *ServiceA
141140
destCert, ok := config.Certificates[destCertKey]
142141

143142
if ok {
144-
145-
destCertFile := certificateFile{CertDir: cm.cfg.caCertDir, ID: destCert.ID}
143+
destCertFile := certificateFile{certDir: cm.cfg.caCertDir, id: destCert.ID}
146144
cm.deletedCertificates[destCertFile.Tag()] = destCertFile
147145
}
148146
}
@@ -157,21 +155,19 @@ func (cm *simpleCertificateManager) Commit() error {
157155
// reload because the config is invalid, so we _do_ need to "stage"
158156
// or commit the removals. Remove all the deleted certificates.
159157
for _, certFile := range cm.deletedCertificates {
160-
err := cm.w.DeleteCertificate(certFile.CertDir, certFile.ID)
158+
err := cm.w.DeleteCertificate(certFile.certDir, certFile.id)
161159
if err != nil {
162-
// TODO: Do we care if a file deletion failed?
163-
// Otherwise we will keep hitting this error on
164-
// every commit. Should we just ignore errors here?
165-
// Clean this up based on review comments.
166-
// FIXME: return err
160+
// Log a warning if the delete fails but proceed on.
161+
glog.Warningf("Ignoring error deleting certificate file %v: %v", certFile.Tag(), err)
167162
}
168163
}
169164

170165
cm.deletedCertificates = make(map[string]certificateFile, 0)
171166

172167
// If we decide to stage the certificate writes, we can flush the
173-
// write to the disk here. The tradeoff is storing a copy in memory
174-
// until we commit.
168+
// write to the disk here. Today, the certificate writes are done
169+
// just before this function is called. The tradeoff is storing a
170+
// copy in memory until we commit.
175171

176172
return nil
177173
}

0 commit comments

Comments
 (0)