Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[autodiscover] - Providing config option to disable Kubeadm config api requests #98

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading