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

Commit

Permalink
Keep one of the duplicated secrets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ankon committed May 19, 2017
1 parent a4bf789 commit ccd0d04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
38 changes: 18 additions & 20 deletions pkg/kubelego/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,26 @@ func (kl *KubeLego) TlsIgnoreDuplicatedSecrets(tlsSlice []kubelego.Tls) []kubele

output := []kubelego.Tls{}
for key, slice := range tlsBySecret {
if len(slice) == 1 {
output = append(output, slice...)
continue
}

texts := []string{}
for _, elem := range slice {
texts = append(
texts,
fmt.Sprintf(
"ingress %s/%s (hosts: %s)",
elem.IngressMetadata().Namespace,
elem.IngressMetadata().Name,
strings.Join(elem.Hosts(), ", "),
),
output = append(output, slice[0])
if len(slice) > 1 {
texts := []string{}
for _, elem := range slice[1:] {
texts = append(
texts,
fmt.Sprintf(
"ingress %s/%s (hosts: %s)",
elem.IngressMetadata().Namespace,
elem.IngressMetadata().Name,
strings.Join(elem.Hosts(), ", "),
),
)
}
kl.Log().Warnf(
"the secret %s is used multiple times. These linked TLS ingress elements where ignored: %s",
key,
strings.Join(texts, ", "),
)
}
kl.Log().Warnf(
"the secret %s is used multiple times. These linked TLS ingress elements where ignored: %s",
key,
strings.Join(texts, ", "),
)
}

return output
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelego/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ func TestKubeLego_TlsIgnoreDuplicatedSecrets(t *testing.T) {
k := New("test")
input := getTlsExample()
output := k.TlsIgnoreDuplicatedSecrets(input)
assert.EqualValues(t, 2, len(output))
assert.EqualValues(t, 3, len(output))
}

0 comments on commit ccd0d04

Please sign in to comment.