Skip to content

Commit

Permalink
Parse arguments before using it in config (open-telemetry#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvp8510 authored Jan 12, 2022
1 parent ecac8e4 commit 8d06da5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
13 changes: 0 additions & 13 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/spf13/pflag"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/open-telemetry/opentelemetry-operator/internal/version"
Expand Down Expand Up @@ -85,18 +84,6 @@ func New(opts ...Option) Config {
}
}

// FlagSet binds the flags to the user-modifiable values of the operator's configuration.
func (c *Config) FlagSet() *pflag.FlagSet {
fs := pflag.NewFlagSet("opentelemetry-operator", pflag.ExitOnError)
pflag.StringVar(&c.collectorImage,
"otelcol-image",
c.collectorImage,
"The default image to use for OpenTelemetry Collector when not specified in the individual custom resource (CR)",
)

return fs
}

// StartAutoDetect attempts to automatically detect relevant information for this operator. This will block until the first
// run is executed and will schedule periodic updates.
func (c *Config) StartAutoDetect() error {
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func main() {
pflag.StringVar(&autoInstrumentationJava, "auto-instrumentation-java-image", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:%s", v.AutoInstrumentationJava), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.")
pflag.StringVar(&autoInstrumentationNodeJS, "auto-instrumentation-nodejs-image", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:%s", v.AutoInstrumentationNodeJS), "The default OpenTelemetry NodeJS instrumentation image. This image is used when no image is specified in the CustomResource.")
pflag.StringVar(&autoInstrumentationPython, "auto-instrumentation-python-image", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:%s", v.AutoInstrumentationPython), "The default OpenTelemetry Python instrumentation image. This image is used when no image is specified in the CustomResource.")
pflag.Parse()

logger := zap.New(zap.UseFlagOptions(&opts))
ctrl.SetLogger(logger)
Expand Down Expand Up @@ -126,10 +127,6 @@ func main() {
config.WithAutoDetect(ad),
)

pflag.CommandLine.AddFlagSet(cfg.FlagSet())

pflag.Parse()

watchNamespace, found := os.LookupEnv("WATCH_NAMESPACE")
if found {
setupLog.Info("watching namespace(s)", "namespaces", watchNamespace)
Expand Down

0 comments on commit 8d06da5

Please sign in to comment.