Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced use of strings.ToLower comparison with EqualFold #214

Merged
merged 1 commit into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewAgent(jaeger *v1alpha1.Jaeger) *Agent {

// Get returns a Agent pod
func (a *Agent) Get() *appsv1.DaemonSet {
if strings.ToLower(a.jaeger.Spec.Agent.Strategy) != "daemonset" {
if !strings.EqualFold(a.jaeger.Spec.Agent.Strategy, "daemonset") {
logrus.Debugf(
"The Jaeger instance '%v' is using a Sidecar strategy for the Jaeger Agent. Skipping its DaemonSet deployment.",
a.jaeger.Name,
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingress/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func (i *QueryIngress) Get() *v1beta1.Ingress {
ServiceName: service.GetNameForQueryService(i.jaeger),
ServicePort: intstr.FromInt(service.GetPortForQueryService(i.jaeger)),
}
if _, ok := i.jaeger.Spec.AllInOne.Options.Map()["query.base-path"]; ok && strings.ToLower(i.jaeger.Spec.Strategy) == "allinone" {
if _, ok := i.jaeger.Spec.AllInOne.Options.Map()["query.base-path"]; ok && strings.EqualFold(i.jaeger.Spec.Strategy, "allinone") {
spec.Rules = append(spec.Rules, getRule(i.jaeger.Spec.AllInOne.Options, backend))
} else if _, ok := i.jaeger.Spec.Query.Options.Map()["query.base-path"]; ok && strings.ToLower(i.jaeger.Spec.Strategy) == "production" {
} else if _, ok := i.jaeger.Spec.Query.Options.Map()["query.base-path"]; ok && strings.EqualFold(i.jaeger.Spec.Strategy, "production") {
spec.Rules = append(spec.Rules, getRule(i.jaeger.Spec.Query.Options, backend))
} else {
spec.Backend = &backend
Expand Down
2 changes: 1 addition & 1 deletion pkg/inject/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Needed(dep *appsv1.Deployment) bool {
// Select a suitable Jaeger from the JaegerList for the given Pod, or nil of none is suitable
func Select(target *appsv1.Deployment, availableJaegerPods *v1alpha1.JaegerList) *v1alpha1.Jaeger {
jaegerName := target.Annotations[Annotation]
if strings.ToLower(jaegerName) == "true" && len(availableJaegerPods.Items) == 1 {
if strings.EqualFold(jaegerName, "true") && len(availableJaegerPods.Items) == 1 {
// if there's only *one* jaeger within this namespace, then that's what
// we'll use -- otherwise, we should just not inject, as it's not clear which
// jaeger instance to use!
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// Dependencies return a list of Jobs that have to be finished before the other components are deployed
func Dependencies(jaeger *v1alpha1.Jaeger) []batchv1.Job {
if strings.ToLower(jaeger.Spec.Storage.Type) == "cassandra" {
if strings.EqualFold(jaeger.Spec.Storage.Type, "cassandra") {
return cassandraDeps(jaeger)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func ValidTypes() []string {

// OptionsPrefix returns the options prefix associated with the supplied storage type
func OptionsPrefix(storageType string) string {
if strings.ToLower(storageType) == "elasticsearch" {
if strings.EqualFold(storageType, "elasticsearch") {
return "es"
}
return storageType
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategy/all-in-one.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *allInOneStrategy) Create() []runtime.Object {
}

if isBoolTrue(c.jaeger.Spec.Storage.EsIndexCleaner.Enabled) {
if strings.ToLower(c.jaeger.Spec.Storage.Type) == "elasticsearch" {
if strings.EqualFold(c.jaeger.Spec.Storage.Type, "elasticsearch") {
os = append(os, cronjob.CreateEsIndexCleaner(c.jaeger))
} else {
logrus.WithField("type", c.jaeger.Spec.Storage.Type).Warn("Skipping Elasticsearch index cleaner job due to unsupported storage.")
Expand Down
12 changes: 6 additions & 6 deletions pkg/strategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ type S interface {

// For returns the appropriate Strategy for the given Jaeger instance
func For(ctx context.Context, jaeger *v1alpha1.Jaeger) S {
if strings.ToLower(jaeger.Spec.Strategy) == "all-in-one" {
if strings.EqualFold(jaeger.Spec.Strategy, "all-in-one") {
logrus.Warnf("Strategy 'all-in-one' is no longer supported, please use 'allInOne'")
jaeger.Spec.Strategy = "allInOne"
}

normalize(jaeger)

logrus.Debugf("Jaeger strategy: %s", jaeger.Spec.Strategy)
if strings.ToLower(jaeger.Spec.Strategy) == "allinone" {
if strings.EqualFold(jaeger.Spec.Strategy, "allinone") {
return newAllInOneStrategy(ctx, jaeger)
}

if strings.ToLower(jaeger.Spec.Strategy) == "streaming" {
if strings.EqualFold(jaeger.Spec.Strategy, "streaming") {
return newStreamingStrategy(ctx, jaeger)
}

Expand Down Expand Up @@ -69,13 +69,13 @@ func normalize(jaeger *v1alpha1.Jaeger) {
}

// normalize the deployment strategy
if strings.ToLower(jaeger.Spec.Strategy) != "production" && strings.ToLower(jaeger.Spec.Strategy) != "streaming" {
if !strings.EqualFold(jaeger.Spec.Strategy, "production") && !strings.EqualFold(jaeger.Spec.Strategy, "streaming") {
jaeger.Spec.Strategy = "allInOne"
}

// check for incompatible options
// if the storage is `memory`, then the only possible strategy is `all-in-one`
if strings.ToLower(jaeger.Spec.Storage.Type) == "memory" && strings.ToLower(jaeger.Spec.Strategy) != "allinone" {
if strings.EqualFold(jaeger.Spec.Storage.Type, "memory") && !strings.EqualFold(jaeger.Spec.Strategy, "allinone") {
logrus.Warnf(
"No suitable storage was provided for the Jaeger instance '%v'. Falling back to all-in-one. Storage type: '%v'",
jaeger.Name,
Expand Down Expand Up @@ -131,7 +131,7 @@ func normalizeIndexCleaner(spec *v1alpha1.JaegerEsIndexCleanerSpec, storage stri

func unknownStorage(typ string) bool {
for _, k := range storage.ValidTypes() {
if strings.ToLower(typ) == k {
if strings.EqualFold(typ, k) {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategy/production.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *productionStrategy) Create() []runtime.Object {
}

if isBoolTrue(c.jaeger.Spec.Storage.EsIndexCleaner.Enabled) {
if strings.ToLower(c.jaeger.Spec.Storage.Type) == "elasticsearch" {
if strings.EqualFold(c.jaeger.Spec.Storage.Type, "elasticsearch") {
os = append(os, cronjob.CreateEsIndexCleaner(c.jaeger))
} else {
logrus.WithField("type", c.jaeger.Spec.Storage.Type).Warn("Skipping Elasticsearch index cleaner job due to unsupported storage.")
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategy/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (c *streamingStrategy) Create() []runtime.Object {
}

if isBoolTrue(c.jaeger.Spec.Storage.EsIndexCleaner.Enabled) {
if strings.ToLower(c.jaeger.Spec.Storage.Type) == "elasticsearch" {
if strings.EqualFold(c.jaeger.Spec.Storage.Type, "elasticsearch") {
os = append(os, cronjob.CreateEsIndexCleaner(c.jaeger))
} else {
logrus.WithField("type", c.jaeger.Spec.Storage.Type).Warn("Skipping Elasticsearch index cleaner job due to unsupported storage.")
Expand Down