diff --git a/kubernetes/metadata/config.go b/kubernetes/metadata/config.go index f60b2b1eb..eafbb9dbd 100644 --- a/kubernetes/metadata/config.go +++ b/kubernetes/metadata/config.go @@ -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"` @@ -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 diff --git a/kubernetes/metadata/metadata.go b/kubernetes/metadata/metadata.go index dc5406790..4db4874be 100644 --- a/kubernetes/metadata/metadata.go +++ b/kubernetes/metadata/metadata.go @@ -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()) @@ -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)