Skip to content

Commit

Permalink
Cherry-pick elastic#21880 to 7.9: Stop storing stateless kubernetes k…
Browse files Browse the repository at this point in the history
…eystores (elastic#21985)
  • Loading branch information
ChrsMark authored Oct 20, 2020
1 parent ea5d7f6 commit 4950c95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix overflow on Prometheus rates when new buckets are added on the go. {pull}17753[17753]
- Add a switch to the driver definition on SQL module to use pretty names {pull}17378[17378]
- Fix remote_write flaky test. {pull}21173[21173]
- Fix panic in kubernetes autodiscover related to keystores {issue}21843[21843] {pull}21880[21880]

*Packetbeat*

Expand Down
20 changes: 5 additions & 15 deletions libbeat/common/kubernetes/k8skeystore/kubernetes_keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ import (
"github.com/elastic/beats/v7/libbeat/logp"
)

type KubernetesKeystores map[string]keystore.Keystore

// KubernetesKeystoresRegistry holds KubernetesKeystores for known namespaces. Once a Keystore for one k8s namespace
// is initialized it will be reused every time it is needed.
// KubernetesKeystoresRegistry implements a Provider for Keystore.
type KubernetesKeystoresRegistry struct {
kubernetesKeystores KubernetesKeystores
logger *logp.Logger
client k8s.Interface
logger *logp.Logger
client k8s.Interface
}

// KubernetesSecretsKeystore allows to retrieve passwords from Kubernetes secrets for a given namespace
Expand All @@ -56,9 +52,8 @@ func Factoryk8s(keystoreNamespace string, ks8client k8s.Interface, logger *logp.
// NewKubernetesKeystoresRegistry initializes a KubernetesKeystoresRegistry
func NewKubernetesKeystoresRegistry(logger *logp.Logger, client k8s.Interface) keystore.Provider {
return &KubernetesKeystoresRegistry{
kubernetesKeystores: KubernetesKeystores{},
logger: logger,
client: client,
logger: logger,
client: client,
}
}

Expand All @@ -75,12 +70,7 @@ func (kr *KubernetesKeystoresRegistry) GetKeystore(event bus.Event) keystore.Key
namespace = ns.(string)
}
if namespace != "" {
// either retrieve already stored keystore or create a new one for the namespace
if storedKeystore, ok := kr.kubernetesKeystores[namespace]; ok {
return storedKeystore
}
k8sKeystore, _ := Factoryk8s(namespace, kr.client, kr.logger)
kr.kubernetesKeystores["namespace"] = k8sKeystore
return k8sKeystore
}
kr.logger.Debugf("Cannot retrieve kubernetes namespace from event: %s", event)
Expand Down

0 comments on commit 4950c95

Please sign in to comment.