Skip to content

Commit 698397b

Browse files
ivanmatmatiMo3m3n
authored andcommitted
BUG/MINOR: fix clean-certs default behavior
Fix that default behavior does not remove unused certificates.
1 parent c954b43 commit 698397b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

controller/annotations/annotations.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,22 @@ func SetDefaultValue(annotation, value string) {
130130
}
131131

132132
func Bool(name string, annotations ...map[string]string) (out bool, err error) {
133+
boolean, err := ParseBool(name, annotations...)
134+
out = boolean == "true"
135+
return
136+
}
137+
138+
func ParseBool(name string, annotations ...map[string]string) (out string, err error) {
133139
input := common.GetValue(name, annotations...)
134140
if input == "" {
135141
return
136142
}
137-
out, err = utils.GetBoolValue(input, name)
143+
_, err = utils.GetBoolValue(input, name)
138144
if err != nil {
139145
err = fmt.Errorf("%s annotation: %w", name, err)
140146
return
141147
}
148+
out = input
142149
return
143150
}
144151

controller/handler/refresh.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ import (
2424
type Refresh struct{}
2525

2626
func (h Refresh) Update(k store.K8s, cfg *config.ControllerCfg, api api.HAProxyClient) (reload bool, err error) {
27-
var cleanCrts bool
28-
cleanCrts, err = annotations.Bool("clean-certs", k.ConfigMaps.Main.Annotations)
29-
if err != nil {
30-
cleanCrts = true
31-
}
32-
if cleanCrts {
27+
cleanCrtsAnn, err := annotations.ParseBool("clean-certs", k.ConfigMaps.Main.Annotations)
28+
// cleanCrtsAnn is empty if clean-certs not set or set with a non boolean value => error
29+
if cleanCrtsAnn == "" || cleanCrtsAnn == "true" {
3330
reload = cfg.Certificates.Refresh() || reload
3431
}
3532
reload = cfg.HAProxyRules.Refresh(api) || reload

controller/haproxy/certs/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func refreshCerts(certs map[string]*cert, certDir string) (reload bool) {
175175
logger.Error(os.Remove(path.Join(certDir, filename)))
176176
delete(certs, certName)
177177
reload = true
178-
logger.Debug("secret %s removed, reload required", crt.name)
178+
logger.Debugf("secret %s removed, reload required", crt.name)
179179
}
180180
}
181181
return

0 commit comments

Comments
 (0)