Skip to content

Commit

Permalink
Remove hard-coded namespace from k8s config
Browse files Browse the repository at this point in the history
The default namespace should be populated by the Kubernetes client. In the case
of in-cluster config, the namespace will be read from the
/var/run/secrets/kubernetes.io/serviceaccount/namespace file. (Note that this
assumes the ServiceAccount admission controller is in use.) In the case of
parsing a k8s configuration file, the default namespace is set to the client
default of "default".

Minor spelling correction of Kubernetes and some additional error information
was changed as well.

Closes #5378
  • Loading branch information
jpeeler authored and Jeff Peeler committed Oct 31, 2017
1 parent b8b7f8a commit e20beda
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Do not require template if index change and template disabled {pull}5319[5319]
- Correctly send configured `Host` header to the remote server. {issue}4842[4842]
- Fix missing ACK in redis output. {issue}5404[5404]
- Change add_kubernetes_metadata to attempt detection of namespace. {pull}5482[5482]

*Auditbeat*

Expand Down
3 changes: 1 addition & 2 deletions libbeat/processors/add_kubernetes_metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ type Enabled struct {

type PluginConfig []map[string]common.Config

func defaultKuberentesAnnotatorConfig() kubeAnnotatorConfig {
func defaultKubernetesAnnotatorConfig() kubeAnnotatorConfig {
return kubeAnnotatorConfig{
InCluster: true,
SyncPeriod: 1 * time.Second,
CleanupTimeout: 60 * time.Second,
Namespace: "kube-system",
DefaultMatchers: Enabled{true},
DefaultIndexers: Enabled{true},
}
Expand Down
8 changes: 4 additions & 4 deletions libbeat/processors/add_kubernetes_metadata/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) {
cfgwarn.Beta("The kubernetes processor is beta")

config := defaultKuberentesAnnotatorConfig()
config := defaultKubernetesAnnotatorConfig()

err := cfg.Unpack(&config)
if err != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) {
if config.InCluster == true {
client, err = k8s.NewInClusterClient()
if err != nil {
return nil, fmt.Errorf("Unable to get in cluster configuration")
return nil, fmt.Errorf("Unable to get in cluster configuration: %v", err)
}
} else {
data, err := ioutil.ReadFile(config.KubeConfig)
Expand All @@ -109,11 +109,11 @@ func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) {
ctx := context.Background()
if config.Host == "" {
podName := os.Getenv("HOSTNAME")
logp.Info("Using pod name %s and namespace %s", podName, config.Namespace)
logp.Info("Using pod name %s and namespace %s", podName, client.Namespace)
if podName == "localhost" {
config.Host = "localhost"
} else {
pod, error := client.CoreV1().GetPod(ctx, podName, config.Namespace)
pod, error := client.CoreV1().GetPod(ctx, podName, client.Namespace)
if error != nil {
logp.Err("Querying for pod failed with error: ", error.Error())
logp.Info("Unable to find pod, setting host to localhost")
Expand Down

0 comments on commit e20beda

Please sign in to comment.