Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Commit ccd0d04

Browse files
committed
Keep one of the duplicated secrets
There is really no problem with duplicated secrets: these exist, and will be shared by the ingresses that refer to them. The existing code excluded a secret as soon as it was referenced by more one than place, but we should really just de-duplicate the given list based on namespace/name.
1 parent a4bf789 commit ccd0d04

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

pkg/kubelego/configure.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,26 @@ func (kl *KubeLego) TlsIgnoreDuplicatedSecrets(tlsSlice []kubelego.Tls) []kubele
2626

2727
output := []kubelego.Tls{}
2828
for key, slice := range tlsBySecret {
29-
if len(slice) == 1 {
30-
output = append(output, slice...)
31-
continue
32-
}
33-
34-
texts := []string{}
35-
for _, elem := range slice {
36-
texts = append(
37-
texts,
38-
fmt.Sprintf(
39-
"ingress %s/%s (hosts: %s)",
40-
elem.IngressMetadata().Namespace,
41-
elem.IngressMetadata().Name,
42-
strings.Join(elem.Hosts(), ", "),
43-
),
29+
output = append(output, slice[0])
30+
if len(slice) > 1 {
31+
texts := []string{}
32+
for _, elem := range slice[1:] {
33+
texts = append(
34+
texts,
35+
fmt.Sprintf(
36+
"ingress %s/%s (hosts: %s)",
37+
elem.IngressMetadata().Namespace,
38+
elem.IngressMetadata().Name,
39+
strings.Join(elem.Hosts(), ", "),
40+
),
41+
)
42+
}
43+
kl.Log().Warnf(
44+
"the secret %s is used multiple times. These linked TLS ingress elements where ignored: %s",
45+
key,
46+
strings.Join(texts, ", "),
4447
)
4548
}
46-
kl.Log().Warnf(
47-
"the secret %s is used multiple times. These linked TLS ingress elements where ignored: %s",
48-
key,
49-
strings.Join(texts, ", "),
50-
)
5149
}
5250

5351
return output

pkg/kubelego/configure_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ func TestKubeLego_TlsIgnoreDuplicatedSecrets(t *testing.T) {
7272
k := New("test")
7373
input := getTlsExample()
7474
output := k.TlsIgnoreDuplicatedSecrets(input)
75-
assert.EqualValues(t, 2, len(output))
75+
assert.EqualValues(t, 3, len(output))
7676
}

0 commit comments

Comments
 (0)