Skip to content

Commit

Permalink
[autodiscover] - Providing config option to disable Kubeadm config ap…
Browse files Browse the repository at this point in the history
…i requests (#98)

Related changes needed for elastic/beats#40086
  • Loading branch information
gizas authored Aug 12, 2024
1 parent a0803d1 commit 8d70795
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions kubernetes/metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

// Config declares supported configuration for metadata generation
type Config struct {
KubeConfig string `config:"kube_config"`

KubeConfig string `config:"kube_config"`
KubeAdm bool `config:"use_kubeadm"`
UseRegexInclude bool `config:"use_regex_include"`
UseRegexExclude bool `config:"use_regex_exclude"`
IncludeLabels []string `config:"include_labels"`
Expand All @@ -45,6 +45,7 @@ type AddResourceMetadataConfig struct {

// InitDefaults initializes the defaults for the config.
func (c *Config) InitDefaults() {
c.KubeAdm = true
c.LabelsDedot = true
c.AnnotationsDedot = true
c.UseRegexInclude = false
Expand Down
11 changes: 7 additions & 4 deletions kubernetes/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func GetPodMetaGen(
replicasetWatcher kubernetes.Watcher,
jobWatcher kubernetes.Watcher,
metaConf *AddResourceMetadataConfig) MetaGen {

var nodeMetaGen, namespaceMetaGen, rsMetaGen, jobMetaGen MetaGen
if nodeWatcher != nil && metaConf.Node.Enabled() {
nodeMetaGen = NewNodeMetadataGenerator(metaConf.Node, nodeWatcher.Store(), nodeWatcher.Client())
Expand Down Expand Up @@ -134,19 +133,23 @@ func GetKubernetesClusterIdentifier(cfg *config.C, client k8sclient.Interface) (
if err == nil {
return clusterInfo, nil
}
// try with kubeadm-config configmap
clusterInfo, err = getClusterInfoFromKubeadmConfigMap(client)

// try with kubeadm-config configmap only if config_kubeAdm == true
clusterInfo, err = getClusterInfoFromKubeadmConfigMap(client, c.KubeAdm)
if err == nil {
return clusterInfo, nil
}
return ClusterInfo{}, fmt.Errorf("unable to retrieve cluster identifiers")
}

func getClusterInfoFromKubeadmConfigMap(client k8sclient.Interface) (ClusterInfo, error) {
func getClusterInfoFromKubeadmConfigMap(client k8sclient.Interface, kubeadm bool) (ClusterInfo, error) {
clusterInfo := ClusterInfo{}
if client == nil {
return clusterInfo, fmt.Errorf("unable to get cluster identifiers from kubeadm-config")
}
if !kubeadm {
return clusterInfo, nil
}
cm, err := client.CoreV1().ConfigMaps("kube-system").Get(context.TODO(), "kubeadm-config", metav1.GetOptions{})
if err != nil {
return clusterInfo, fmt.Errorf("unable to get cluster identifiers from kubeadm-config: %w", err)
Expand Down

0 comments on commit 8d70795

Please sign in to comment.