forked from jaegertracing/jaeger-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protect the platform behind a mutex (jaegertracing#2278)
* Refactor the autodetect module to reduce the number of writes/reads in viper Signed-off-by: Israel Blancas <[email protected]> * Fix linting Signed-off-by: Israel Blancas <[email protected]> * Move the cleaning tasks outside the autodetection Signed-off-by: Israel Blancas <[email protected]> * Increase timeotus Signed-off-by: Israel Blancas <[email protected]> --------- Signed-off-by: Israel Blancas <[email protected]>
- Loading branch information
Showing
30 changed files
with
166 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package autodetect | ||
|
||
import ( | ||
"strings" | ||
"sync" | ||
|
||
"github.com/spf13/viper" | ||
|
||
v1 "github.com/jaegertracing/jaeger-operator/apis/v1" | ||
) | ||
|
||
// Platform holds the auto-detected running platform. | ||
type Platform int | ||
|
||
const ( | ||
// KubernetesPlatform represents the cluster is Kubernetes. | ||
KubernetesPlatform Platform = iota | ||
|
||
// OpenShiftPlatform represents the cluster is OpenShift. | ||
OpenShiftPlatform | ||
) | ||
|
||
func (p Platform) String() string { | ||
return [...]string{"Kubernetes", "OpenShift"}[p] | ||
} | ||
|
||
var OperatorConfiguration operatorConfigurationWrapper | ||
|
||
type operatorConfigurationWrapper struct { | ||
mu sync.RWMutex | ||
} | ||
|
||
func (c *operatorConfigurationWrapper) SetPlatform(p interface{}) { | ||
var platform string | ||
switch v := p.(type) { | ||
case string: | ||
platform = v | ||
case Platform: | ||
platform = v.String() | ||
default: | ||
platform = KubernetesPlatform.String() | ||
} | ||
|
||
c.mu.Lock() | ||
viper.Set(v1.FlagPlatform, platform) | ||
c.mu.Unlock() | ||
} | ||
|
||
func (c *operatorConfigurationWrapper) GetPlatform() Platform { | ||
c.mu.RLock() | ||
p := viper.GetString(v1.FlagPlatform) | ||
c.mu.RUnlock() | ||
|
||
p = strings.ToLower(p) | ||
|
||
var platform Platform | ||
switch p { | ||
case "openshift": | ||
platform = OpenShiftPlatform | ||
default: | ||
platform = KubernetesPlatform | ||
} | ||
return platform | ||
} | ||
|
||
func (c *operatorConfigurationWrapper) IsPlatformAutodetectionEnabled() bool { | ||
c.mu.RLock() | ||
p := viper.GetString(v1.FlagPlatform) | ||
c.mu.RUnlock() | ||
|
||
return strings.EqualFold(p, "auto-detect") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.