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

[WIP] Add AWS Cloud Map support for collector discovery #3532

Closed
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add runtime - kubernetes, to avoid mandatory loading of k8s config
vape-spryker committed Nov 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 77cbc71b177a422c14927b572dde6aefc22434c5
38 changes: 28 additions & 10 deletions cmd/otel-allocator/config/config.go
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ type Config struct {
PrometheusCR PrometheusCRConfig `yaml:"prometheus_cr,omitempty"`
HTTPS HTTPSServerConfig `yaml:"https,omitempty"`
CollectorWatcher CollectorWatcherConfig `yaml:"collector_watcher,omitempty"`
Runtime RuntimeConfig `yaml:"runtime,omitempty"`
}

type PrometheusCRConfig struct {
@@ -87,6 +88,14 @@ type AwsCloudMapConfig struct {
ServiceName string `yaml:"service_name,omitempty"`
}

type RuntimeConfig struct {
Kubernetes KubernetesRuntimeConfig `yaml:"kubernetes,omitempty"`
}

type KubernetesRuntimeConfig struct {
Enabled bool `yaml:"enabled,omitempty"`
}

func LoadFromFile(file string, target *Config) error {
return unmarshal(target, file)
}
@@ -102,19 +111,28 @@ func LoadFromCLI(target *Config, flagSet *pflag.FlagSet) error {
if err != nil {
return err
}
clusterConfig, err := clientcmd.BuildConfigFromFlags("", target.KubeConfigFilePath)
if err != nil {
pathError := &fs.PathError{}
if ok := errors.As(err, &pathError); !ok {
return err
}
clusterConfig, err = rest.InClusterConfig()

if runtimeKubernetesEnabled, changed, flagErr := getRuntimeKubernetesEnabled(flagSet); flagErr != nil {
return flagErr
} else if changed {
target.Runtime.Kubernetes.Enabled = runtimeKubernetesEnabled
}

if target.Runtime.Kubernetes.Enabled {
clusterConfig, err := clientcmd.BuildConfigFromFlags("", target.KubeConfigFilePath)
if err != nil {
return err
pathError := &fs.PathError{}
if ok := errors.As(err, &pathError); !ok {
return err
}
clusterConfig, err = rest.InClusterConfig()
if err != nil {
return err
}
target.KubeConfigFilePath = ""
}
target.KubeConfigFilePath = ""
target.ClusterConfig = clusterConfig
}
target.ClusterConfig = clusterConfig

target.ListenAddr, err = getListenAddr(flagSet)
if err != nil {
36 changes: 23 additions & 13 deletions cmd/otel-allocator/config/flags.go
Original file line number Diff line number Diff line change
@@ -25,19 +25,20 @@ import (

// Flag names.
const (
targetAllocatorName = "target-allocator"
configFilePathFlagName = "config-file"
listenAddrFlagName = "listen-addr"
prometheusCREnabledFlagName = "enable-prometheus-cr-watcher"
kubeConfigPathFlagName = "kubeconfig-path"
httpsEnabledFlagName = "enable-https-server"
listenAddrHttpsFlagName = "listen-addr-https"
httpsCAFilePathFlagName = "https-ca-file"
httpsTLSCertFilePathFlagName = "https-tls-cert-file"
httpsTLSKeyFilePathFlagName = "https-tls-key-file"
collectorWatcherTypeFlagName = "collector-watcher-type"
awsCloudMapNamespaceFlagName = "aws-cloud-map-namespace"
awsCloudMapServiceNameFlagName = "aws-cloud-map-service-name"
targetAllocatorName = "target-allocator"
configFilePathFlagName = "config-file"
listenAddrFlagName = "listen-addr"
prometheusCREnabledFlagName = "enable-prometheus-cr-watcher"
kubeConfigPathFlagName = "kubeconfig-path"
httpsEnabledFlagName = "enable-https-server"
listenAddrHttpsFlagName = "listen-addr-https"
httpsCAFilePathFlagName = "https-ca-file"
httpsTLSCertFilePathFlagName = "https-tls-cert-file"
httpsTLSKeyFilePathFlagName = "https-tls-key-file"
collectorWatcherTypeFlagName = "collector-watcher-type"
awsCloudMapNamespaceFlagName = "aws-cloud-map-namespace"
awsCloudMapServiceNameFlagName = "aws-cloud-map-service-name"
runtimeKubernetesEnabledFlagName = "runtime-kubernetes-enabled"
)

// We can't bind this flag to our FlagSet, so we need to handle it separately.
@@ -155,3 +156,12 @@ func getAWSCloudMapServiceName(flagSet *pflag.FlagSet) (value string, changed bo
value, err = flagSet.GetString(awsCloudMapServiceNameFlagName)
return
}

func getRuntimeKubernetesEnabled(flagSet *pflag.FlagSet) (value bool, changed bool, err error) {
if changed = flagSet.Changed(runtimeKubernetesEnabledFlagName); !changed {
value, err = true, nil
return
}
value, err = flagSet.GetBool(runtimeKubernetesEnabledFlagName)
return
}