diff --git a/apis/v1/jaeger_types.go b/apis/v1/jaeger_types.go index eccd1203d..dc6e4b2e0 100644 --- a/apis/v1/jaeger_types.go +++ b/apis/v1/jaeger_types.go @@ -36,14 +36,8 @@ const ( // FlagAutoscalingVersionV2Beta2 represents the v2beta2 version of the Kubernetes Autoscaling API, no longer available as of 1.26 FlagAutoscalingVersionV2Beta2 = "autoscaling/v2beta2" - // FlagPlatformKubernetes represents the value for the 'platform' flag for Kubernetes - FlagPlatformKubernetes = "kubernetes" - - // FlagPlatformOpenShift represents the value for the 'platform' flag for OpenShift - FlagPlatformOpenShift = "openshift" - - // FlagPlatformAutoDetect represents the "auto-detect" value for the platform flag - FlagPlatformAutoDetect = "auto-detect" + // FlagPlatform represents the flag to set the platform + FlagPlatform = "platform" // FlagProvisionElasticsearchAuto represents the 'auto' value for the 'es-provision' flag FlagProvisionElasticsearchAuto = "auto" diff --git a/controllers/appsv1/deployment_webhook_test.go b/controllers/appsv1/deployment_webhook_test.go index 521968a72..3a2250a98 100644 --- a/controllers/appsv1/deployment_webhook_test.go +++ b/controllers/appsv1/deployment_webhook_test.go @@ -24,6 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/inject" ) @@ -93,8 +94,7 @@ func TestReconcileConfigMaps(t *testing.T) { errors: tC.errors, } - viper.Set("platform", v1.FlagPlatformOpenShift) - defer viper.Reset() + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) // test err := reconcileConfigMaps(context.Background(), cl, jaeger, &dep) diff --git a/pkg/autodetect/main.go b/pkg/autodetect/main.go index 9bf749ff5..077280a77 100644 --- a/pkg/autodetect/main.go +++ b/pkg/autodetect/main.go @@ -192,10 +192,10 @@ func AvailableAPIs(discovery discovery.DiscoveryInterface, groups map[string]boo func (b *Background) detectPlatform(ctx context.Context, apiList []*metav1.APIResourceList) { // detect the platform, we run this only once, as the platform can't change between runs ;) - platform := viper.GetString("platform") + platform := OperatorConfiguration.GetPlatform() detectedPlatform := "" - if !strings.EqualFold(platform, v1.FlagPlatformAutoDetect) { + if !OperatorConfiguration.IsPlatformAutodetectionEnabled() { log.Log.V(-1).Info( "The 'platform' option is explicitly set", "platform", platform, @@ -205,12 +205,12 @@ func (b *Background) detectPlatform(ctx context.Context, apiList []*metav1.APIRe log.Log.V(-1).Info("Attempting to auto-detect the platform") if isOpenShift(apiList) { - detectedPlatform = v1.FlagPlatformOpenShift + detectedPlatform = OpenShiftPlatform.String() } else { - detectedPlatform = v1.FlagPlatformKubernetes + detectedPlatform = KubernetesPlatform.String() } - viper.Set("platform", detectedPlatform) + OperatorConfiguration.SetPlatform(detectedPlatform) log.Log.Info( "Auto-detected the platform", "platform", detectedPlatform, @@ -222,7 +222,7 @@ func (b *Background) detectOAuthProxyImageStream(ctx context.Context) { ctx, span := tracer.Start(ctx, "detectOAuthProxyImageStream") defer span.End() - if viper.GetString("platform") != v1.FlagPlatformOpenShift { + if OperatorConfiguration.GetPlatform() == OpenShiftPlatform { log.Log.V(-1).Info( "Not running on OpenShift, so won't configure OAuthProxy imagestream.", ) @@ -347,7 +347,7 @@ func (b *Background) detectKafka(_ context.Context, apiList []*metav1.APIResourc } func (b *Background) detectClusterRoles(ctx context.Context) { - if viper.GetString("platform") != v1.FlagPlatformOpenShift { + if OperatorConfiguration.GetPlatform() != OpenShiftPlatform { return } tr := &authenticationapi.TokenReview{ diff --git a/pkg/autodetect/main_test.go b/pkg/autodetect/main_test.go index 6376877cf..7eb690236 100644 --- a/pkg/autodetect/main_test.go +++ b/pkg/autodetect/main_test.go @@ -21,7 +21,7 @@ import ( ) func TestStart(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + OperatorConfiguration.SetPlatform(OpenShiftPlatform) defer viper.Reset() // sanity check @@ -57,7 +57,7 @@ func TestStart(t *testing.T) { } func TestStartContinuesInBackground(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + OperatorConfiguration.SetPlatform(OpenShiftPlatform) defer viper.Reset() // prepare @@ -68,6 +68,9 @@ func TestStartContinuesInBackground(t *testing.T) { } b := WithClients(cl, dcl, cl) + fmt.Println(viper.IsSet("auth-delegator-available")) + fmt.Println(viper.GetBool("auth-delegator-available")) + done := make(chan bool) go func() { for { @@ -85,7 +88,7 @@ func TestStartContinuesInBackground(t *testing.T) { select { case <-done: assert.False(t, viper.GetBool("auth-delegator-available")) - case <-time.After(1 * time.Second): + case <-time.After(5 * time.Second): assert.Fail(t, "timed out waiting for the start process to detect the capabilities") } @@ -97,7 +100,7 @@ func TestStartContinuesInBackground(t *testing.T) { if viper.GetBool("auth-delegator-available") { break } - time.Sleep(500 * time.Millisecond) + time.Sleep(10 * time.Millisecond) } done <- true }() @@ -176,7 +179,7 @@ func TestAutoDetectWithServerResourcesForGroupVersionError(t *testing.T) { func TestAutoDetectOpenShift(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformAutoDetect) + viper.Set("platform", "auto-detect") defer viper.Reset() dcl := &fakeDiscoveryClient{} @@ -197,7 +200,7 @@ func TestAutoDetectOpenShift(t *testing.T) { b.autoDetectCapabilities() // verify - assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform")) + assert.Equal(t, OpenShiftPlatform, OperatorConfiguration.GetPlatform()) // set the error dcl.ServerResourcesForGroupVersionFunc = func(_ string) (apiGroupList *metav1.APIResourceList, err error) { @@ -208,12 +211,12 @@ func TestAutoDetectOpenShift(t *testing.T) { b.autoDetectCapabilities() // verify again - assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform")) + assert.Equal(t, OpenShiftPlatform, OperatorConfiguration.GetPlatform()) } func TestAutoDetectKubernetes(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformAutoDetect) + viper.Set("platform", "auto-detect") defer viper.Reset() dcl := &fakeDiscoveryClient{} @@ -224,12 +227,12 @@ func TestAutoDetectKubernetes(t *testing.T) { b.autoDetectCapabilities() // verify - assert.Equal(t, v1.FlagPlatformKubernetes, viper.GetString("platform")) + assert.Equal(t, KubernetesPlatform, OperatorConfiguration.GetPlatform()) } func TestExplicitPlatform(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + OperatorConfiguration.SetPlatform(OpenShiftPlatform) defer viper.Reset() dcl := &fakeDiscoveryClient{} @@ -240,7 +243,7 @@ func TestExplicitPlatform(t *testing.T) { b.autoDetectCapabilities() // verify - assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform")) + assert.Equal(t, OpenShiftPlatform, OperatorConfiguration.GetPlatform()) } func TestAutoDetectEsProvisionNoEsOperator(t *testing.T) { @@ -499,7 +502,7 @@ func TestAutoDetectAutoscalingVersion(t *testing.T) { func TestSkipAuthDelegatorNonOpenShift(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformKubernetes) + OperatorConfiguration.SetPlatform(KubernetesPlatform) defer viper.Reset() dcl := &fakeDiscoveryClient{} @@ -515,7 +518,7 @@ func TestSkipAuthDelegatorNonOpenShift(t *testing.T) { func TestNoAuthDelegatorAvailable(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + OperatorConfiguration.SetPlatform(OpenShiftPlatform) defer viper.Reset() dcl := &fakeDiscoveryClient{} @@ -534,7 +537,7 @@ func TestNoAuthDelegatorAvailable(t *testing.T) { func TestAuthDelegatorBecomesAvailable(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + OperatorConfiguration.SetPlatform(OpenShiftPlatform) defer viper.Reset() dcl := &fakeDiscoveryClient{} @@ -555,7 +558,7 @@ func TestAuthDelegatorBecomesAvailable(t *testing.T) { func TestAuthDelegatorBecomesUnavailable(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + OperatorConfiguration.SetPlatform(OpenShiftPlatform) defer viper.Reset() dcl := &fakeDiscoveryClient{} diff --git a/pkg/autodetect/operatorconfig.go b/pkg/autodetect/operatorconfig.go new file mode 100644 index 000000000..026d4236d --- /dev/null +++ b/pkg/autodetect/operatorconfig.go @@ -0,0 +1,72 @@ +package autodetect + +import ( + "strings" + "sync" + + "github.com/spf13/viper" + + v1 "github.com/jaegertracing/jaeger-operator/apis/v1" +) + +// Platform holds the auto-detected running platform. +type Platform int + +const ( + // KubernetesPlatform represents the cluster is Kubernetes. + KubernetesPlatform Platform = iota + + // OpenShiftPlatform represents the cluster is OpenShift. + OpenShiftPlatform +) + +func (p Platform) String() string { + return [...]string{"Kubernetes", "OpenShift"}[p] +} + +var OperatorConfiguration operatorConfigurationWrapper + +type operatorConfigurationWrapper struct { + mu sync.RWMutex +} + +func (c *operatorConfigurationWrapper) SetPlatform(p interface{}) { + var platform string + switch v := p.(type) { + case string: + platform = v + case Platform: + platform = v.String() + default: + platform = KubernetesPlatform.String() + } + + c.mu.Lock() + viper.Set(v1.FlagPlatform, platform) + c.mu.Unlock() +} + +func (c *operatorConfigurationWrapper) GetPlatform() Platform { + c.mu.RLock() + p := viper.GetString(v1.FlagPlatform) + c.mu.RUnlock() + + p = strings.ToLower(p) + + var platform Platform + switch p { + case "openshift": + platform = OpenShiftPlatform + default: + platform = KubernetesPlatform + } + return platform +} + +func (c *operatorConfigurationWrapper) IsPlatformAutodetectionEnabled() bool { + c.mu.RLock() + p := viper.GetString(v1.FlagPlatform) + c.mu.RUnlock() + + return strings.EqualFold(p, "auto-detect") +} diff --git a/pkg/cmd/start/bootstrap.go b/pkg/cmd/start/bootstrap.go index 649308e63..7311c6cb9 100644 --- a/pkg/cmd/start/bootstrap.go +++ b/pkg/cmd/start/bootstrap.go @@ -104,7 +104,7 @@ func bootstrap(ctx context.Context) manager.Manager { log.Log.V(6).Info("%s", err) } - span.SetAttributes(otelattribute.String("Platform", viper.GetString("platform"))) + span.SetAttributes(otelattribute.String("Platform", autodetect.OperatorConfiguration.GetPlatform().String())) watchNamespace, found := os.LookupEnv("WATCH_NAMESPACE") if found { setupLog.Info("watching namespace(s)", "namespaces", watchNamespace) diff --git a/pkg/config/ca/ca.go b/pkg/config/ca/ca.go index 814264252..f9fbc2a63 100644 --- a/pkg/config/ca/ca.go +++ b/pkg/config/ca/ca.go @@ -4,11 +4,11 @@ import ( "fmt" "strings" - "github.com/spf13/viper" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/util" ) @@ -24,7 +24,7 @@ const ( // GetTrustedCABundle returns a trusted CA bundle configmap if platform is OpenShift func GetTrustedCABundle(jaeger *v1.Jaeger) *corev1.ConfigMap { // Only configure the trusted CA if running in OpenShift - if viper.GetString("platform") != v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() != autodetect.OpenShiftPlatform { return nil } @@ -59,7 +59,7 @@ func GetTrustedCABundle(jaeger *v1.Jaeger) *corev1.ConfigMap { // GetServiceCABundle returns a service CA configmap if platform is OpenShift func GetServiceCABundle(jaeger *v1.Jaeger) *corev1.ConfigMap { // Only configure the service CA if running in OpenShift - if viper.GetString("platform") != v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() != autodetect.OpenShiftPlatform { return nil } @@ -93,7 +93,7 @@ func GetServiceCABundle(jaeger *v1.Jaeger) *corev1.ConfigMap { // trusted CA bundle volume and volumeMount, if running on OpenShift func Update(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec) { // Only configure the trusted CA if running in OpenShift - if viper.GetString("platform") != v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() != autodetect.OpenShiftPlatform { return } @@ -130,7 +130,7 @@ func Update(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec) { // AddServiceCA will modify the supplied common spec, to include // the service CA volume and volumeMount, if running on OpenShift func AddServiceCA(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec) { - if viper.GetString("platform") != v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() != autodetect.OpenShiftPlatform { return } diff --git a/pkg/config/ca/ca_test.go b/pkg/config/ca/ca_test.go index 6d8baaf69..b1159aeca 100644 --- a/pkg/config/ca/ca_test.go +++ b/pkg/config/ca/ca_test.go @@ -9,6 +9,7 @@ import ( "k8s.io/apimachinery/pkg/types" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" ) func TestGetWithoutTrustedCA(t *testing.T) { @@ -29,7 +30,7 @@ func TestGetWithoutTrustedCA(t *testing.T) { func TestGetWithTrustedCA(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) @@ -45,7 +46,7 @@ func TestGetWithTrustedCA(t *testing.T) { func TestGetWithServiceCA(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) @@ -60,7 +61,7 @@ func TestGetWithServiceCA(t *testing.T) { func TestGetWithExistingTrustedCA(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) @@ -78,7 +79,7 @@ func TestGetWithExistingTrustedCA(t *testing.T) { func TestGetWithExistingServiceCA(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) @@ -113,7 +114,7 @@ func TestUpdateWithoutCAs(t *testing.T) { func TestUpdateWithTrustedCA(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) @@ -130,7 +131,7 @@ func TestUpdateWithTrustedCA(t *testing.T) { func TestUpdateWithExistingTrustedCA(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) diff --git a/pkg/config/tls/tls.go b/pkg/config/tls/tls.go index c313490ad..374f09167 100644 --- a/pkg/config/tls/tls.go +++ b/pkg/config/tls/tls.go @@ -3,17 +3,17 @@ package tls import ( "fmt" - "github.com/spf13/viper" corev1 "k8s.io/api/core/v1" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/service" "github.com/jaegertracing/jaeger-operator/pkg/util" ) // Update will mount the tls secret on the collector pod. func Update(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec, options *[]string) { - if viper.GetString("platform") != v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() != autodetect.OpenShiftPlatform { return } diff --git a/pkg/config/tls/tls_test.go b/pkg/config/tls/tls_test.go index baeb5eee0..c10e595b3 100644 --- a/pkg/config/tls/tls_test.go +++ b/pkg/config/tls/tls_test.go @@ -3,16 +3,16 @@ package tls import ( "testing" - "github.com/spf13/viper" "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/types" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" ) func TestUpdateWithTLSSecret(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestUpdateWithTLSSecret"}) - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) commonSpec := v1.JaegerCommonSpec{} options := []string{} @@ -28,7 +28,7 @@ func TestUpdateWithTLSSecret(t *testing.T) { func TestIgnoreDefaultTLSSecretWhenGrpcHostPortIsSet(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestIgnoreDefaultTLSSecretWhenGrpcHostPortIsSet"}) - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) commonSpec := v1.JaegerCommonSpec{} options := []string{} diff --git a/pkg/controller/jaeger/jaeger_controller.go b/pkg/controller/jaeger/jaeger_controller.go index 0c9e7ddb1..47614993e 100644 --- a/pkg/controller/jaeger/jaeger_controller.go +++ b/pkg/controller/jaeger/jaeger_controller.go @@ -24,6 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/inject" "github.com/jaegertracing/jaeger-operator/pkg/storage" "github.com/jaegertracing/jaeger-operator/pkg/strategy" @@ -350,7 +351,7 @@ func (r *ReconcileJaeger) apply(ctx context.Context, jaeger v1.Jaeger, str strat return jaeger, tracing.HandleError(err, span) } - if strings.EqualFold(viper.GetString("platform"), v1.FlagPlatformOpenShift) { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { if err := r.applyRoutes(ctx, jaeger, str.Routes()); err != nil { return jaeger, tracing.HandleError(err, span) } diff --git a/pkg/cronjob/es_rollover.go b/pkg/cronjob/es_rollover.go index 3571df0e2..8f0d4cc66 100644 --- a/pkg/cronjob/es_rollover.go +++ b/pkg/cronjob/es_rollover.go @@ -15,6 +15,7 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/apis/v1" "github.com/jaegertracing/jaeger-operator/pkg/account" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/util" ) @@ -235,7 +236,7 @@ func EsScriptEnvVars(opts v1.Options) []corev1.EnvVar { if val, ok := options["skip-dependencies"]; ok { envs = append(envs, corev1.EnvVar{Name: "SKIP_DEPENDENCIES", Value: val}) - } else if !ok && viper.GetString("platform") == v1.FlagPlatformOpenShift { + } else if !ok && autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { envs = append(envs, corev1.EnvVar{Name: "SKIP_DEPENDENCIES", Value: "true"}) } diff --git a/pkg/cronjob/es_rollover_test.go b/pkg/cronjob/es_rollover_test.go index e54570cd0..12c58f619 100644 --- a/pkg/cronjob/es_rollover_test.go +++ b/pkg/cronjob/es_rollover_test.go @@ -7,6 +7,7 @@ import ( batchv1 "k8s.io/api/batch/v1" batchv1beta1 "k8s.io/api/batch/v1beta1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/version" "github.com/spf13/viper" @@ -78,8 +79,8 @@ func TestRollover(t *testing.T) { assert.Equal(t, historyLimits, *cjob.Spec.SuccessfulJobsHistoryLimit) // Test openshift settings - viper.Set("platform", v1.FlagPlatformOpenShift) - defer viper.Set("platform", v1.FlagPlatformKubernetes) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) + defer autodetect.OperatorConfiguration.SetPlatform(autodetect.KubernetesPlatform) cjob = rollover(j).(*batchv1.CronJob) assert.Equal(t, []corev1.EnvVar{ diff --git a/pkg/deployment/agent.go b/pkg/deployment/agent.go index cf3913054..31c5ddcee 100644 --- a/pkg/deployment/agent.go +++ b/pkg/deployment/agent.go @@ -6,7 +6,6 @@ import ( "strconv" "strings" - "github.com/spf13/viper" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -14,6 +13,7 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/apis/v1" "github.com/jaegertracing/jaeger-operator/pkg/account" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/service" "github.com/jaegertracing/jaeger-operator/pkg/util" @@ -47,7 +47,7 @@ func (a *Agent) Get() *appsv1.DaemonSet { } // Enable tls by default for openshift platform - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { if len(util.FindItem("--reporter.grpc.tls.enabled=", args)) == 0 { args = append(args, "--reporter.grpc.tls.enabled=true") args = append(args, fmt.Sprintf("--reporter.grpc.tls.ca=%s", ca.ServiceCAPath)) diff --git a/pkg/deployment/agent_test.go b/pkg/deployment/agent_test.go index c303f23f8..4689a0712 100644 --- a/pkg/deployment/agent_test.go +++ b/pkg/deployment/agent_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/util" "github.com/jaegertracing/jaeger-operator/pkg/version" @@ -201,7 +202,7 @@ func TestAgentCustomReporterPort(t *testing.T) { } func TestAgentArgumentsOpenshiftTLS(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() for _, tt := range []struct { diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index ec54ac234..824a28fd1 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -5,9 +5,9 @@ import ( "sort" "strconv" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/storage" - "github.com/spf13/viper" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -81,7 +81,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { // Enable tls by default for openshift platform // even though the agent is in the same process as the collector, they communicate via gRPC, and the collector has TLS enabled, // as it might receive connections from external agents - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { if len(util.FindItem("--reporter.grpc.host-port=", options)) == 0 && len(util.FindItem("--reporter.grpc.tls.enabled=", options)) == 0 { options = append(options, "--reporter.grpc.tls.enabled=true") diff --git a/pkg/deployment/all_in_one_test.go b/pkg/deployment/all_in_one_test.go index 7af0ba525..5cf807df0 100644 --- a/pkg/deployment/all_in_one_test.go +++ b/pkg/deployment/all_in_one_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/util" "github.com/jaegertracing/jaeger-operator/pkg/version" ) @@ -369,7 +370,7 @@ func TestAllInOneOrderOfArguments(t *testing.T) { func TestAllInOneArgumentsOpenshiftTLS(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() for _, tt := range []struct { diff --git a/pkg/deployment/collector_test.go b/pkg/deployment/collector_test.go index db3dc2325..644505a4e 100644 --- a/pkg/deployment/collector_test.go +++ b/pkg/deployment/collector_test.go @@ -18,6 +18,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/util" "github.com/jaegertracing/jaeger-operator/pkg/version" ) @@ -594,7 +595,7 @@ func TestCollectorAutoscalersSetMaxReplicas(t *testing.T) { } func TestCollectoArgumentsOpenshiftTLS(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() for _, tt := range []struct { name string diff --git a/pkg/inject/oauth_proxy_test.go b/pkg/inject/oauth_proxy_test.go index da509d926..5916a2699 100644 --- a/pkg/inject/oauth_proxy_test.go +++ b/pkg/inject/oauth_proxy_test.go @@ -6,6 +6,7 @@ import ( "testing" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/util" @@ -237,7 +238,7 @@ func TestPropagateOAuthCookieSecret(t *testing.T) { } func TestTrustedCAVolumeIsUsed(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer func() { viper.Reset() setDefaults() diff --git a/pkg/inject/sidecar.go b/pkg/inject/sidecar.go index 1aac72c39..96e9e5ce7 100644 --- a/pkg/inject/sidecar.go +++ b/pkg/inject/sidecar.go @@ -7,13 +7,13 @@ import ( "strconv" "strings" - "github.com/spf13/viper" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/controller-runtime/pkg/log" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/deployment" "github.com/jaegertracing/jaeger-operator/pkg/service" @@ -216,7 +216,7 @@ func container(jaeger *v1.Jaeger, dep *appsv1.Deployment, agentIdx int) corev1.C } // Enable tls by default for openshift platform - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { if len(util.FindItem("--reporter.grpc.tls.enabled=", args)) == 0 { args = append(args, "--reporter.grpc.tls.enabled=true") args = append(args, fmt.Sprintf("--reporter.grpc.tls.ca=%s", ca.ServiceCAPath)) @@ -423,7 +423,7 @@ func CleanSidecar(instanceName string, deployment *appsv1.Deployment) { break } } - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { names := map[string]bool{ ca.TrustedCANameFromString(instanceName): true, ca.ServiceCANameFromString(instanceName): true, diff --git a/pkg/inject/sidecar_test.go b/pkg/inject/sidecar_test.go index 6f7b7763b..70a8d5787 100644 --- a/pkg/inject/sidecar_test.go +++ b/pkg/inject/sidecar_test.go @@ -15,6 +15,7 @@ import ( "k8s.io/apimachinery/pkg/types" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/util" ) @@ -57,7 +58,7 @@ func TestInjectSidecar(t *testing.T) { } func TestInjectSidecarOpenShift(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) @@ -690,7 +691,7 @@ func TestCleanSidecars(t *testing.T) { func TestCleanSidecarsOpenShift(t *testing.T) { // prepare - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() instanceName := "my-instance" @@ -874,7 +875,7 @@ func containsOptionWithPrefix(t *testing.T, args []string, prefix string) bool { } func TestSidecarArgumentsOpenshiftTLS(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() for _, tt := range []struct { @@ -984,7 +985,7 @@ func TestEqualSidecar(t *testing.T) { } func TestInjectSidecarOnOpenShift(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) + autodetect.OperatorConfiguration.SetPlatform(autodetect.OpenShiftPlatform) defer viper.Reset() jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) diff --git a/pkg/service/collector.go b/pkg/service/collector.go index cd7c1fa00..19e54dbe9 100644 --- a/pkg/service/collector.go +++ b/pkg/service/collector.go @@ -4,11 +4,11 @@ import ( "fmt" "strconv" - "github.com/spf13/viper" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/util" ) @@ -112,7 +112,7 @@ func GetPortNameForGRPC(jaeger *v1.Jaeger) string { protoSecure = "tls-grpc-jaeger" protoInsecure = "grpc-jaeger" ) - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { // we always have TLS certs when running on OpenShift, so, TLS is always enabled return protoSecure } diff --git a/pkg/service/collector_test.go b/pkg/service/collector_test.go index e74b18a52..1fad8047a 100644 --- a/pkg/service/collector_test.go +++ b/pkg/service/collector_test.go @@ -9,6 +9,7 @@ import ( "k8s.io/apimachinery/pkg/types" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" ) func TestCollectorServiceNameAndPorts(t *testing.T) { @@ -122,7 +123,7 @@ func TestCollectorGRPCPortName(t *testing.T) { t.Run(tt.name, func(t *testing.T) { // prepare if tt.inOpenShift { - viper.Set("platform", v1.FlagPlatformOpenShift) + viper.Set("platform", autodetect.OpenShiftPlatform.String()) defer viper.Reset() } diff --git a/pkg/strategy/all_in_one.go b/pkg/strategy/all_in_one.go index 7f5327e11..ed712a9e0 100644 --- a/pkg/strategy/all_in_one.go +++ b/pkg/strategy/all_in_one.go @@ -3,12 +3,12 @@ package strategy import ( "context" - "github.com/spf13/viper" "go.opentelemetry.io/otel" appsv1 "k8s.io/api/apps/v1" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" "github.com/jaegertracing/jaeger-operator/pkg/account" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" crb "github.com/jaegertracing/jaeger-operator/pkg/clusterrolebinding" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/config/sampling" @@ -74,7 +74,7 @@ func newAllInOneStrategy(ctx context.Context, jaeger *v1.Jaeger) S { } // add the routes/ingresses - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { if q := route.NewQueryRoute(jaeger).Get(); nil != q { c.routes = append(c.routes, *q) if link := consolelink.Get(jaeger, q); link != nil { diff --git a/pkg/strategy/all_in_one_test.go b/pkg/strategy/all_in_one_test.go index f7008a4e9..86cb7c1f6 100644 --- a/pkg/strategy/all_in_one_test.go +++ b/pkg/strategy/all_in_one_test.go @@ -7,6 +7,7 @@ import ( "testing" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/consolelink" "github.com/spf13/viper" @@ -101,7 +102,7 @@ func assertDeploymentsAndServicesForAllInOne(t *testing.T, instance *v1.Jaeger, ingresses := map[string]bool{} routes := map[string]bool{} consoleLinks := map[string]bool{} - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { routes[util.DNSName(name)] = false consoleLinks[consolelink.Name(instance)] = false diff --git a/pkg/strategy/controller.go b/pkg/strategy/controller.go index cfdf67e6c..35adf44da 100644 --- a/pkg/strategy/controller.go +++ b/pkg/strategy/controller.go @@ -13,6 +13,7 @@ import ( esv1 "github.com/openshift/elasticsearch-operator/apis/logging/v1" v1 "github.com/jaegertracing/jaeger-operator/apis/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/cronjob" ) @@ -111,7 +112,7 @@ func normalize(ctx context.Context, jaeger *v1.Jaeger) { } // we always set the value to None, except when we are on OpenShift *and* the user has not explicitly set to 'none' - if viper.GetString("platform") == v1.FlagPlatformOpenShift && jaeger.Spec.Ingress.Security != v1.IngressSecurityNoneExplicit { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform && jaeger.Spec.Ingress.Security != v1.IngressSecurityNoneExplicit { jaeger.Spec.Ingress.Security = v1.IngressSecurityOAuthProxy } else { // cases: @@ -120,7 +121,7 @@ func normalize(ctx context.Context, jaeger *v1.Jaeger) { jaeger.Spec.Ingress.Security = v1.IngressSecurityNoneExplicit } - if viper.GetString("platform") == v1.FlagPlatformOpenShift && jaeger.Spec.Ingress.Security == v1.IngressSecurityOAuthProxy && + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform && jaeger.Spec.Ingress.Security == v1.IngressSecurityOAuthProxy && jaeger.Spec.Ingress.Openshift.SAR == nil { sar := fmt.Sprintf("{\"namespace\": \"%s\", \"resource\": \"pods\", \"verb\": \"get\"}", jaeger.Namespace) jaeger.Spec.Ingress.Openshift.SAR = &sar diff --git a/pkg/strategy/production.go b/pkg/strategy/production.go index 2692263d9..8e100f1db 100644 --- a/pkg/strategy/production.go +++ b/pkg/strategy/production.go @@ -15,6 +15,7 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/apis/v1" "github.com/jaegertracing/jaeger-operator/pkg/account" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" crb "github.com/jaegertracing/jaeger-operator/pkg/clusterrolebinding" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/config/sampling" @@ -81,7 +82,7 @@ func newProductionStrategy(ctx context.Context, jaeger *v1.Jaeger) S { } // add the routes/ingresses - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { if q := route.NewQueryRoute(jaeger).Get(); nil != q { c.routes = append(c.routes, *q) if link := consolelink.Get(jaeger, q); link != nil { @@ -89,11 +90,11 @@ func newProductionStrategy(ctx context.Context, jaeger *v1.Jaeger) S { } } } else { - span.SetAttributes(attribute.String("Platform", v1.FlagPlatformKubernetes)) if q := ingress.NewQueryIngress(jaeger).Get(); nil != q { c.ingresses = append(c.ingresses, *q) } } + span.SetAttributes(attribute.String("Platform", autodetect.OperatorConfiguration.GetPlatform().String())) // add autoscalers c.horizontalPodAutoscalers = collector.Autoscalers() diff --git a/pkg/strategy/production_test.go b/pkg/strategy/production_test.go index d20af0c7f..559f8256f 100644 --- a/pkg/strategy/production_test.go +++ b/pkg/strategy/production_test.go @@ -8,6 +8,7 @@ import ( batchv1 "k8s.io/api/batch/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/consolelink" "github.com/spf13/viper" @@ -146,7 +147,7 @@ func assertDeploymentsAndServicesForProduction(t *testing.T, instance *v1.Jaeger ingresses := map[string]bool{} routes := map[string]bool{} consoleLinks := map[string]bool{} - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { routes[util.DNSName(name)] = false consoleLinks[consolelink.Name(instance)] = false } else { diff --git a/pkg/strategy/streaming.go b/pkg/strategy/streaming.go index d901d6fb2..783359bc7 100644 --- a/pkg/strategy/streaming.go +++ b/pkg/strategy/streaming.go @@ -15,6 +15,7 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/apis/v1" "github.com/jaegertracing/jaeger-operator/pkg/account" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" crb "github.com/jaegertracing/jaeger-operator/pkg/clusterrolebinding" "github.com/jaegertracing/jaeger-operator/pkg/config/ca" "github.com/jaegertracing/jaeger-operator/pkg/config/sampling" @@ -97,7 +98,7 @@ func newStreamingStrategy(ctx context.Context, jaeger *v1.Jaeger) S { } // add the routes/ingresses - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { if q := route.NewQueryRoute(jaeger).Get(); nil != q { manifest.routes = append(manifest.routes, *q) if link := consolelink.Get(jaeger, q); link != nil { diff --git a/pkg/strategy/streaming_test.go b/pkg/strategy/streaming_test.go index 162bbab30..e28deed55 100644 --- a/pkg/strategy/streaming_test.go +++ b/pkg/strategy/streaming_test.go @@ -8,6 +8,7 @@ import ( batchv1 "k8s.io/api/batch/v1" + "github.com/jaegertracing/jaeger-operator/pkg/autodetect" "github.com/jaegertracing/jaeger-operator/pkg/consolelink" "github.com/spf13/viper" @@ -196,7 +197,7 @@ func assertDeploymentsAndServicesForStreaming(t *testing.T, instance *v1.Jaeger, ingresses := map[string]bool{} routes := map[string]bool{} consoleLinks := map[string]bool{} - if viper.GetString("platform") == v1.FlagPlatformOpenShift { + if autodetect.OperatorConfiguration.GetPlatform() == autodetect.OpenShiftPlatform { routes[name] = false consoleLinks[consolelink.Name(instance)] = false } else {