-
Notifications
You must be signed in to change notification settings - Fork 460
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
[targetallocator] PrometheusOperator CRD MVC #653
Changes from 16 commits
4a72ffb
626d002
b71d1f2
727493b
f6a1996
f12336d
d5c90ea
24275d0
0da5fa8
8a29f22
077c0c4
78161df
28fc0c9
bb21889
c18ac42
acc07c5
8b7d8bf
1b249ca
2f5e0b3
f665de5
e23a2c5
0a429a7
92a55d5
96cea47
45a0e84
7d3f036
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,11 +120,21 @@ type OpenTelemetryTargetAllocator struct { | |
// +optional | ||
Enabled bool `json:"enabled,omitempty"` | ||
|
||
// PrometheusCR defines the configuration for Prometheus custom resource retrieval. | ||
// +optional | ||
PrometheusCR OpenTelemetryTargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"` | ||
|
||
// Image indicates the container image to use for the OpenTelemetry TargetAllocator. | ||
// +optional | ||
Image string `json:"image,omitempty"` | ||
} | ||
|
||
type OpenTelemetryTargetAllocatorPrometheusCR struct { | ||
// Enabled indicates whether to use a Prometheus custom resources as target or not. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which p8s CR does it use? Can there be multiple in a namespace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is a MVC all instances of |
||
// +optional | ||
Enabled bool `json:"enabled,omitempty"` | ||
} | ||
|
||
// OpenTelemetryCollectorStatus defines the observed state of OpenTelemetryCollector. | ||
type OpenTelemetryCollectorStatus struct { | ||
// Replicas is currently not being set and might be removed in the next version. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,54 @@ package config | |
|
||
import ( | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"io/fs" | ||
"io/ioutil" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/go-logr/logr" | ||
promconfig "github.com/prometheus/prometheus/config" | ||
_ "github.com/prometheus/prometheus/discovery/install" | ||
"github.com/spf13/pflag" | ||
"gopkg.in/yaml.v2" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/util/homedir" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
) | ||
|
||
// ErrInvalidYAML represents an error in the format of the original YAML configuration file. | ||
var ( | ||
ErrInvalidYAML = errors.New("couldn't parse the loadbalancer configuration") | ||
) | ||
|
||
const defaultConfigFile string = "/conf/targetallocator.yaml" | ||
const DefaultResyncTime = 5 * time.Minute | ||
const DefaultConfigFilePath string = "/conf/targetallocator.yaml" | ||
|
||
type Config struct { | ||
LabelSelector map[string]string `yaml:"label_selector,omitempty"` | ||
Config *promconfig.Config `yaml:"config"` | ||
} | ||
|
||
func Load(file string) (Config, error) { | ||
if file == "" { | ||
file = defaultConfigFile | ||
} | ||
type PrometheusCRWatcherConfig struct { | ||
Enabled *bool | ||
} | ||
|
||
type CLIConfig struct { | ||
ListenAddr *string | ||
ConfigFilePath *string | ||
ClusterConfig *rest.Config | ||
// KubeConfigFilePath empty if in cluster configuration is in use | ||
KubeConfigFilePath string | ||
RootLogger logr.Logger | ||
PromCRWatcherConf PrometheusCRWatcherConfig | ||
} | ||
|
||
func Load(file string) (Config, error) { | ||
var cfg Config | ||
if err := unmarshal(&cfg, file); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: It seems previously the allocator would load a default config file if no file was provided, it seems that was because we would always pass in an empty string in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to users of the TargetAllocator or Devs which import this package? In the first case the behavior has not changed. It is still loading the same default file as before. This is implement using pflags now. https://github.com/open-telemetry/opentelemetry-operator/pull/653/files#diff-d292758014333553bcd82dfdf75743ef82b0b32f6414e2dc345777fc342e4480R77 |
||
return Config{}, err | ||
|
@@ -45,3 +68,36 @@ func unmarshal(cfg *Config, configFile string) error { | |
} | ||
return nil | ||
} | ||
|
||
func ParseCLI() (CLIConfig, error) { | ||
opts := zap.Options{} | ||
opts.BindFlags(flag.CommandLine) | ||
cLIConf := CLIConfig{ | ||
ListenAddr: pflag.String("listen-addr", ":8080", "The address where this service serves."), | ||
ConfigFilePath: pflag.String("config-file", DefaultConfigFilePath, "The path to the config file."), | ||
PromCRWatcherConf: PrometheusCRWatcherConfig{ | ||
Enabled: pflag.Bool("enable-prometheus-cr-watcher", false, "Enable Prometheus CRs as target sources"), | ||
}, | ||
} | ||
kubeconfigPath := pflag.String("kubeconfig-path", filepath.Join(homedir.HomeDir(), ".kube", "config"), "absolute path to the KubeconfigPath file") | ||
pflag.Parse() | ||
|
||
cLIConf.RootLogger = zap.New(zap.UseFlagOptions(&opts)) | ||
klog.SetLogger(cLIConf.RootLogger) | ||
ctrl.SetLogger(cLIConf.RootLogger) | ||
|
||
clusterConfig, err := clientcmd.BuildConfigFromFlags("", *kubeconfigPath) | ||
cLIConf.KubeConfigFilePath = *kubeconfigPath | ||
if err != nil { | ||
if _, ok := err.(*fs.PathError); !ok { | ||
return CLIConfig{}, err | ||
} | ||
clusterConfig, err = rest.InClusterConfig() | ||
if err != nil { | ||
return CLIConfig{}, err | ||
} | ||
cLIConf.KubeConfigFilePath = "" // reset as we use in cluster configuration | ||
} | ||
cLIConf.ClusterConfig = clusterConfig | ||
return cLIConf, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What CR is it exactly? could you please document the fully qualified name (group.kind)? (I am playing an ignorant here not knowing anything about p8s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's referring to the
ServiceMonitor
andPodMonitor
CRDs in themonitoring.coreos.com/v1
API