diff --git a/.codecov.yml b/.codecov.yml index 12565284f..38b985c21 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,3 +1,10 @@ +coverage: + status: + project: + default: + target: auto + # this allows a 0.1% drop from the previous base commit coverage + threshold: 0.1% ignore: - "apis/v1/zz_generated.deepcopy.go" - "apis/v1/zz_generated.defaults.go" diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..9ccd102fd --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +run: + go: '1.18' + timeout: 10m + +linters-settings: + goimports: + local-prefixes: github.com/jaegertracing/jaeger-operator + gosimple: + go: "1.18" + +linters: + enable: + - depguard + - gofmt + - gofumpt + - goimports + - gosec + - govet + - misspell + - bidichk + disable: + - errcheck + +issues: + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gosec diff --git a/Makefile b/Makefile index 17995ebaf..3b746336f 100644 --- a/Makefile +++ b/Makefile @@ -118,6 +118,7 @@ PHONY: lint lint: $(ECHO) Linting... $(VECHO)GOPATH=${GOPATH} ./.ci/lint.sh + golangci-lint -v run .PHONY: vet vet: ## Run go vet against code. @@ -437,6 +438,7 @@ tools: kustomize controller-gen operator-sdk .PHONY: install-tools install-tools: operator-sdk + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 $(VECHO)${GO_FLAGS} ./.ci/vgot.sh \ golang.org/x/lint/golint \ golang.org/x/tools/cmd/goimports diff --git a/apis/v1/jaeger_types.go b/apis/v1/jaeger_types.go index 4402c4e38..9df144b87 100644 --- a/apis/v1/jaeger_types.go +++ b/apis/v1/jaeger_types.go @@ -273,7 +273,7 @@ type JaegerQuerySpec struct { // +optional // TracingEnabled if set to false adds the JAEGER_DISABLED environment flag and removes the injected // agent container from the query component to disable tracing requests to the query service. - // The default, if ommited, is true + // The default, if omitted, is true TracingEnabled *bool `json:"tracingEnabled,omitempty"` // +optional @@ -381,7 +381,7 @@ type JaegerAllInOneSpec struct { // +optional // TracingEnabled if set to false adds the JAEGER_DISABLED environment flag and removes the injected // agent container from the query component to disable tracing requests to the query service. - // The default, if ommited, is true + // The default, if omitted, is true TracingEnabled *bool `json:"tracingEnabled,omitempty"` // +optional @@ -405,7 +405,6 @@ type AutoScaleSpec struct { // JaegerCollectorSpec defines the options to be used when deploying the collector type JaegerCollectorSpec struct { - // +optional AutoScaleSpec `json:",inline,omitempty"` diff --git a/apis/v1/options.go b/apis/v1/options.go index 76a8d1408..bed4c8078 100644 --- a/apis/v1/options.go +++ b/apis/v1/options.go @@ -14,12 +14,12 @@ type Values map[string]interface{} func (v *Values) DeepCopy() *Values { out := make(Values, len(*v)) for key, val := range *v { - switch val.(type) { + switch val := val.(type) { case string: out[key] = val case []string: - out[key] = append([]string(nil), val.([]string)...) + out[key] = append([]string(nil), val...) } } return &out @@ -132,11 +132,11 @@ func (o *Options) ToArgs() []string { if len(o.opts) > 0 { args := make([]string, 0, len(o.opts)) for k, v := range o.opts { - switch v.(type) { + switch v := v.(type) { case string: args = append(args, fmt.Sprintf("--%s=%v", k, v)) case []string: - for _, vv := range v.([]string) { + for _, vv := range v { args = append(args, fmt.Sprintf("--%s=%v", k, vv)) } } @@ -157,9 +157,9 @@ func (o *Options) Map() map[string]interface{} { func (o *Options) StringMap() map[string]string { smap := make(map[string]string) for k, v := range o.opts { - switch v.(type) { + switch v := v.(type) { case string: - smap[k] = v.(string) + smap[k] = v } } return smap diff --git a/apis/v1/options_test.go b/apis/v1/options_test.go index 0fc260795..342fbcc52 100644 --- a/apis/v1/options_test.go +++ b/apis/v1/options_test.go @@ -186,5 +186,4 @@ func TestRepetitiveArguments(t *testing.T) { assert.Len(t, args, 3) assert.Equal(t, expected, args) - } diff --git a/controllers/appsv1/deployment_webhook.go b/controllers/appsv1/deployment_webhook.go index c0b39b933..15d6edbbf 100644 --- a/controllers/appsv1/deployment_webhook.go +++ b/controllers/appsv1/deployment_webhook.go @@ -74,7 +74,6 @@ func (d *deploymentInterceptor) Handle(ctx context.Context, req admission.Reques if dep.Labels["app"] == "jaeger" && dep.Labels["app.kubernetes.io/component"] != "query" { // Don't touch jaeger deployments return admission.Allowed("is jaeger deployment, we do not touch it") - } ns := &corev1.Namespace{} @@ -149,7 +148,6 @@ func (d *deploymentInterceptor) Handle(ctx context.Context, req admission.Reques return admission.PatchResponseFromRaw(req.Object.Raw, marshaledDeploy) } - } return admission.Allowed("no action needed") } diff --git a/controllers/appsv1/suite_test.go b/controllers/appsv1/suite_test.go index 4afee67be..556d25d2a 100644 --- a/controllers/appsv1/suite_test.go +++ b/controllers/appsv1/suite_test.go @@ -15,9 +15,11 @@ import ( // +kubebuilder:scaffold:imports ) -var k8sClient client.Client -var testEnv *envtest.Environment -var testScheme *runtime.Scheme = scheme.Scheme +var ( + k8sClient client.Client + testEnv *envtest.Environment + testScheme *runtime.Scheme = scheme.Scheme +) func TestMain(m *testing.M) { testEnv = &envtest.Environment{ diff --git a/controllers/jaegertracing/suite_test.go b/controllers/jaegertracing/suite_test.go index ce8b0657a..e9a35a98e 100644 --- a/controllers/jaegertracing/suite_test.go +++ b/controllers/jaegertracing/suite_test.go @@ -15,9 +15,11 @@ import ( // +kubebuilder:scaffold:imports ) -var k8sClient client.Client -var testEnv *envtest.Environment -var testScheme *runtime.Scheme = scheme.Scheme +var ( + k8sClient client.Client + testEnv *envtest.Environment + testScheme *runtime.Scheme = scheme.Scheme +) func TestMain(m *testing.M) { testEnv = &envtest.Environment{ diff --git a/pkg/account/oauth_proxy.go b/pkg/account/oauth_proxy.go index 966f7a37a..da1098ea9 100644 --- a/pkg/account/oauth_proxy.go +++ b/pkg/account/oauth_proxy.go @@ -26,7 +26,7 @@ func OAuthProxy(jaeger *v1.Jaeger) *corev1.ServiceAccount { "serviceaccounts.openshift.io/oauth-redirectreference.primary": getOAuthRedirectReference(jaeger), }, OwnerReferences: []metav1.OwnerReference{ - metav1.OwnerReference{ + { APIVersion: jaeger.APIVersion, Kind: jaeger.Kind, Name: jaeger.Name, diff --git a/pkg/autodetect/main.go b/pkg/autodetect/main.go index e9d83ffd9..1b01c61c4 100644 --- a/pkg/autodetect/main.go +++ b/pkg/autodetect/main.go @@ -71,10 +71,8 @@ func (b *Background) Start() { go func() { for { - select { - case <-b.ticker.C: - b.autoDetectCapabilities() - } + <-b.ticker.C + b.autoDetectCapabilities() } }() } @@ -97,7 +95,6 @@ func (b *Background) autoDetectCapabilities() { b.firstRun.Do(func() { // the platform won't change during the execution of the operator, need to run it only once b.detectPlatform(ctx, apiList) - }) b.detectElasticsearch(ctx, apiList) @@ -132,7 +129,6 @@ func (b *Background) detectCronjobsVersion(ctx context.Context) { log.Log.V(2).Info( fmt.Sprintf("Did not find the cronjobs api in %s", strings.Join(apiGroupVersions, " or ")), ) - } // AvailableAPIs returns available list of CRDs from the cluster. diff --git a/pkg/autodetect/main_test.go b/pkg/autodetect/main_test.go index 1b3fd3664..9f7ec6b6a 100644 --- a/pkg/autodetect/main_test.go +++ b/pkg/autodetect/main_test.go @@ -116,8 +116,8 @@ func TestStartContinuesInBackground(t *testing.T) { case <-time.After(6 * time.Second): // this one might take up to 5 seconds to run again + processing time assert.Fail(t, "timed out waiting for the start process to detect the new capabilities") } - } + func TestAutoDetectWithServerGroupsError(t *testing.T) { // prepare defer viper.Reset() @@ -282,7 +282,6 @@ func TestAutoDetectEsProvisionWithEsOperator(t *testing.T) { } t.Run("kind Elasticsearch", func(t *testing.T) { - dcl.ServerResourcesForGroupVersionFunc = func(_ string) (apiGroupList *metav1.APIResourceList, err error) { return &metav1.APIResourceList{ GroupVersion: "logging.openshift.io/v1", @@ -300,7 +299,6 @@ func TestAutoDetectEsProvisionWithEsOperator(t *testing.T) { t.Run("no kind Elasticsearch", func(t *testing.T) { dcl.ServerResourcesForGroupVersionFunc = func(_ string) (apiGroupList *metav1.APIResourceList, err error) { return &metav1.APIResourceList{ - GroupVersion: "logging.openshift.io/v1", APIResources: []metav1.APIResource{ { @@ -433,7 +431,7 @@ func TestAutoDetectCronJobsVersion(t *testing.T) { apiGroupVersions := []string{v1.FlagCronJobsVersionBatchV1, v1.FlagCronJobsVersionBatchV1Beta1} for _, apiGroup := range apiGroupVersions { dcl := &fakeDiscoveryClient{} - cl := fake.NewFakeClient() + cl := fake.NewFakeClient() // nolint:staticcheck b := WithClients(cl, dcl, cl) dcl.ServerGroupsFunc = func() (apiGroupList *metav1.APIGroupList, err error) { return &metav1.APIGroupList{Groups: []metav1.APIGroup{{ @@ -594,7 +592,7 @@ func TestCleanDeployments(t *testing.T) { ObjectMeta: metav1.ObjectMeta{}, Spec: corev1.PodSpec{ Containers: []corev1.Container{ - corev1.Container{ + { Name: "C1", Image: "image1", }, diff --git a/pkg/cmd/generate/main.go b/pkg/cmd/generate/main.go index 524eb7416..c5fa0d748 100644 --- a/pkg/cmd/generate/main.go +++ b/pkg/cmd/generate/main.go @@ -63,7 +63,6 @@ func createSpecFromYAML(filename string) (*v1.Jaeger, error) { } func generate(_ *cobra.Command, _ []string) error { - var loggingLevel zapcore.Level switch strings.ToLower(viper.GetString("log-level")) { case "panic": @@ -104,7 +103,7 @@ func generate(_ *cobra.Command, _ []string) error { outputName := viper.GetString("output") pathToFile := filepath.Clean(outputName) - out, err := os.OpenFile(pathToFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) + out, err := os.OpenFile(pathToFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0o600) if err != nil { return err } diff --git a/pkg/cmd/start/bootstrap.go b/pkg/cmd/start/bootstrap.go index f78eb3c9b..613163b8f 100644 --- a/pkg/cmd/start/bootstrap.go +++ b/pkg/cmd/start/bootstrap.go @@ -69,7 +69,6 @@ func init() { } func bootstrap(ctx context.Context) manager.Manager { - namespace := getNamespace(ctx) tracing.Bootstrap(ctx, namespace) @@ -230,7 +229,7 @@ func detectNamespacePermissions(ctx context.Context, mgr manager.Manager) { func setOperatorScope(ctx context.Context, namespace string) { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "setOperatorScope") + ctx, span := tracer.Start(ctx, "setOperatorScope") // nolint:ineffassign,staticcheck defer span.End() // set what's the namespace to watch @@ -249,7 +248,7 @@ func setOperatorScope(ctx context.Context, namespace string) { func setLogLevel(ctx context.Context) { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "setLogLevel") + ctx, span := tracer.Start(ctx, "setLogLevel") // nolint:ineffassign,staticcheck defer span.End() var loggingLevel zapcore.Level @@ -277,12 +276,11 @@ func setLogLevel(ctx context.Context) { pflag.CommandLine.AddGoFlagSet(flag.CommandLine) ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) - } func buildIdentity(ctx context.Context, podNamespace string) { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "buildIdentity") + ctx, span := tracer.Start(ctx, "buildIdentity") // nolint:ineffassign,staticcheck defer span.End() operatorName, found := os.LookupEnv("OPERATOR_NAME") @@ -297,7 +295,7 @@ func buildIdentity(ctx context.Context, podNamespace string) { if len(podNamespace) > 0 { identity = fmt.Sprintf("%s.%s", podNamespace, operatorName) } else { - identity = fmt.Sprintf("%s", operatorName) + identity = operatorName } span.SetAttributes(otelattribute.String(v1.ConfigIdentity, identity)) @@ -306,7 +304,7 @@ func buildIdentity(ctx context.Context, podNamespace string) { func createManager(ctx context.Context, cfg *rest.Config) manager.Manager { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "createManager") + ctx, span := tracer.Start(ctx, "createManager") // nolint:ineffassign,staticcheck defer span.End() metricsHost := viper.GetString("metrics-host") @@ -378,7 +376,7 @@ func performUpgrades(ctx context.Context, mgr manager.Manager) { func setupControllers(ctx context.Context, mgr manager.Manager) { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "setupControllers") + ctx, span := tracer.Start(ctx, "setupControllers") // nolint:ineffassign,staticcheck clientReader := mgr.GetAPIReader() client := mgr.GetClient() schema := mgr.GetScheme() @@ -419,7 +417,7 @@ func setupWebhooks(_ context.Context, mgr manager.Manager) { func getNamespace(ctx context.Context) string { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "getNamespace") + ctx, span := tracer.Start(ctx, "getNamespace") // nolint:ineffassign,staticcheck defer span.End() podNamespace, found := os.LookupEnv("POD_NAMESPACE") diff --git a/pkg/config/sampling/sampling.go b/pkg/config/sampling/sampling.go index 94a57b5f8..246e5b407 100644 --- a/pkg/config/sampling/sampling.go +++ b/pkg/config/sampling/sampling.go @@ -61,7 +61,7 @@ func (u *Config) Get() *corev1.ConfigMap { Namespace: u.jaeger.Namespace, Labels: util.Labels(fmt.Sprintf("%s-sampling-configuration", u.jaeger.Name), "sampling-configuration", *u.jaeger), OwnerReferences: []metav1.OwnerReference{ - metav1.OwnerReference{ + { APIVersion: u.jaeger.APIVersion, Kind: u.jaeger.Kind, Name: u.jaeger.Name, @@ -97,7 +97,6 @@ func CheckForSamplingConfigFile(jaeger *v1.Jaeger) bool { // Update will modify the supplied common spec and options to include // support for the Sampling configmap. func Update(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec, options *[]string) { - if CheckForSamplingConfigFile(jaeger) { return } @@ -110,7 +109,7 @@ func Update(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec, options *[]strin Name: fmt.Sprintf("%s-sampling-configuration", jaeger.Name), }, Items: []corev1.KeyToPath{ - corev1.KeyToPath{ + { Key: "sampling", Path: "sampling.json", }, diff --git a/pkg/config/ui/ui.go b/pkg/config/ui/ui.go index e7df924a5..0274d6d85 100644 --- a/pkg/config/ui/ui.go +++ b/pkg/config/ui/ui.go @@ -48,7 +48,7 @@ func (u *UIConfig) Get() *corev1.ConfigMap { Namespace: u.jaeger.Namespace, Labels: util.Labels(fmt.Sprintf("%s-ui-configuration", u.jaeger.Name), "ui-configuration", *u.jaeger), OwnerReferences: []metav1.OwnerReference{ - metav1.OwnerReference{ + { APIVersion: u.jaeger.APIVersion, Kind: u.jaeger.Kind, Name: u.jaeger.Name, @@ -77,7 +77,7 @@ func Update(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec, options *[]strin Name: fmt.Sprintf("%s-ui-configuration", jaeger.Name), }, Items: []corev1.KeyToPath{ - corev1.KeyToPath{ + { Key: "ui", Path: "ui.json", }, diff --git a/pkg/consolelink/main.go b/pkg/consolelink/main.go index 0715fa5d6..406aa717c 100644 --- a/pkg/consolelink/main.go +++ b/pkg/consolelink/main.go @@ -13,7 +13,7 @@ import ( // RouteAnnotation used to annotate the link with the route name var RouteAnnotation = "consolelink.jaegertracing.io/route" -//Name derived a console link resource name from jaeger instance +// Name derived a console link resource name from jaeger instance func Name(jaeger *v1.Jaeger) string { return "jaeger-" + jaeger.Namespace + "-" + jaeger.Name } @@ -21,7 +21,7 @@ func Name(jaeger *v1.Jaeger) string { // Get returns a ConsoleLink specification for the current instance func Get(jaeger *v1.Jaeger, route *routev1.Route) *consolev1.ConsoleLink { // If ingress is not enable there is no reason for create a console link - if jaeger.Spec.Ingress.Enabled != nil && *jaeger.Spec.Ingress.Enabled == false { + if jaeger.Spec.Ingress.Enabled != nil && !*jaeger.Spec.Ingress.Enabled { return nil } @@ -67,7 +67,7 @@ func UpdateHref(routes []routev1.Route, links []consolev1.ConsoleLink) []console cl.Spec.Href = fmt.Sprintf("https://%s", host) updated = append(updated, cl) } - //TODO: log if not found the route associated with the link + // TODO: log if not found the route associated with the link } return updated } diff --git a/pkg/controller/jaeger/configmap_test.go b/pkg/controller/jaeger/configmap_test.go index 65636b37f..87fc8c767 100644 --- a/pkg/controller/jaeger/configmap_test.go +++ b/pkg/controller/jaeger/configmap_test.go @@ -256,5 +256,4 @@ func TestConfigMapsClean(t *testing.T) { assert.NoError(t, err) assert.Len(t, configMaps.Items, 1) assert.Equal(t, fmt.Sprintf("%s-service-ca", nsnExisting.Name), configMaps.Items[0].Name) - } diff --git a/pkg/controller/jaeger/consolelink_test.go b/pkg/controller/jaeger/consolelink_test.go index 0c5f0e010..74eeebbe6 100644 --- a/pkg/controller/jaeger/consolelink_test.go +++ b/pkg/controller/jaeger/consolelink_test.go @@ -281,7 +281,6 @@ func TestConsoleLinksCreateExistingNameInAnotherNamespace(t *testing.T) { assert.Equal(t, nsnExisting.Namespace, persistedExisting.Namespace) // Existing should have Href=host1, reconciliation should not touch existing instances. assert.Equal(t, "https://host1", persistedExisting.Spec.Href) - } func TestConsoleLinksSkipped(t *testing.T) { diff --git a/pkg/controller/jaeger/dependencies.go b/pkg/controller/jaeger/dependencies.go index a6fac61bd..9bbab2af9 100644 --- a/pkg/controller/jaeger/dependencies.go +++ b/pkg/controller/jaeger/dependencies.go @@ -21,10 +21,8 @@ import ( "github.com/jaegertracing/jaeger-operator/pkg/tracing" ) -var ( - // ErrDependencyRemoved is returned when a dependency existed but has been removed - ErrDependencyRemoved = errors.New("dependency has been removed") -) +// ErrDependencyRemoved is returned when a dependency existed but has been removed +var ErrDependencyRemoved = errors.New("dependency has been removed") func (r *ReconcileJaeger) handleDependencies(ctx context.Context, str strategy.S) error { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) diff --git a/pkg/controller/jaeger/deployment.go b/pkg/controller/jaeger/deployment.go index a98ddd37f..840471b4b 100644 --- a/pkg/controller/jaeger/deployment.go +++ b/pkg/controller/jaeger/deployment.go @@ -19,10 +19,8 @@ import ( "github.com/jaegertracing/jaeger-operator/pkg/tracing" ) -var ( - // ErrDeploymentRemoved is returned when a deployment existed but has been removed - ErrDeploymentRemoved = errors.New("deployment has been removed") -) +// ErrDeploymentRemoved is returned when a deployment existed but has been removed +var ErrDeploymentRemoved = errors.New("deployment has been removed") func (r *ReconcileJaeger) applyDeployments(ctx context.Context, jaeger v1.Jaeger, desired []appsv1.Deployment) error { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) diff --git a/pkg/controller/jaeger/elasticsearch.go b/pkg/controller/jaeger/elasticsearch.go index 673c8159a..e0482fa57 100644 --- a/pkg/controller/jaeger/elasticsearch.go +++ b/pkg/controller/jaeger/elasticsearch.go @@ -19,10 +19,8 @@ import ( "github.com/jaegertracing/jaeger-operator/pkg/tracing" ) -var ( - // ErrElasticsearchRemoved is returned when an ES cluster existed but has been removed - ErrElasticsearchRemoved = errors.New("Elasticsearch cluster has been removed") -) +// ErrElasticsearchRemoved is returned when an ES cluster existed but has been removed +var ErrElasticsearchRemoved = errors.New("Elasticsearch cluster has been removed") func (r *ReconcileJaeger) applyElasticsearches(ctx context.Context, jaeger v1.Jaeger, desired []esv1.Elasticsearch) error { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) diff --git a/pkg/controller/jaeger/jaeger_controller.go b/pkg/controller/jaeger/jaeger_controller.go index db6d98635..873870ae0 100644 --- a/pkg/controller/jaeger/jaeger_controller.go +++ b/pkg/controller/jaeger/jaeger_controller.go @@ -250,7 +250,7 @@ func (r *ReconcileJaeger) apply(ctx context.Context, jaeger v1.Jaeger, str strat if v1.ShouldInjectOpenShiftElasticsearchConfiguration(jaeger.Spec.Storage) && // generate the certs only if cert management is disabled (jaeger.Spec.Storage.Elasticsearch.UseCertManagement == nil || - *jaeger.Spec.Storage.Elasticsearch.UseCertManagement == false) { + !*jaeger.Spec.Storage.Elasticsearch.UseCertManagement) { opts := client.MatchingLabels(map[string]string{ "app.kubernetes.io/instance": jaeger.Name, diff --git a/pkg/controller/jaeger/jaeger_controller_test.go b/pkg/controller/jaeger/jaeger_controller_test.go index 258a6e116..15da67935 100644 --- a/pkg/controller/jaeger/jaeger_controller_test.go +++ b/pkg/controller/jaeger/jaeger_controller_test.go @@ -180,7 +180,7 @@ func TestSyncOnJaegerChanges(t *testing.T) { assert.Equal(t, errList, err) cl.listErr = nil - err = syncOnJaegerChanges(cl, cl, jaeger.Name) + _ = syncOnJaegerChanges(cl, cl, jaeger.Name) assert.Equal(t, 3, cl.counter) cl.counter = 0 cl.getErr = nil @@ -194,7 +194,6 @@ func TestSyncOnJaegerChanges(t *testing.T) { err = syncOnJaegerChanges(cl, cl, jaeger.Name) assert.Equal(t, 1, cl.counter) assert.Equal(t, errUpdate, err) - } func TestNewJaegerInstance(t *testing.T) { @@ -265,7 +264,7 @@ func TestDeletedInstance(t *testing.T) { assert.False(t, res.Requeue, "We don't requeue for now") persisted := &v1.Jaeger{} - err = cl.Get(context.Background(), req.NamespacedName, persisted) + _ = cl.Get(context.Background(), req.NamespacedName, persisted) assert.NotEmpty(t, jaeger.Name) assert.Empty(t, persisted.Name) // this means that the object wasn't found } diff --git a/pkg/controller/jaeger/kafka.go b/pkg/controller/jaeger/kafka.go index 9890ecb5d..3669ee9b0 100644 --- a/pkg/controller/jaeger/kafka.go +++ b/pkg/controller/jaeger/kafka.go @@ -20,10 +20,8 @@ import ( "github.com/jaegertracing/jaeger-operator/pkg/tracing" ) -var ( - // ErrKafkaRemoved is returned when a kafka existed but has been removed - ErrKafkaRemoved = errors.New("kafka has been removed") -) +// ErrKafkaRemoved is returned when a kafka existed but has been removed +var ErrKafkaRemoved = errors.New("kafka has been removed") func (r *ReconcileJaeger) applyKafkas(ctx context.Context, jaeger v1.Jaeger, desired []kafkav1beta2.Kafka) error { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) diff --git a/pkg/controller/jaeger/kafkauser.go b/pkg/controller/jaeger/kafkauser.go index ee5fba6d3..1df888b1e 100644 --- a/pkg/controller/jaeger/kafkauser.go +++ b/pkg/controller/jaeger/kafkauser.go @@ -20,10 +20,8 @@ import ( "github.com/jaegertracing/jaeger-operator/pkg/tracing" ) -var ( - // ErrKafkaUserRemoved is returned when a kafka user existed but has been removed - ErrKafkaUserRemoved = errors.New("kafka user has been removed") -) +// ErrKafkaUserRemoved is returned when a kafka user existed but has been removed +var ErrKafkaUserRemoved = errors.New("kafka user has been removed") func (r *ReconcileJaeger) applyKafkaUsers(ctx context.Context, jaeger v1.Jaeger, desired []kafkav1beta2.KafkaUser) error { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) diff --git a/pkg/controller/jaeger/upgrade_test.go b/pkg/controller/jaeger/upgrade_test.go index 3326c520c..85fd33dfb 100644 --- a/pkg/controller/jaeger/upgrade_test.go +++ b/pkg/controller/jaeger/upgrade_test.go @@ -24,7 +24,7 @@ func TestDirectNextMinor(t *testing.T) { j := *v1.NewJaeger(nsn) j.Status.Version = "1.12.0" - //test + // test j, err := r.applyUpgrades(context.Background(), j) // verify @@ -40,7 +40,7 @@ func TestSetVersionOnNewInstance(t *testing.T) { r := &ReconcileJaeger{} j := *v1.NewJaeger(types.NamespacedName{Name: "my-instance"}) - //test + // test j, err := r.applyUpgrades(context.Background(), j) // verify diff --git a/pkg/controller/namespace/namespace_controller_test.go b/pkg/controller/namespace/namespace_controller_test.go index 2a545c706..995ee43f8 100644 --- a/pkg/controller/namespace/namespace_controller_test.go +++ b/pkg/controller/namespace/namespace_controller_test.go @@ -172,7 +172,6 @@ func TestReconcilieDeployment(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { - ns := &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: depNamespace, diff --git a/pkg/cronjob/es_index_cleaner_test.go b/pkg/cronjob/es_index_cleaner_test.go index a99107197..1ffb6ce79 100644 --- a/pkg/cronjob/es_index_cleaner_test.go +++ b/pkg/cronjob/es_index_cleaner_test.go @@ -150,7 +150,6 @@ func TestEsIndexCleanerLabels(t *testing.T) { } func TestEsIndexCleanerResources(t *testing.T) { - parentResources := corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceLimitsCPU: *resource.NewQuantity(1024, resource.BinarySI), diff --git a/pkg/cronjob/es_rollover_test.go b/pkg/cronjob/es_rollover_test.go index fb8b8b9d4..eb0cdd02f 100644 --- a/pkg/cronjob/es_rollover_test.go +++ b/pkg/cronjob/es_rollover_test.go @@ -204,7 +204,6 @@ func TestEsRolloverLabels(t *testing.T) { } func TestEsRolloverResources(t *testing.T) { - parentResources := corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceLimitsCPU: *resource.NewQuantity(1024, resource.BinarySI), @@ -307,7 +306,6 @@ func TestEsRolloverLookbackLabels(t *testing.T) { } func TestEsRolloverLookbackResources(t *testing.T) { - parentResources := corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceLimitsCPU: *resource.NewQuantity(1024, resource.BinarySI), diff --git a/pkg/cronjob/spark_dependencies_test.go b/pkg/cronjob/spark_dependencies_test.go index dc298336a..63992567f 100644 --- a/pkg/cronjob/spark_dependencies_test.go +++ b/pkg/cronjob/spark_dependencies_test.go @@ -27,9 +27,14 @@ func TestStorageEnvs(t *testing.T) { expected []corev1.EnvVar }{ {storage: v1.JaegerStorageSpec{Type: "foo"}}, - {storage: v1.JaegerStorageSpec{Type: v1.JaegerCassandraStorage, - Options: v1.NewOptions(map[string]interface{}{"cassandra.servers": "lol:hol", "cassandra.keyspace": "haha", - "cassandra.username": "jdoe", "cassandra.password": "none"})}, + { + storage: v1.JaegerStorageSpec{ + Type: v1.JaegerCassandraStorage, + Options: v1.NewOptions(map[string]interface{}{ + "cassandra.servers": "lol:hol", "cassandra.keyspace": "haha", + "cassandra.username": "jdoe", "cassandra.password": "none", + }), + }, expected: []corev1.EnvVar{ {Name: "CASSANDRA_CONTACT_POINTS", Value: "lol:hol"}, {Name: "CASSANDRA_KEYSPACE", Value: "haha"}, @@ -38,10 +43,16 @@ func TestStorageEnvs(t *testing.T) { {Name: "CASSANDRA_USE_SSL", Value: ""}, {Name: "CASSANDRA_LOCAL_DC", Value: ""}, {Name: "CASSANDRA_CLIENT_AUTH_ENABLED", Value: "false"}, - }}, - {storage: v1.JaegerStorageSpec{Type: v1.JaegerCassandraStorage, - Options: v1.NewOptions(map[string]interface{}{"cassandra.servers": "lol:hol", "cassandra.keyspace": "haha", - "cassandra.username": "jdoe", "cassandra.password": "none", "cassandra.tls": "ofcourse!", "cassandra.local-dc": "no-remote"})}, + }, + }, + { + storage: v1.JaegerStorageSpec{ + Type: v1.JaegerCassandraStorage, + Options: v1.NewOptions(map[string]interface{}{ + "cassandra.servers": "lol:hol", "cassandra.keyspace": "haha", + "cassandra.username": "jdoe", "cassandra.password": "none", "cassandra.tls": "ofcourse!", "cassandra.local-dc": "no-remote", + }), + }, expected: []corev1.EnvVar{ {Name: "CASSANDRA_CONTACT_POINTS", Value: "lol:hol"}, {Name: "CASSANDRA_KEYSPACE", Value: "haha"}, @@ -50,10 +61,16 @@ func TestStorageEnvs(t *testing.T) { {Name: "CASSANDRA_USE_SSL", Value: "ofcourse!"}, {Name: "CASSANDRA_LOCAL_DC", Value: "no-remote"}, {Name: "CASSANDRA_CLIENT_AUTH_ENABLED", Value: "false"}, - }}, - {storage: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, - Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "lol:hol", "es.index-prefix": "haha", - "es.index-date-separator": ".", "es.username": "jdoe", "es.password": "none"})}, + }, + }, + { + storage: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, + Options: v1.NewOptions(map[string]interface{}{ + "es.server-urls": "lol:hol", "es.index-prefix": "haha", + "es.index-date-separator": ".", "es.username": "jdoe", "es.password": "none", + }), + }, expected: []corev1.EnvVar{ {Name: "ES_NODES", Value: "lol:hol"}, {Name: "ES_INDEX_PREFIX", Value: "haha"}, @@ -61,11 +78,17 @@ func TestStorageEnvs(t *testing.T) { {Name: "ES_USERNAME", Value: "jdoe"}, {Name: "ES_PASSWORD", Value: "none"}, {Name: "ES_TIME_RANGE", Value: ""}, - }}, - {storage: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, - Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "lol:hol", "es.index-prefix": "haha", - "es.index-date-separator": ".", "es.username": "jdoe", "es.password": "none"}), - Dependencies: v1.JaegerDependenciesSpec{ElasticsearchClientNodeOnly: &trueVar, ElasticsearchNodesWanOnly: &falseVar}}, + }, + }, + { + storage: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, + Options: v1.NewOptions(map[string]interface{}{ + "es.server-urls": "lol:hol", "es.index-prefix": "haha", + "es.index-date-separator": ".", "es.username": "jdoe", "es.password": "none", + }), + Dependencies: v1.JaegerDependenciesSpec{ElasticsearchClientNodeOnly: &trueVar, ElasticsearchNodesWanOnly: &falseVar}, + }, expected: []corev1.EnvVar{ {Name: "ES_NODES", Value: "lol:hol"}, {Name: "ES_INDEX_PREFIX", Value: "haha"}, @@ -75,11 +98,17 @@ func TestStorageEnvs(t *testing.T) { {Name: "ES_TIME_RANGE", Value: ""}, {Name: "ES_NODES_WAN_ONLY", Value: "false"}, {Name: "ES_CLIENT_NODE_ONLY", Value: "true"}, - }}, - {storage: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, - Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "lol:hol", "es.index-prefix": "haha", - "es.username": "jdoe", "es.password": "none"}), - Dependencies: v1.JaegerDependenciesSpec{ElasticsearchTimeRange: "30m"}}, + }, + }, + { + storage: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, + Options: v1.NewOptions(map[string]interface{}{ + "es.server-urls": "lol:hol", "es.index-prefix": "haha", + "es.username": "jdoe", "es.password": "none", + }), + Dependencies: v1.JaegerDependenciesSpec{ElasticsearchTimeRange: "30m"}, + }, expected: []corev1.EnvVar{ {Name: "ES_NODES", Value: "lol:hol"}, {Name: "ES_INDEX_PREFIX", Value: "haha"}, @@ -87,7 +116,8 @@ func TestStorageEnvs(t *testing.T) { {Name: "ES_USERNAME", Value: "jdoe"}, {Name: "ES_PASSWORD", Value: "none"}, {Name: "ES_TIME_RANGE", Value: "30m"}, - }}, + }, + }, } for _, test := range tests { envVars := getStorageEnvs(test.storage) @@ -173,7 +203,6 @@ func TestDependenciesLabels(t *testing.T) { } func TestSparkDependenciesResources(t *testing.T) { - parentResources := corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceLimitsCPU: *resource.NewQuantity(1024, resource.BinarySI), diff --git a/pkg/deployment/agent.go b/pkg/deployment/agent.go index b73d8aeb0..ed234e629 100644 --- a/pkg/deployment/agent.go +++ b/pkg/deployment/agent.go @@ -39,7 +39,7 @@ func (a *Agent) Get() *appsv1.DaemonSet { return nil } - args := append(a.jaeger.Spec.Agent.Options.ToArgs()) + args := a.jaeger.Spec.Agent.Options.ToArgs() // we only add the grpc host if we are adding the reporter type and there's no explicit value yet if len(util.FindItem("--reporter.grpc.host-port=", args)) == 0 { diff --git a/pkg/deployment/agent_test.go b/pkg/deployment/agent_test.go index 02f266219..a3b3c68af 100644 --- a/pkg/deployment/agent_test.go +++ b/pkg/deployment/agent_test.go @@ -278,7 +278,6 @@ func TestAgentArgumentsOpenshiftTLS(t *testing.T) { assert.Len(t, dep.Spec.Template.Spec.Containers[0].VolumeMounts, 2) }) } - } func TestAgentImagePullSecrets(t *testing.T) { diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index e95bbee68..c264b358c 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -39,12 +39,12 @@ func (a *AllInOne) Get() *appsv1.Deployment { trueVar := true falseVar := false - args := append(a.jaeger.Spec.AllInOne.Options.ToArgs()) + args := a.jaeger.Spec.AllInOne.Options.ToArgs() adminPort := util.GetAdminPort(args, 14269) jaegerDisabled := false - if a.jaeger.Spec.AllInOne.TracingEnabled != nil && *a.jaeger.Spec.AllInOne.TracingEnabled == false { + if a.jaeger.Spec.AllInOne.TracingEnabled != nil && !*a.jaeger.Spec.AllInOne.TracingEnabled { jaegerDisabled = true } @@ -262,7 +262,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { // Services returns a list of services to be deployed along with the all-in-one deployment func (a *AllInOne) Services() []*corev1.Service { // merge defined labels with default labels - spec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.AllInOne.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, v1.JaegerCommonSpec{Labels: a.labels()}}) + spec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.AllInOne.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, {Labels: a.labels()}}) labels := spec.Labels return append(service.NewCollectorServices(a.jaeger, labels), diff --git a/pkg/deployment/all_in_one_test.go b/pkg/deployment/all_in_one_test.go index a94ced436..26ca4b35c 100644 --- a/pkg/deployment/all_in_one_test.go +++ b/pkg/deployment/all_in_one_test.go @@ -450,7 +450,6 @@ func TestAllInOneArgumentsOpenshiftTLS(t *testing.T) { } } } - } func TestAllInOneServiceLinks(t *testing.T) { diff --git a/pkg/deployment/autoscale.go b/pkg/deployment/autoscale.go index 739eb68a5..ebcd1aacf 100644 --- a/pkg/deployment/autoscale.go +++ b/pkg/deployment/autoscale.go @@ -28,7 +28,6 @@ type component interface { // Autoscalers returns a list of HPAs based on specs func autoscalers(component component) []autoscalingv2beta2.HorizontalPodAutoscaler { - // fixed number of replicas is explicitly set, do not auto scale if component.replicas() != nil { return []autoscalingv2beta2.HorizontalPodAutoscaler{} @@ -37,7 +36,7 @@ func autoscalers(component component) []autoscalingv2beta2.HorizontalPodAutoscal autoScaleSpec := component.autoscalingSpec() // explicitly disabled, do not auto scale - if autoScaleSpec.Autoscale != nil && *autoScaleSpec.Autoscale == false { + if autoScaleSpec.Autoscale != nil && !*autoScaleSpec.Autoscale { return []autoscalingv2beta2.HorizontalPodAutoscaler{} } diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index 399a0247c..7e206e53a 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -39,7 +39,7 @@ func (c *Collector) Get() *appsv1.Deployment { trueVar := true falseVar := false - args := append(c.jaeger.Spec.Collector.Options.ToArgs()) + args := c.jaeger.Spec.Collector.Options.ToArgs() adminPort := util.GetAdminPort(args, 14269) diff --git a/pkg/deployment/collector_test.go b/pkg/deployment/collector_test.go index 30fd9059d..42628c135 100644 --- a/pkg/deployment/collector_test.go +++ b/pkg/deployment/collector_test.go @@ -637,7 +637,6 @@ func TestCollectoArgumentsOpenshiftTLS(t *testing.T) { } }) } - } func TestCollectorServiceLinks(t *testing.T) { @@ -786,30 +785,3 @@ func TestCollectorContainerSecurityContextOverride(t *testing.T) { assert.Equal(t, overrideSecurityContextVar, *dep.Spec.Template.Spec.Containers[0].SecurityContext) } - -func hasVolume(name string, volumes []corev1.Volume) bool { - for _, v := range volumes { - if v.Name == name { - return true - } - } - return false -} - -func hasVolumeMount(name string, volumeMounts []corev1.VolumeMount) bool { - for _, v := range volumeMounts { - if v.Name == name { - return true - } - } - return false -} - -func hasArgument(arg string, args []string) bool { - for _, v := range args { - if v == arg { - return true - } - } - return false -} diff --git a/pkg/deployment/ingester.go b/pkg/deployment/ingester.go index b3d6bfb58..0775a4359 100644 --- a/pkg/deployment/ingester.go +++ b/pkg/deployment/ingester.go @@ -45,7 +45,7 @@ func (i *Ingester) Get() *appsv1.Deployment { trueVar := true falseVar := false - args := append(i.jaeger.Spec.Ingester.Options.ToArgs()) + args := i.jaeger.Spec.Ingester.Options.ToArgs() adminPort := util.GetAdminPort(args, 14270) diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index 6a254fbf5..dd2618f97 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -36,7 +36,7 @@ func (q *Query) Get() *appsv1.Deployment { trueVar := true falseVar := false - args := append(q.jaeger.Spec.Query.Options.ToArgs()) + args := q.jaeger.Spec.Query.Options.ToArgs() adminPort := util.GetAdminPort(args, 16687) @@ -50,7 +50,7 @@ func (q *Query) Get() *appsv1.Deployment { } jaegerDisabled := false - if q.jaeger.Spec.Query.TracingEnabled != nil && *q.jaeger.Spec.Query.TracingEnabled == false { + if q.jaeger.Spec.Query.TracingEnabled != nil && !*q.jaeger.Spec.Query.TracingEnabled { jaegerDisabled = true } else { // note that we are explicitly using a string here, not the value from `inject.Annotation` diff --git a/pkg/ingress/query.go b/pkg/ingress/query.go index 9cf27befe..0f67c7f14 100644 --- a/pkg/ingress/query.go +++ b/pkg/ingress/query.go @@ -23,7 +23,7 @@ func NewQueryIngress(jaeger *v1.Jaeger) *QueryIngress { // Get returns an ingress specification for the current instance func (i *QueryIngress) Get() *networkingv1.Ingress { - if i.jaeger.Spec.Ingress.Enabled != nil && *i.jaeger.Spec.Ingress.Enabled == false { + if i.jaeger.Spec.Ingress.Enabled != nil && !*i.jaeger.Spec.Ingress.Enabled { return nil } @@ -64,7 +64,7 @@ func (i *QueryIngress) Get() *networkingv1.Ingress { Namespace: i.jaeger.Namespace, Labels: commonSpec.Labels, OwnerReferences: []metav1.OwnerReference{ - metav1.OwnerReference{ + { APIVersion: i.jaeger.APIVersion, Kind: i.jaeger.Kind, Name: i.jaeger.Name, @@ -136,7 +136,7 @@ func getRule(host string, path string, backend *networkingv1.IngressBackend) net rule.Host = host rule.HTTP = &networkingv1.HTTPIngressRuleValue{ Paths: []networkingv1.HTTPIngressPath{ - networkingv1.HTTPIngressPath{ + { PathType: &pathType, Path: path, Backend: *backend, diff --git a/pkg/ingress/query_test.go b/pkg/ingress/query_test.go index 918b1affb..2ec153843 100644 --- a/pkg/ingress/query_test.go +++ b/pkg/ingress/query_test.go @@ -205,7 +205,7 @@ func TestQueryIngressQueryBasePathWithHosts(t *testing.T) { assert.NotNil(t, dep.Spec.Rules[0].HTTP.Paths[0].Backend) } -//TODO: Remove this test when ingress.secretName is removed from the spec +// TODO: Remove this test when ingress.secretName is removed from the spec func TestQueryIngressDeprecatedSecretName(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestQueryIngressDeprecatedSecretName"}) @@ -217,14 +217,14 @@ func TestQueryIngressDeprecatedSecretName(t *testing.T) { assert.Equal(t, "test-secret", dep.Spec.TLS[0].SecretName) } -//TODO: Remove this test when ingress.secretName is removed from the spec +// TODO: Remove this test when ingress.secretName is removed from the spec func TestQueryIngressTLSOverridesDeprecatedSecretName(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestQueryIngressTLSOverridesDeprecatedSecretName"}) jaeger.Spec.Ingress.SecretName = "test-secret-secret-name" jaeger.Spec.Ingress.TLS = []v1.JaegerIngressTLSSpec{ - v1.JaegerIngressTLSSpec{ + { SecretName: "test-secret-tls", }, } @@ -240,7 +240,7 @@ func TestQueryIngressTLSSecret(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestQueryIngressTLSSecret"}) jaeger.Spec.Ingress.TLS = []v1.JaegerIngressTLSSpec{ - v1.JaegerIngressTLSSpec{ + { SecretName: "test-secret", }, } @@ -266,17 +266,16 @@ func TestQueryIngressClass(t *testing.T) { assert.NotNil(t, dep.Spec.IngressClassName) assert.Equal(t, "nginx", *dep.Spec.IngressClassName) assert.Nil(t, ingressNoClass.Get().Spec.IngressClassName) - } func TestQueryIngressTLSHosts(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestQueryIngressTLSHosts"}) jaeger.Spec.Ingress.TLS = []v1.JaegerIngressTLSSpec{ - v1.JaegerIngressTLSSpec{ + { Hosts: []string{"test-host-1"}, }, - v1.JaegerIngressTLSSpec{ + { Hosts: []string{"test-host-2", "test-host-3"}, }, } diff --git a/pkg/inject/oauth_proxy.go b/pkg/inject/oauth_proxy.go index 2b0adf45a..7032adea9 100644 --- a/pkg/inject/oauth_proxy.go +++ b/pkg/inject/oauth_proxy.go @@ -113,7 +113,7 @@ func getOAuthProxyContainer(jaeger *v1.Jaeger) corev1.Container { } } -//PropagateOAuthCookieSecret preserve the generated oauth cookie across multiple reconciliations +// PropagateOAuthCookieSecret preserve the generated oauth cookie across multiple reconciliations func PropagateOAuthCookieSecret(specSrc, specDst appsv1.DeploymentSpec) appsv1.DeploymentSpec { spec := specDst.DeepCopy() secretArg := "" diff --git a/pkg/inject/sidecar.go b/pkg/inject/sidecar.go index b5fe7ed44..47a9149c3 100644 --- a/pkg/inject/sidecar.go +++ b/pkg/inject/sidecar.go @@ -36,7 +36,6 @@ var ( ) const ( - envVarTags = "JAEGER_TAGS" envVarServiceName = "JAEGER_SERVICE_NAME" envVarPropagation = "JAEGER_PROPAGATION" envVarPodName = "POD_NAME" @@ -196,7 +195,7 @@ func getJaeger(name string, jaegers *v1.JaegerList) *v1.Jaeger { } func container(jaeger *v1.Jaeger, dep *appsv1.Deployment, agentIdx int) corev1.Container { - args := append(jaeger.Spec.Agent.Options.ToArgs()) + args := jaeger.Spec.Agent.Options.ToArgs() // we only add the grpc host if we are adding the reporter type and there's no explicit value yet if len(util.FindItem("--reporter.grpc.host-port=", args)) == 0 { @@ -349,7 +348,6 @@ func decorate(dep *appsv1.Deployment) { dep.Annotations[key] = value } } - } func hasEnv(name string, vars []corev1.EnvVar) bool { diff --git a/pkg/inject/sidecar_test.go b/pkg/inject/sidecar_test.go index 6cfb6ebe7..7a9f8d067 100644 --- a/pkg/inject/sidecar_test.go +++ b/pkg/inject/sidecar_test.go @@ -244,7 +244,6 @@ func TestInjectSidecarWithVolumeMounts(t *testing.T) { } func TestSidecarImagePullSecrets(t *testing.T) { - deploymentImagePullSecrets := []corev1.LocalObjectReference{{ Name: "deploymentImagePullSecret", }} @@ -299,7 +298,6 @@ func TestSkipInjectSidecar(t *testing.T) { } func TestSidecarNeeded(t *testing.T) { - jaeger := v1.NewJaeger(types.NamespacedName{Name: "some-jaeger-instance"}) depWithAgent := dep(map[string]string{ @@ -780,7 +778,6 @@ func containsOptionWithPrefix(t *testing.T, args []string, prefix string) bool { } func TestSidecarArgumentsOpenshiftTLS(t *testing.T) { - viper.Set("platform", v1.FlagPlatformOpenShift) defer viper.Reset() @@ -890,33 +887,6 @@ func TestEqualSidecar(t *testing.T) { assert.False(t, EqualSidecar(dep1, dep3)) } -func hasVolume(name string, volumes []corev1.Volume) bool { - for _, v := range volumes { - if v.Name == name { - return true - } - } - return false -} - -func hasVolumeMount(name string, volumeMounts []corev1.VolumeMount) bool { - for _, v := range volumeMounts { - if v.Name == name { - return true - } - } - return false -} - -func hasArgument(arg string, args []string) bool { - for _, v := range args { - if v == arg { - return true - } - } - return false -} - func TestInjectSidecarOnOpenShift(t *testing.T) { viper.Set("platform", v1.FlagPlatformOpenShift) defer viper.Reset() diff --git a/pkg/inventory/kafka.go b/pkg/inventory/kafka.go index 478775bbf..c2141a6d2 100644 --- a/pkg/inventory/kafka.go +++ b/pkg/inventory/kafka.go @@ -36,7 +36,6 @@ func ForKafkas(existing []v1beta2.Kafka, desired []v1beta2.Kafka) Kafka { "kafka", k.GetName(), "namespace", k.GetNamespace(), ) - } for k, v := range mcreate { diff --git a/pkg/metrics/instances.go b/pkg/metrics/instances.go index a292eaf0e..42bfe379e 100644 --- a/pkg/metrics/instances.go +++ b/pkg/metrics/instances.go @@ -14,13 +14,15 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/apis/v1" ) -const metricPrefix = "jaeger_operator_instances" -const agentStrategiesMetric = "agent_strategies" -const storageMetric = "storage_types" -const strategiesMetric = "strategies" -const autoprovisioningMetric = "autoprovisioning" -const managedMetric = "managed" -const managedByLabel = "app.kubernetes.io/managed-by" +const ( + metricPrefix = "jaeger_operator_instances" + agentStrategiesMetric = "agent_strategies" + storageMetric = "storage_types" + strategiesMetric = "strategies" + autoprovisioningMetric = "autoprovisioning" + managedMetric = "managed" + managedByLabel = "app.kubernetes.io/managed-by" +) // This structure contains the labels associated with the instances and a counter of the number of instances type instancesView struct { @@ -84,7 +86,7 @@ func newObservation(batch metric.BatchObserver, name, desc, label string, keyFn func (i *instancesMetric) Setup(ctx context.Context) error { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "setup-jaeger-instances-metrics") + ctx, span := tracer.Start(ctx, "setup-jaeger-instances-metrics") // nolint:ineffassign,staticcheck defer span.End() meter := global.Meter(meterName) batch := meter.NewBatchObserver(i.callback) @@ -95,7 +97,6 @@ func (i *instancesMetric) Setup(ctx context.Context) error { func(jaeger v1.Jaeger) string { return strings.ToLower(string(jaeger.Spec.Agent.Strategy)) }) - if err != nil { return err } diff --git a/pkg/metrics/instances_test.go b/pkg/metrics/instances_test.go index a3747cf75..9f6001fc3 100644 --- a/pkg/metrics/instances_test.go +++ b/pkg/metrics/instances_test.go @@ -20,8 +20,10 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/apis/v1" ) -const AgentSideCar = "Sidecar" -const AgentDaemonSet = "Daemonset" +const ( + AgentSideCar = "Sidecar" + AgentDaemonSet = "Daemonset" +) type expectedMetric struct { name string @@ -31,7 +33,7 @@ type expectedMetric struct { func assertLabelAndValues(t *testing.T, name string, batches []oteltest.Batch, expectedLabels []attribute.KeyValue, expectedValue int64) { var measurement oteltest.Measurement - var found = false + found := false for _, b := range batches { for _, m := range b.Measurements { if m.Instrument.Descriptor().Name() == name && reflect.DeepEqual(expectedLabels, b.Labels) { @@ -45,11 +47,11 @@ func assertLabelAndValues(t *testing.T, name string, batches []oteltest.Batch, e v := oteltest.ResolveNumberByKind(t, number.Int64Kind, float64(expectedValue)) assert.Equal(t, 0, measurement.Number.CompareNumber(number.Int64Kind, v), "Metric %s doesn't have expected value %d", name, expectedValue) - } func newJaegerInstance(nsn types.NamespacedName, strategy v1.DeploymentStrategy, - storage v1.JaegerStorageType, agentMode string) v1.Jaeger { + storage v1.JaegerStorageType, agentMode string, +) v1.Jaeger { return v1.Jaeger{ ObjectMeta: metav1.ObjectMeta{ Name: nsn.Name, @@ -225,12 +227,11 @@ func TestAutoProvisioningESObservedMetric(t *testing.T) { assertLabelAndValues(t, expectedMetric.name, meter.MeasurementBatches, expectedMetric.labels, expectedMetric.value) // Create no autoprovisioned instance - err = cl.Delete(context.Background(), &noAutoProvisioningInstance) + _ = cl.Delete(context.Background(), &noAutoProvisioningInstance) meter.MeasurementBatches = []oteltest.Batch{} meter.RunAsyncInstruments() expectedMetric = newExpectedMetric(autoprovisioningMetric, attribute.String("type", "elasticsearch"), 0) assertLabelAndValues(t, expectedMetric.name, meter.MeasurementBatches, expectedMetric.labels, expectedMetric.value) - } func TestManagerByMetric(t *testing.T) { diff --git a/pkg/route/query.go b/pkg/route/query.go index 6848fd241..a86a5c173 100644 --- a/pkg/route/query.go +++ b/pkg/route/query.go @@ -22,7 +22,7 @@ func NewQueryRoute(jaeger *v1.Jaeger) *QueryRoute { // Get returns an ingress specification for the current instance func (r *QueryRoute) Get() *corev1.Route { - if r.jaeger.Spec.Ingress.Enabled != nil && *r.jaeger.Spec.Ingress.Enabled == false { + if r.jaeger.Spec.Ingress.Enabled != nil && !*r.jaeger.Spec.Ingress.Enabled { return nil } @@ -58,7 +58,7 @@ func (r *QueryRoute) Get() *corev1.Route { Namespace: r.jaeger.Namespace, Labels: util.Labels(r.jaeger.Name, "query-route", *r.jaeger), OwnerReferences: []metav1.OwnerReference{ - metav1.OwnerReference{ + { APIVersion: r.jaeger.APIVersion, Kind: r.jaeger.Kind, Name: r.jaeger.Name, diff --git a/pkg/service/agent.go b/pkg/service/agent.go index fe11cbc02..625ae021e 100644 --- a/pkg/service/agent.go +++ b/pkg/service/agent.go @@ -23,7 +23,7 @@ func NewAgentService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Serv Namespace: jaeger.Namespace, Labels: util.Labels(name, "service-agent", *jaeger), OwnerReferences: []metav1.OwnerReference{ - metav1.OwnerReference{ + { APIVersion: jaeger.APIVersion, Kind: jaeger.Kind, Name: jaeger.Name, diff --git a/pkg/service/agent_test.go b/pkg/service/agent_test.go index 82bf71cca..84357d230 100644 --- a/pkg/service/agent_test.go +++ b/pkg/service/agent_test.go @@ -39,5 +39,4 @@ func TestAgentServiceNameAndPorts(t *testing.T) { for k, v := range ports { assert.Equal(t, true, v, "Expected port %v to be specified, but wasn't", k) } - } diff --git a/pkg/service/collector_test.go b/pkg/service/collector_test.go index f1fdbbc12..dfd209184 100644 --- a/pkg/service/collector_test.go +++ b/pkg/service/collector_test.go @@ -143,6 +143,7 @@ func TestCollectorServiceLoadBalancer(t *testing.T) { // Only the non-headless service will receive the type assert.Equal(t, svc[1].Spec.Type, corev1.ServiceTypeLoadBalancer) } + func TestCollectorServiceAnnotations(t *testing.T) { name := "TestCollectorServiceLoadBalancer" selector := map[string]string{"app": "myapp", "jaeger": name, "jaeger-component": "collector"} diff --git a/pkg/service/query.go b/pkg/service/query.go index 8c3b10fe7..8470336df 100644 --- a/pkg/service/query.go +++ b/pkg/service/query.go @@ -50,7 +50,7 @@ func NewQueryService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Serv Labels: util.Labels(GetNameForQueryService(jaeger), "service-query", *jaeger), Annotations: annotations, OwnerReferences: []metav1.OwnerReference{ - metav1.OwnerReference{ + { APIVersion: jaeger.APIVersion, Kind: jaeger.Kind, Name: jaeger.Name, diff --git a/pkg/storage/elasticsearch.go b/pkg/storage/elasticsearch.go index a5dda66dc..d77f52377 100644 --- a/pkg/storage/elasticsearch.go +++ b/pkg/storage/elasticsearch.go @@ -169,7 +169,7 @@ func (ed *ElasticsearchDeployment) Elasticsearch() *esv1.Elasticsearch { } annotations := map[string]string{} - if ed.Jaeger.Spec.Storage.Elasticsearch.UseCertManagement != nil && *ed.Jaeger.Spec.Storage.Elasticsearch.UseCertManagement == true { + if ed.Jaeger.Spec.Storage.Elasticsearch.UseCertManagement != nil && *ed.Jaeger.Spec.Storage.Elasticsearch.UseCertManagement { annotations["logging.openshift.io/elasticsearch-cert-management"] = "true" // The value has to match searchguard configuration // https://github.com/openshift/origin-aggregated-logging/blob/50126fb8e0c602e9c623d6a8599857aaf98f80f8/elasticsearch/sgconfig/roles_mapping.yml#L34 diff --git a/pkg/storage/elasticsearch_dependencies.go b/pkg/storage/elasticsearch_dependencies.go index d6b470c2f..fed8a51fb 100644 --- a/pkg/storage/elasticsearch_dependencies.go +++ b/pkg/storage/elasticsearch_dependencies.go @@ -71,7 +71,7 @@ func elasticsearchDependencies(jaeger *v1.Jaeger) []batchv1.Job { } func envVars(opts v1.Options) []corev1.EnvVar { - var envs = cronjob.EsScriptEnvVars(opts) + envs := cronjob.EsScriptEnvVars(opts) scriptEnvVars := []struct { flag string envVar string diff --git a/pkg/storage/elasticsearch_dependencies_test.go b/pkg/storage/elasticsearch_dependencies_test.go index c0b6785b3..a795a6cc5 100644 --- a/pkg/storage/elasticsearch_dependencies_test.go +++ b/pkg/storage/elasticsearch_dependencies_test.go @@ -84,7 +84,8 @@ func TestEnvVars(t *testing.T) { "es.num-shards": "5", "es.num-replicas": "3", "es.password": "nopass", - "es.username": "fredy"}), + "es.username": "fredy", + }), expected: []corev1.EnvVar{ {Name: "INDEX_PREFIX", Value: "foo"}, {Name: "INDEX_DATE_SEPARATOR", Value: "."}, diff --git a/pkg/storage/elasticsearch_secretes_test.go b/pkg/storage/elasticsearch_secretes_test.go index 9f8ba4073..f6e5dd927 100644 --- a/pkg/storage/elasticsearch_secretes_test.go +++ b/pkg/storage/elasticsearch_secretes_test.go @@ -41,7 +41,8 @@ func TestCreateESSecrets(t *testing.T) { masterSecret.instanceName(j), esSecret.instanceName(j), jaegerSecret.instanceName(j), - curatorSecret.instanceName(j)}, + curatorSecret.instanceName(j), + }, []string{sec[0].Name, sec[1].Name, sec[2].Name, sec[3].Name}) for _, s := range sec { if s.Name == jaegerSecret.instanceName(j) { @@ -73,7 +74,7 @@ func TestGetWorkingFileDirContent(t *testing.T) { defer os.RemoveAll(dir) err := os.MkdirAll(dir, os.ModePerm) assert.NoError(t, err) - err = ioutil.WriteFile(dir+"/foobar", []byte("foo"), 0644) + err = ioutil.WriteFile(dir+"/foobar", []byte("foo"), 0o644) assert.NoError(t, err) b := getDirFileContents(dir, "foobar") assert.Equal(t, "foo", string(b)) diff --git a/pkg/storage/elasticsearch_secrets.go b/pkg/storage/elasticsearch_secrets.go index 2ad214d36..e0ed1f550 100644 --- a/pkg/storage/elasticsearch_secrets.go +++ b/pkg/storage/elasticsearch_secrets.go @@ -34,7 +34,7 @@ func (s secret) instanceName(jaeger *v1.Jaeger) string { } useCertManager := jaeger.Spec.Storage.Elasticsearch.UseCertManagement - if useCertManager != nil && *useCertManager == true { + if useCertManager != nil && *useCertManager { return fmt.Sprintf("curator-%s", jaeger.Spec.Storage.Elasticsearch.Name) } @@ -131,7 +131,6 @@ func extractSecretToFile(workingDir string, data map[string][]byte, secret secre for k, v := range secret.keyFileNameMap { if err := writeToFile(workingDir, v, data[k]); err != nil { return err - } } return nil @@ -211,7 +210,7 @@ func writeToFile(dir, file string, value []byte) error { if err := os.MkdirAll(dir, os.ModePerm); err != nil { return err } - f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600) + f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0o600) if err != nil { return err } diff --git a/pkg/storage/elasticsearch_test.go b/pkg/storage/elasticsearch_test.go index a23f88be9..65bd66f5e 100644 --- a/pkg/storage/elasticsearch_test.go +++ b/pkg/storage/elasticsearch_test.go @@ -264,10 +264,14 @@ func TestInject(t *testing.T) { {Name: volumeName, ReadOnly: true, MountPath: volumeMountPath}, }, }}, - Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "jtest-jaeger-elasticsearch"}}}, - }}, + Volumes: []corev1.Volume{ + {Name: "certs", VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "jtest-jaeger-elasticsearch", + }, + }}, + }, + }, }, { es: v1.ElasticsearchSpec{ @@ -298,10 +302,14 @@ func TestInject(t *testing.T) { {Name: volumeName, ReadOnly: true, MountPath: volumeMountPath}, }, }}, - Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "jaeger-elasticsearch"}}}, - }}, + Volumes: []corev1.Volume{ + {Name: "certs", VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "jaeger-elasticsearch", + }, + }}, + }, + }, }, { es: v1.ElasticsearchSpec{Name: "elasticsearch"}, @@ -326,10 +334,14 @@ func TestInject(t *testing.T) { {Name: volumeName, ReadOnly: true, MountPath: volumeMountPath}, }, }}, - Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "jtest-jaeger-elasticsearch"}}}, - }}, + Volumes: []corev1.Volume{ + {Name: "certs", VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "jtest-jaeger-elasticsearch", + }, + }}, + }, + }, }, { pod: &corev1.PodSpec{Containers: []corev1.Container{{}}}, @@ -354,10 +366,14 @@ func TestInject(t *testing.T) { {Name: volumeName, ReadOnly: true, MountPath: volumeMountPath}, }, }}, - Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "jtest-jaeger-my-es"}}}, - }}, + Volumes: []corev1.Volume{ + {Name: "certs", VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "jtest-jaeger-my-es", + }, + }}, + }, + }, }, { es: v1.ElasticsearchSpec{ @@ -397,10 +413,14 @@ func TestInject(t *testing.T) { {Name: volumeName, ReadOnly: true, MountPath: volumeMountPath}, }, }}, - Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "jtest-jaeger-es-tenant2"}}}, - }}, + Volumes: []corev1.Volume{ + {Name: "certs", VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "jtest-jaeger-es-tenant2", + }, + }}, + }, + }, }, } @@ -468,10 +488,14 @@ func TestInjectJobs(t *testing.T) { {Name: volumeName, ReadOnly: true, MountPath: volumeMountPath}, }, }}, - Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "jtest-curator"}}}, - }}, + Volumes: []corev1.Volume{ + {Name: "certs", VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "jtest-curator", + }, + }}, + }, + }, }, { name: "es-cert-management", @@ -520,10 +544,14 @@ func TestInjectJobs(t *testing.T) { {Name: volumeName, ReadOnly: true, MountPath: volumeMountPath}, }, }}, - Volumes: []corev1.Volume{{Name: "certs", VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "curator-elasticsearch"}}}, - }}, + Volumes: []corev1.Volume{ + {Name: "certs", VolumeSource: corev1.VolumeSource{ + Secret: &corev1.SecretVolumeSource{ + SecretName: "curator-elasticsearch", + }, + }}, + }, + }, }, } diff --git a/pkg/strategy/all_in_one.go b/pkg/strategy/all_in_one.go index 844ce580c..7f5327e11 100644 --- a/pkg/strategy/all_in_one.go +++ b/pkg/strategy/all_in_one.go @@ -24,7 +24,7 @@ import ( func newAllInOneStrategy(ctx context.Context, jaeger *v1.Jaeger) S { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) - ctx, span := tracer.Start(ctx, "newAllInOneStrategy") + ctx, span := tracer.Start(ctx, "newAllInOneStrategy") // nolint:ineffassign,staticcheck defer span.End() c := S{typ: v1.DeploymentStrategyAllInOne} diff --git a/pkg/strategy/all_in_one_test.go b/pkg/strategy/all_in_one_test.go index 9135f1f14..f7008a4e9 100644 --- a/pkg/strategy/all_in_one_test.go +++ b/pkg/strategy/all_in_one_test.go @@ -80,19 +80,6 @@ func TestNoAutoscaleForAllInOne(t *testing.T) { func assertDeploymentsAndServicesForAllInOne(t *testing.T, instance *v1.Jaeger, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) { // TODO(jpkroehling): this func deserves a refactoring already name := instance.Name - expectedNumObjs := 7 - - if hasDaemonSet { - expectedNumObjs++ - } - - if hasOAuthProxy { - expectedNumObjs++ - } - - if hasConfigMap { - expectedNumObjs++ - } // we should have one deployment, named after the Jaeger's name (ObjectMeta.Name) deployments := map[string]bool{ @@ -115,7 +102,7 @@ func assertDeploymentsAndServicesForAllInOne(t *testing.T, instance *v1.Jaeger, routes := map[string]bool{} consoleLinks := map[string]bool{} if viper.GetString("platform") == v1.FlagPlatformOpenShift { - routes[fmt.Sprintf("%s", util.DNSName(name))] = false + routes[util.DNSName(name)] = false consoleLinks[consolelink.Name(instance)] = false } else { @@ -147,16 +134,22 @@ func testSparkDependencies(t *testing.T, fce func(jaeger *v1.Jaeger) S) { sparkCronJobEnabled bool }{ {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ - Storage: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, - Dependencies: v1.JaegerDependenciesSpec{Enabled: &trueVar}}, + Storage: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, + Dependencies: v1.JaegerDependenciesSpec{Enabled: &trueVar}, + }, }}, sparkCronJobEnabled: true}, {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ - Storage: v1.JaegerStorageSpec{Type: v1.JaegerCassandraStorage, - Dependencies: v1.JaegerDependenciesSpec{Enabled: &trueVar}}, + Storage: v1.JaegerStorageSpec{ + Type: v1.JaegerCassandraStorage, + Dependencies: v1.JaegerDependenciesSpec{Enabled: &trueVar}, + }, }}, sparkCronJobEnabled: true}, {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ - Storage: v1.JaegerStorageSpec{Type: v1.JaegerKafkaStorage, - Dependencies: v1.JaegerDependenciesSpec{Enabled: &trueVar}}, + Storage: v1.JaegerStorageSpec{ + Type: v1.JaegerKafkaStorage, + Dependencies: v1.JaegerDependenciesSpec{Enabled: &trueVar}, + }, }}, sparkCronJobEnabled: false}, {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ Storage: v1.JaegerStorageSpec{Type: v1.JaegerESStorage}, @@ -187,16 +180,22 @@ func testEsIndexCleaner(t *testing.T, fce func(jaeger *v1.Jaeger) S) { sparkCronJobEnabled bool }{ {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ - Storage: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, - EsIndexCleaner: v1.JaegerEsIndexCleanerSpec{Enabled: &trueVar, NumberOfDays: &days}}, + Storage: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, + EsIndexCleaner: v1.JaegerEsIndexCleanerSpec{Enabled: &trueVar, NumberOfDays: &days}, + }, }}, sparkCronJobEnabled: true}, {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ - Storage: v1.JaegerStorageSpec{Type: v1.JaegerCassandraStorage, - EsIndexCleaner: v1.JaegerEsIndexCleanerSpec{Enabled: &trueVar, NumberOfDays: &days}}, + Storage: v1.JaegerStorageSpec{ + Type: v1.JaegerCassandraStorage, + EsIndexCleaner: v1.JaegerEsIndexCleanerSpec{Enabled: &trueVar, NumberOfDays: &days}, + }, }}, sparkCronJobEnabled: false}, {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ - Storage: v1.JaegerStorageSpec{Type: v1.JaegerKafkaStorage, - EsIndexCleaner: v1.JaegerEsIndexCleanerSpec{Enabled: &trueVar, NumberOfDays: &days}}, + Storage: v1.JaegerStorageSpec{ + Type: v1.JaegerKafkaStorage, + EsIndexCleaner: v1.JaegerEsIndexCleanerSpec{Enabled: &trueVar, NumberOfDays: &days}, + }, }}, sparkCronJobEnabled: false}, {jaeger: &v1.Jaeger{Spec: v1.JaegerSpec{ Storage: v1.JaegerStorageSpec{Type: v1.JaegerESStorage}, diff --git a/pkg/strategy/controller.go b/pkg/strategy/controller.go index cb76890e3..cfdf67e6c 100644 --- a/pkg/strategy/controller.go +++ b/pkg/strategy/controller.go @@ -55,7 +55,7 @@ func For(ctx context.Context, jaeger *v1.Jaeger) S { // needed and incompatible options are cleaned func normalize(ctx context.Context, jaeger *v1.Jaeger) { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) - ctx, span := tracer.Start(ctx, "normalize") + ctx, span := tracer.Start(ctx, "normalize") // nolint:ineffassign,staticcheck defer span.End() // we need a name! @@ -237,7 +237,7 @@ func enableArchiveButton(uiOpts map[string]interface{}, sOpts map[string]string) func disableDependenciesTab(uiOpts map[string]interface{}, storage v1.JaegerStorageType, depsEnabled *bool) { // dependency tab is by default enabled and memory storage support it - if (storage == v1.JaegerMemoryStorage) || (depsEnabled != nil && *depsEnabled == true) { + if (storage == v1.JaegerMemoryStorage) || (depsEnabled != nil && *depsEnabled) { return } deps := map[string]interface{}{} @@ -317,12 +317,12 @@ func enableDocumentationLink(uiOpts map[string]interface{}, spec *v1.JaegerSpec) } func enableLogOut(uiOpts map[string]interface{}, spec *v1.JaegerSpec) { - if (spec.Ingress.Enabled != nil && *spec.Ingress.Enabled == false) || + if (spec.Ingress.Enabled != nil && !*spec.Ingress.Enabled) || spec.Ingress.Security != v1.IngressSecurityOAuthProxy { return } - if spec.Ingress.Openshift.SkipLogout != nil && *spec.Ingress.Openshift.SkipLogout == true { + if spec.Ingress.Openshift.SkipLogout != nil && *spec.Ingress.Openshift.SkipLogout { return } diff --git a/pkg/strategy/controller_test.go b/pkg/strategy/controller_test.go index 5693001a2..e4f4c2c9e 100644 --- a/pkg/strategy/controller_test.go +++ b/pkg/strategy/controller_test.go @@ -200,10 +200,14 @@ func TestNormalizeIndexCleaner(t *testing.T) { underTest v1.JaegerEsIndexCleanerSpec expected v1.JaegerEsIndexCleanerSpec }{ - {underTest: v1.JaegerEsIndexCleanerSpec{}, - expected: v1.JaegerEsIndexCleanerSpec{Schedule: "55 23 * * *", NumberOfDays: &days7, Enabled: &trueVar}}, - {underTest: v1.JaegerEsIndexCleanerSpec{Image: "bla", Schedule: "lol", NumberOfDays: &days55, Enabled: &falseVar}, - expected: v1.JaegerEsIndexCleanerSpec{Image: "bla", Schedule: "lol", NumberOfDays: &days55, Enabled: &falseVar}}, + { + underTest: v1.JaegerEsIndexCleanerSpec{}, + expected: v1.JaegerEsIndexCleanerSpec{Schedule: "55 23 * * *", NumberOfDays: &days7, Enabled: &trueVar}, + }, + { + underTest: v1.JaegerEsIndexCleanerSpec{Image: "bla", Schedule: "lol", NumberOfDays: &days55, Enabled: &falseVar}, + expected: v1.JaegerEsIndexCleanerSpec{Image: "bla", Schedule: "lol", NumberOfDays: &days55, Enabled: &falseVar}, + }, } for _, test := range tests { normalizeIndexCleaner(&test.underTest, v1.JaegerESStorage) @@ -216,10 +220,14 @@ func TestNormalizeRollover(t *testing.T) { underTest v1.JaegerEsRolloverSpec expected v1.JaegerEsRolloverSpec }{ - {underTest: v1.JaegerEsRolloverSpec{}, - expected: v1.JaegerEsRolloverSpec{Schedule: "0 0 * * *"}}, - {underTest: v1.JaegerEsRolloverSpec{Image: "bla", Schedule: "lol"}, - expected: v1.JaegerEsRolloverSpec{Image: "bla", Schedule: "lol"}}, + { + underTest: v1.JaegerEsRolloverSpec{}, + expected: v1.JaegerEsRolloverSpec{Schedule: "0 0 * * *"}, + }, + { + underTest: v1.JaegerEsRolloverSpec{Image: "bla", Schedule: "lol"}, + expected: v1.JaegerEsRolloverSpec{Image: "bla", Schedule: "lol"}, + }, } for _, test := range tests { normalizeRollover(&test.underTest) @@ -236,31 +244,42 @@ func TestNormalizeSparkDependencies(t *testing.T) { }{ { underTest: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "foo"})}, - expected: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "foo"}), - Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: &trueVar}}, + expected: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "foo"}), + Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: &trueVar}, + }, }, { underTest: v1.JaegerStorageSpec{Type: v1.JaegerESStorage}, expected: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *"}}, }, { - underTest: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{}, - Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.tls": true})}, - expected: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: nil}, + underTest: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{}, + Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.tls": true}), + }, + expected: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: nil}, Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.tls": true}), }, }, { - underTest: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{}, - Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.skip-host-verify": false})}, - expected: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: &trueVar}, + underTest: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{}, + Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.skip-host-verify": false}), + }, + expected: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: &trueVar}, Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.skip-host-verify": false}), }, }, { - underTest: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{}, - Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.skip-host-verify": false, "es.tls.ca": "rr"})}, - expected: v1.JaegerStorageSpec{Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: nil}, + underTest: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{}, + Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.skip-host-verify": false, "es.tls.ca": "rr"}), + }, + expected: v1.JaegerStorageSpec{ + Type: v1.JaegerESStorage, Dependencies: v1.JaegerDependenciesSpec{Schedule: "55 23 * * *", Enabled: nil}, Options: v1.NewOptions(map[string]interface{}{"es.server-urls": "local", "es.skip-host-verify": false, "es.tls.ca": "rr"}), }, }, @@ -284,15 +303,22 @@ func TestNormalizeElasticsearch(t *testing.T) { underTest v1.ElasticsearchSpec expected v1.ElasticsearchSpec }{ - {underTest: v1.ElasticsearchSpec{}, - expected: v1.ElasticsearchSpec{NodeCount: 3, RedundancyPolicy: "SingleRedundancy", Resources: defResources}, + { + underTest: v1.ElasticsearchSpec{}, + expected: v1.ElasticsearchSpec{NodeCount: 3, RedundancyPolicy: "SingleRedundancy", Resources: defResources}, + }, + { + underTest: v1.ElasticsearchSpec{NodeCount: 1}, + expected: v1.ElasticsearchSpec{NodeCount: 1, RedundancyPolicy: "ZeroRedundancy", Resources: defResources}, + }, + { + underTest: v1.ElasticsearchSpec{NodeCount: 3, RedundancyPolicy: "FullRedundancy"}, + expected: v1.ElasticsearchSpec{NodeCount: 3, RedundancyPolicy: "FullRedundancy", Resources: defResources}, + }, + { + underTest: v1.ElasticsearchSpec{Image: "bla", NodeCount: 150, RedundancyPolicy: "ZeroRedundancy", Resources: &corev1.ResourceRequirements{}}, + expected: v1.ElasticsearchSpec{Image: "bla", NodeCount: 150, RedundancyPolicy: "ZeroRedundancy", Resources: &corev1.ResourceRequirements{}}, }, - {underTest: v1.ElasticsearchSpec{NodeCount: 1}, - expected: v1.ElasticsearchSpec{NodeCount: 1, RedundancyPolicy: "ZeroRedundancy", Resources: defResources}}, - {underTest: v1.ElasticsearchSpec{NodeCount: 3, RedundancyPolicy: "FullRedundancy"}, - expected: v1.ElasticsearchSpec{NodeCount: 3, RedundancyPolicy: "FullRedundancy", Resources: defResources}}, - {underTest: v1.ElasticsearchSpec{Image: "bla", NodeCount: 150, RedundancyPolicy: "ZeroRedundancy", Resources: &corev1.ResourceRequirements{}}, - expected: v1.ElasticsearchSpec{Image: "bla", NodeCount: 150, RedundancyPolicy: "ZeroRedundancy", Resources: &corev1.ResourceRequirements{}}}, } for _, test := range tests { normalizeElasticsearch(&test.underTest) @@ -315,8 +341,10 @@ func TestNormalizeUI(t *testing.T) { }, { j: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})}}, - expected: &v1.JaegerSpec{Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})}, - UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"archiveEnabled": true, "dependencies": map[string]interface{}{"menuEnabled": false}})}}, + expected: &v1.JaegerSpec{ + Storage: v1.JaegerStorageSpec{Options: v1.NewOptions(map[string]interface{}{"es-archive.enabled": "true"})}, + UI: v1.JaegerUISpec{Options: v1.NewFreeForm(map[string]interface{}{"archiveEnabled": true, "dependencies": map[string]interface{}{"menuEnabled": false}})}, + }, }, } for _, test := range tests { @@ -494,7 +522,6 @@ func TestUpdateMenuDocURL(t *testing.T) { }, } assert.Equal(t, expected, uiOpts["menu"]) - } func TestNoDocWithCustomMenu(t *testing.T) { @@ -517,7 +544,6 @@ func TestNoDocWithCustomMenu(t *testing.T) { spec := &v1.JaegerSpec{Ingress: v1.JaegerIngressSpec{Security: v1.IngressSecurityOAuthProxy}} enableDocumentationLink(uiOpts, spec) assert.Equal(t, uiOpts, uiOpts) - } func TestMenuNoLogOutIngressSecurityNone(t *testing.T) { diff --git a/pkg/strategy/production.go b/pkg/strategy/production.go index 805136f57..2692263d9 100644 --- a/pkg/strategy/production.go +++ b/pkg/strategy/production.go @@ -30,7 +30,7 @@ import ( func newProductionStrategy(ctx context.Context, jaeger *v1.Jaeger) S { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) - ctx, span := tracer.Start(ctx, "newProductionStrategy") + ctx, span := tracer.Start(ctx, "newProductionStrategy") // nolint:ineffassign,staticcheck defer span.End() c := S{typ: v1.DeploymentStrategyProduction} @@ -144,7 +144,6 @@ func newProductionStrategy(ctx context.Context, jaeger *v1.Jaeger) S { } else { jobs = append(jobs, &indexCleaner.(*batchv1.CronJob).Spec.JobTemplate.Spec.Template.Spec) } - } for i := range esRollover { if cronjobsVersion == v1.FlagCronJobsVersionBatchV1Beta1 { diff --git a/pkg/strategy/production_test.go b/pkg/strategy/production_test.go index 63337e1ae..d20af0c7f 100644 --- a/pkg/strategy/production_test.go +++ b/pkg/strategy/production_test.go @@ -128,19 +128,6 @@ func TestAutoscaleForProduction(t *testing.T) { func assertDeploymentsAndServicesForProduction(t *testing.T, instance *v1.Jaeger, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) { name := instance.Name - expectedNumObjs := 7 - - if hasDaemonSet { - expectedNumObjs++ - } - - if hasOAuthProxy { - expectedNumObjs++ - } - - if hasConfigMap { - expectedNumObjs++ - } deployments := map[string]bool{ fmt.Sprintf("%s-collector", name): false, @@ -166,7 +153,7 @@ func assertDeploymentsAndServicesForProduction(t *testing.T, instance *v1.Jaeger ingresses[fmt.Sprintf("%s-query", name)] = false } - serviceAccounts := map[string]bool{fmt.Sprintf("%s", name): false} + serviceAccounts := map[string]bool{name: false} if hasOAuthProxy { serviceAccounts[fmt.Sprintf("%s-ui-proxy", name)] = false } diff --git a/pkg/strategy/strategy.go b/pkg/strategy/strategy.go index 791f89e25..75bed59b1 100644 --- a/pkg/strategy/strategy.go +++ b/pkg/strategy/strategy.go @@ -250,9 +250,7 @@ func (s S) All() []runtime.Object { ret = append(ret, o.DeepCopy()) } - for _, o := range s.cronJobs { - ret = append(ret, o) - } + ret = append(ret, s.cronJobs...) for _, o := range s.elasticsearches { ret = append(ret, o.DeepCopy()) diff --git a/pkg/strategy/streaming.go b/pkg/strategy/streaming.go index f0f9d8647..d901d6fb2 100644 --- a/pkg/strategy/streaming.go +++ b/pkg/strategy/streaming.go @@ -144,7 +144,7 @@ func newStreamingStrategy(ctx context.Context, jaeger *v1.Jaeger) S { // prepare the deployments, which may get changed by the elasticsearch routine cDep := collector.Get() queryDep := inject.OAuthProxy(jaeger, query.Get()) - if jaeger.Spec.Query.TracingEnabled == nil || *jaeger.Spec.Query.TracingEnabled == true { + if jaeger.Spec.Query.TracingEnabled == nil || *jaeger.Spec.Query.TracingEnabled { queryDep = inject.Sidecar(jaeger, queryDep) } var ingesterDep *appsv1.Deployment @@ -198,7 +198,7 @@ func newStreamingStrategy(ctx context.Context, jaeger *v1.Jaeger) S { func autoProvisionKafka(ctx context.Context, jaeger *v1.Jaeger, manifest S) S { tracer := otel.GetTracerProvider().Tracer(v1.ReconciliationTracer) - ctx, span := tracer.Start(ctx, "autoProvisionKafka") + ctx, span := tracer.Start(ctx, "autoProvisionKafka") // nolint:ineffassign,staticcheck defer span.End() if jaeger.Annotations == nil { diff --git a/pkg/strategy/streaming_test.go b/pkg/strategy/streaming_test.go index 1bcc534d0..162bbab30 100644 --- a/pkg/strategy/streaming_test.go +++ b/pkg/strategy/streaming_test.go @@ -178,19 +178,6 @@ func TestAutoscaleForStreaming(t *testing.T) { func assertDeploymentsAndServicesForStreaming(t *testing.T, instance *v1.Jaeger, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) { name := instance.Name - expectedNumObjs := 7 - - if hasDaemonSet { - expectedNumObjs++ - } - - if hasOAuthProxy { - expectedNumObjs++ - } - - if hasConfigMap { - expectedNumObjs++ - } deployments := map[string]bool{ fmt.Sprintf("%s-collector", name): false, diff --git a/pkg/tracing/bootstrap.go b/pkg/tracing/bootstrap.go index 113541c97..7466988cc 100644 --- a/pkg/tracing/bootstrap.go +++ b/pkg/tracing/bootstrap.go @@ -17,9 +17,7 @@ import ( "github.com/jaegertracing/jaeger-operator/pkg/version" ) -var ( - processor tracesdk.SpanProcessor -) +var processor tracesdk.SpanProcessor // Bootstrap prepares a new tracer to be used by the operator func Bootstrap(ctx context.Context, namespace string) { @@ -33,7 +31,7 @@ func Bootstrap(ctx context.Context, namespace string) { } } -//SetInstanceID set the computed instance id on the tracing provider +// SetInstanceID set the computed instance id on the tracing provider func SetInstanceID(ctx context.Context, namespace string) { if viper.GetBool("tracing-enabled") { // Rebuild the provider with the same exporter @@ -58,7 +56,6 @@ func buildSpanProcessor() error { } jexporter, err := jaeger.NewRawExporter(endpoint) - if err != nil { return err } @@ -68,7 +65,7 @@ func buildSpanProcessor() error { func buildJaegerExporter(ctx context.Context, namespace string, instanceID string) { tracer := otel.GetTracerProvider().Tracer(v1.BootstrapTracer) - ctx, span := tracer.Start(ctx, "buildJaegerExporter") + ctx, span := tracer.Start(ctx, "buildJaegerExporter") // nolint:ineffassign,staticcheck defer span.End() attr := []attribute.KeyValue{ semconv.ServiceNameKey.String("jaeger-operator"), diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index feb19d6d2..148179109 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -111,7 +111,6 @@ func ManagedInstance(ctx context.Context, client client.Client, jaeger v1.Jaeger defer span.End() currentSemVersion, err := semver.NewVersion(jaeger.Status.Version) - if err != nil { jaeger.Logger().Error( err, diff --git a/pkg/upgrade/upgrade_test.go b/pkg/upgrade/upgrade_test.go index e992a834b..3bb752012 100644 --- a/pkg/upgrade/upgrade_test.go +++ b/pkg/upgrade/upgrade_test.go @@ -160,7 +160,6 @@ func TestErrorForInvalidSemVer(t *testing.T) { } func TestSkipUpgradeForVersionsGreaterThanLatest(t *testing.T) { - // prepare nsn := types.NamespacedName{Name: "my-instance"} diff --git a/pkg/upgrade/v1_15_0_test.go b/pkg/upgrade/v1_15_0_test.go index f378f7dc0..fc0774e9a 100644 --- a/pkg/upgrade/v1_15_0_test.go +++ b/pkg/upgrade/v1_15_0_test.go @@ -62,5 +62,4 @@ func TestRemoveDeprecatedFlagWithNoReplacementv1_15_0(t *testing.T) { assert.NoError(t, err) assert.Len(t, updated.Spec.Collector.Options.Map(), 0) assert.NotContains(t, updated.Spec.Collector.Options.Map(), "cassandra.enable-dependencies-v2") - } diff --git a/pkg/upgrade/v1_18_0_test.go b/pkg/upgrade/v1_18_0_test.go index 219595cff..b053830ee 100644 --- a/pkg/upgrade/v1_18_0_test.go +++ b/pkg/upgrade/v1_18_0_test.go @@ -58,7 +58,8 @@ func TestUpgradeDeprecatedOptionsv1_18_0(t *testing.T) { "collector.http-server.host-port", "collector.grpc-server.host-port", "collector.zipkin.host-port", - "admin.http.host-port"} { + "admin.http.host-port", + } { assert.Contains(t, opts, newFlag) expectedValue := fmt.Sprintf(":%s", oldOptionsMap[flagsMap[newFlag]]) assert.Equal(t, expectedValue, opts[newFlag]) diff --git a/pkg/upgrade/v1_22_0.go b/pkg/upgrade/v1_22_0.go index c016eaa69..5d60b7ab1 100644 --- a/pkg/upgrade/v1_22_0.go +++ b/pkg/upgrade/v1_22_0.go @@ -36,7 +36,7 @@ func upgrade1_22_0(ctx context.Context, client client.Client, jaeger v1.Jaeger) j.Spec.Agent.Options = migrateDeprecatedOptions(j, j.Spec.Agent.Options, flagMapAgent) j.Spec.Query.Options = migrateDeprecatedOptions(j, j.Spec.Query.Options, flagMapQuery) - //Migrate query host/port flags + // Migrate query host/port flags j.Spec.Query.Options = migrateQueryHostPortFlagsv1_22_0(j.Spec.Query.Options) return migrateCassandraVerifyFlagv1_22_0(jaeger), nil diff --git a/pkg/upgrade/v1_22_0_test.go b/pkg/upgrade/v1_22_0_test.go index 7455d6656..80906e597 100644 --- a/pkg/upgrade/v1_22_0_test.go +++ b/pkg/upgrade/v1_22_0_test.go @@ -69,7 +69,6 @@ func TestUpgradeJaegerTagssv1_22_0(t *testing.T) { assert.Equal(t, storageOpts.Map(), persisted.Spec.Storage.Options.Map()) assert.Equal(t, ingressOpts.Map(), persisted.Spec.Ingress.Options.Map()) - } func TestDeleteQueryRemovedFlags(t *testing.T) { @@ -101,7 +100,6 @@ func TestDeleteQueryRemovedFlags(t *testing.T) { } func TestCassandraVerifyHostFlags(t *testing.T) { - oldFlag := "cassandra.tls.verify-host" newFlag := "cassandra.tls.skip-host-verify" @@ -154,13 +152,11 @@ func TestCassandraVerifyHostFlags(t *testing.T) { assert.Len(t, persisted.Spec.Collector.Options.Map(), 0) assert.NotContains(t, persisted.Spec.Collector.Options.Map(), oldFlag) } - }) } } func TestMigrateQueryHostPortFlagsv1_22_0(t *testing.T) { - tests := []struct { testName string opts v1.Options @@ -255,5 +251,4 @@ func TestMigrateQueryHostPortFlagsv1_22_0(t *testing.T) { assert.Equal(t, tt.expectedOps, persisted.Spec.Query.Options.StringMap()) } - } diff --git a/pkg/upgrade/v1_31_0.go b/pkg/upgrade/v1_31_0.go index f47cdfd1b..b6004584a 100644 --- a/pkg/upgrade/v1_31_0.go +++ b/pkg/upgrade/v1_31_0.go @@ -12,7 +12,6 @@ import ( ) func upgrade1_31_0(ctx context.Context, c client.Client, jaeger v1.Jaeger) (v1.Jaeger, error) { - // Delete ES instance if self-provisioned ES is used. // The newly created instance will use cert-management from EO operator. if v1.ShouldInjectOpenShiftElasticsearchConfiguration(jaeger.Spec.Storage) { diff --git a/pkg/upgrade/versions.go b/pkg/upgrade/versions.go index a57ad5bbc..1b4c07fd3 100644 --- a/pkg/upgrade/versions.go +++ b/pkg/upgrade/versions.go @@ -10,14 +10,12 @@ import ( type upgradeFunction = func(ctx context.Context, client client.Client, jaeger v1.Jaeger) (v1.Jaeger, error) -var ( - upgrades = map[string]upgradeFunction{ - "1.15.0": upgrade1_15_0, - "1.17.0": upgrade1_17_0, - "1.18.0": upgrade1_18_0, - "1.20.0": upgrade1_20_0, - "1.22.0": upgrade1_22_0, - "1.28.0": upgrade1_28_0, - "1.31.0": upgrade1_31_0, - } -) +var upgrades = map[string]upgradeFunction{ + "1.15.0": upgrade1_15_0, + "1.17.0": upgrade1_17_0, + "1.18.0": upgrade1_18_0, + "1.20.0": upgrade1_20_0, + "1.22.0": upgrade1_22_0, + "1.28.0": upgrade1_28_0, + "1.31.0": upgrade1_31_0, +} diff --git a/pkg/util/dns_name_test.go b/pkg/util/dns_name_test.go index fbd159358..f15265a14 100644 --- a/pkg/util/dns_name_test.go +++ b/pkg/util/dns_name_test.go @@ -8,7 +8,7 @@ import ( ) func TestDnsName(t *testing.T) { - var tests = []struct { + tests := []struct { in string out string }{ @@ -23,11 +23,11 @@ func TestDnsName(t *testing.T) { {"-foo", "afoo"}, } + re := regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`) for _, tt := range tests { assert.Equal(t, tt.out, DNSName(tt.in)) - matched, err := regexp.MatchString(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`, tt.out) - assert.NoError(t, err) + matched := re.MatchString(tt.out) assert.True(t, matched, "%v is not a valid name", tt.out) } } diff --git a/pkg/util/k8s_utils.go b/pkg/util/k8s_utils.go index 31228b599..1f5c5b29c 100644 --- a/pkg/util/k8s_utils.go +++ b/pkg/util/k8s_utils.go @@ -21,9 +21,9 @@ var ForceRunModeEnv = "OSDK_FORCE_RUN_MODE" type RunModeType string const ( - //LocalRunMode local run mode + // LocalRunMode local run mode LocalRunMode RunModeType = "local" - //ClusterRunMode cluster run mode + // ClusterRunMode cluster run mode ClusterRunMode RunModeType = "cluster" ) diff --git a/pkg/util/util.go b/pkg/util/util.go index 600eaff9a..a72134715 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -120,9 +120,7 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { serviceAccount = commonSpec.ServiceAccount } - for _, ips := range commonSpec.ImagePullSecrets { - imagePullSecrets = append(imagePullSecrets, ips) - } + imagePullSecrets = append(imagePullSecrets, commonSpec.ImagePullSecrets...) if imagePullPolicy == corev1.PullPolicy("") { imagePullPolicy = commonSpec.ImagePullPolicy @@ -147,7 +145,6 @@ func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec { // MergeResources returns a merged version of two resource requirements func MergeResources(resources *corev1.ResourceRequirements, res corev1.ResourceRequirements) { - for k, v := range res.Limits { if _, ok := resources.Limits[k]; !ok { if resources.Limits == nil { @@ -326,7 +323,6 @@ func GenerateProxySecret() (string, error) { } base64Secret := base64.StdEncoding.EncodeToString(randString) return base64Secret, nil - } // FindEnvVar return the EnvVar with given name or nil if not found diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 33fdfa2a9..302ebfce7 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -543,8 +543,10 @@ func TestRemoveEmptyVars(t *testing.T) { expected []corev1.EnvVar }{ {}, - {underTest: []corev1.EnvVar{{Name: "foo", Value: "bar"}, {Name: "foo3"}, {Name: "foo2", ValueFrom: &corev1.EnvVarSource{}}}, - expected: []corev1.EnvVar{{Name: "foo", Value: "bar"}, {Name: "foo2", ValueFrom: &corev1.EnvVarSource{}}}}, + { + underTest: []corev1.EnvVar{{Name: "foo", Value: "bar"}, {Name: "foo3"}, {Name: "foo2", ValueFrom: &corev1.EnvVarSource{}}}, + expected: []corev1.EnvVar{{Name: "foo", Value: "bar"}, {Name: "foo2", ValueFrom: &corev1.EnvVarSource{}}}, + }, {underTest: []corev1.EnvVar{{Name: "foo"}}}, } for _, test := range tests { @@ -572,7 +574,6 @@ func TestCreateFromSecret(t *testing.T) { } func TestReplaceArgument(t *testing.T) { - newValue := "SECRET2" prefix := "--cookie-secret=" @@ -627,7 +628,6 @@ func TestReplaceArgument(t *testing.T) { assert.Equal(t, test.count, counter) assert.Equal(t, test.expected, test.input) } - } func TestArgs(t *testing.T) { @@ -646,7 +646,6 @@ func TestArgs(t *testing.T) { } func TestFindEnvVars(t *testing.T) { - myEnvVar := corev1.EnvVar{ Name: "my_env_var", Value: "v1", @@ -686,7 +685,6 @@ func TestFindEnvVars(t *testing.T) { } func TestIsOTLPEnable(t *testing.T) { - tests := []struct { name string options v1.Options @@ -718,7 +716,6 @@ func TestIsOTLPEnable(t *testing.T) { } func TestIsOTLPExplcitSet(t *testing.T) { - tests := []struct { name string options v1.Options diff --git a/tests/assert-jobs/index/main.go b/tests/assert-jobs/index/main.go index c5205a772..5778172c1 100644 --- a/tests/assert-jobs/index/main.go +++ b/tests/assert-jobs/index/main.go @@ -47,7 +47,6 @@ func filterIndices(indices *[]elasticsearch.EsIndex, pattern string) ([]elastics logrus.Debugf("%d indices matches the pattern '%s'", len(matchingIndices), pattern) return matchingIndices, nil - } // Init the CMD and return error if something didn't go properly @@ -115,7 +114,7 @@ func main() { logrus.Fatalln(err) } - if viper.GetBool(flagVerbose) == true { + if viper.GetBool(flagVerbose) { logrus.SetLevel(logrus.DebugLevel) } @@ -186,5 +185,4 @@ func main() { logrus.Fatalln(foundDocs, "docs found.", viper.GetInt(flagAssertCountDocs), "expected") } } - } diff --git a/tests/assert-jobs/query/main.go b/tests/assert-jobs/query/main.go index f5e3871ff..0d2de2638 100644 --- a/tests/assert-jobs/query/main.go +++ b/tests/assert-jobs/query/main.go @@ -51,7 +51,7 @@ func main() { host := viper.GetString(flagIngressHost) serviceName := viper.GetString(flagServiceName) - if viper.GetBool(flagVerbose) == true { + if viper.GetBool(flagVerbose) { logrus.SetLevel(logrus.DebugLevel) } diff --git a/tests/assert-jobs/reporter-otlp/main.go b/tests/assert-jobs/reporter-otlp/main.go index aa8392215..c9cad12d2 100644 --- a/tests/assert-jobs/reporter-otlp/main.go +++ b/tests/assert-jobs/reporter-otlp/main.go @@ -164,7 +164,7 @@ func initProvider(serviceName string) func() { } } -// Generate substans inside a span +// Generate subspans inside a span // ctx: context for the program // depth: how many spans should be created as child spans of this one func generateSubSpans(ctx context.Context, depth int) { @@ -208,7 +208,7 @@ func main() { if err != nil { logrus.Fatal(err) } - if viper.GetBool(flagVerbose) == true { + if viper.GetBool(flagVerbose) { logrus.SetLevel(logrus.DebugLevel) } diff --git a/tests/assert-jobs/reporter/main.go b/tests/assert-jobs/reporter/main.go index f595f312c..fae006863 100644 --- a/tests/assert-jobs/reporter/main.go +++ b/tests/assert-jobs/reporter/main.go @@ -5,11 +5,10 @@ import ( "flag" "fmt" "io" + "net/http" "strings" "time" - "net/http" - "github.com/opentracing/opentracing-go" "github.com/sirupsen/logrus" "github.com/spf13/pflag" @@ -197,7 +196,7 @@ func main() { logrus.Fatal(err) } - if viper.GetBool(flagVerbose) == true { + if viper.GetBool(flagVerbose) { logrus.SetLevel(logrus.DebugLevel) } diff --git a/tests/assert-jobs/utils/params.go b/tests/assert-jobs/utils/params.go index c86d41423..ddd6dc7a5 100644 --- a/tests/assert-jobs/utils/params.go +++ b/tests/assert-jobs/utils/params.go @@ -20,19 +20,19 @@ const ( secretDefault = "" ) -//TestParams contains all general parameters of the test job +// TestParams contains all general parameters of the test job type TestParams struct { Timeout time.Duration RetryInterval time.Duration Secret string } -//NewParameters create a new TestParams structure +// NewParameters create a new TestParams structure func NewParameters() *TestParams { return &TestParams{} } -//Parse the environment variables and fill the structure with the parameters +// Parse the environment variables and fill the structure with the parameters func (params *TestParams) Parse() { viper.SetDefault(envTimeoutKey, timeOutDefault) viper.SetDefault(envRetryInterval, retryIntervalDefault) diff --git a/tests/assert-jobs/utils/secrets/secrets.go b/tests/assert-jobs/utils/secrets/secrets.go index 2d9b6ca40..d831c77bd 100644 --- a/tests/assert-jobs/utils/secrets/secrets.go +++ b/tests/assert-jobs/utils/secrets/secrets.go @@ -10,7 +10,6 @@ import ( // GetToken reads the token from the given path and returns it func GetToken(path string) string { content, err := ioutil.ReadFile(filepath.Clean(path)) - if err != nil { logrus.Errorln("Something failed during reading the token:", err) return "" diff --git a/tests/assert-jobs/utils/testhttp.go b/tests/assert-jobs/utils/testhttp.go index e6352f636..bf1b50407 100644 --- a/tests/assert-jobs/utils/testhttp.go +++ b/tests/assert-jobs/utils/testhttp.go @@ -12,10 +12,9 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ) -//TestGetHTTP polls an endpoint and test the response +// TestGetHTTP polls an endpoint and test the response func TestGetHTTP(url string, params *TestParams, testFn func(response *http.Response, body []byte) (done bool, err error)) error { req, err := http.NewRequest(http.MethodGet, url, nil) - if err != nil { return err } @@ -107,7 +106,6 @@ func TestGetHTTP(url string, params *TestParams, testFn func(response *http.Resp } return false, nil - }) } diff --git a/tests/cmd-utils/uiconfig/main.go b/tests/cmd-utils/uiconfig/main.go index 4a01faf62..2fcc91e47 100644 --- a/tests/cmd-utils/uiconfig/main.go +++ b/tests/cmd-utils/uiconfig/main.go @@ -46,7 +46,6 @@ func main() { logrus.Warningln("Found: ", found, ". Assert: ", assertPresent) return false, nil }) - if err != nil { log.Fatalln(err) } diff --git a/tests/cmd-utils/wait-cronjob/main.go b/tests/cmd-utils/wait-cronjob/main.go index 4c8108b71..61c208136 100644 --- a/tests/cmd-utils/wait-cronjob/main.go +++ b/tests/cmd-utils/wait-cronjob/main.go @@ -6,9 +6,8 @@ import ( "fmt" "os" "path/filepath" - "time" - "strings" + "time" "github.com/sirupsen/logrus" "github.com/spf13/pflag" @@ -187,7 +186,7 @@ func main() { logrus.Fatalln(err) } - if viper.GetBool(flagVerbose) == true { + if viper.GetBool(flagVerbose) { logrus.SetLevel(logrus.DebugLevel) }