-
Notifications
You must be signed in to change notification settings - Fork 344
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
Protect the platform behind a mutex #2278
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e4b9a6
Refactor the autodetect module to reduce the number of writes/reads i…
iblancasa 43a0706
Fix linting
iblancasa 9bfbb36
Move the cleaning tasks outside the autodetection
iblancasa a8d19f2
Merge branch 'main' of github.com:jaegertracing/jaeger-operator into …
iblancasa df519c4
Remove unused statement
iblancasa 0978bea
Merge branch 'main' of github.com:jaegertracing/jaeger-operator into …
iblancasa 539b0cd
Increase timeotus
iblancasa 408fc16
Merge branch 'main' of github.com:jaegertracing/jaeger-operator into …
iblancasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import ( | |
) | ||
|
||
func TestStart(t *testing.T) { | ||
viper.Set("platform", v1.FlagPlatformOpenShift) | ||
OperatorConfiguration.SetPlatform(OpenShiftPlatform) | ||
defer viper.Reset() | ||
|
||
// sanity check | ||
|
@@ -57,7 +57,7 @@ func TestStart(t *testing.T) { | |
} | ||
|
||
func TestStartContinuesInBackground(t *testing.T) { | ||
viper.Set("platform", v1.FlagPlatformOpenShift) | ||
OperatorConfiguration.SetPlatform(OpenShiftPlatform) | ||
defer viper.Reset() | ||
|
||
// prepare | ||
|
@@ -68,6 +68,9 @@ func TestStartContinuesInBackground(t *testing.T) { | |
} | ||
b := WithClients(cl, dcl, cl) | ||
|
||
fmt.Println(viper.IsSet("auth-delegator-available")) | ||
fmt.Println(viper.GetBool("auth-delegator-available")) | ||
|
||
done := make(chan bool) | ||
go func() { | ||
for { | ||
|
@@ -85,7 +88,7 @@ func TestStartContinuesInBackground(t *testing.T) { | |
select { | ||
case <-done: | ||
assert.False(t, viper.GetBool("auth-delegator-available")) | ||
case <-time.After(1 * time.Second): | ||
case <-time.After(5 * time.Second): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here we changed it from 1 to 5 s and in the next pr we change it back to 1s? seems weird to me. |
||
assert.Fail(t, "timed out waiting for the start process to detect the capabilities") | ||
} | ||
|
||
|
@@ -97,7 +100,7 @@ func TestStartContinuesInBackground(t *testing.T) { | |
if viper.GetBool("auth-delegator-available") { | ||
break | ||
} | ||
time.Sleep(500 * time.Millisecond) | ||
time.Sleep(10 * time.Millisecond) | ||
} | ||
done <- true | ||
}() | ||
|
@@ -176,7 +179,7 @@ func TestAutoDetectWithServerResourcesForGroupVersionError(t *testing.T) { | |
|
||
func TestAutoDetectOpenShift(t *testing.T) { | ||
// prepare | ||
viper.Set("platform", v1.FlagPlatformAutoDetect) | ||
viper.Set("platform", "auto-detect") | ||
defer viper.Reset() | ||
|
||
dcl := &fakeDiscoveryClient{} | ||
|
@@ -197,7 +200,7 @@ func TestAutoDetectOpenShift(t *testing.T) { | |
b.autoDetectCapabilities() | ||
|
||
// verify | ||
assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform")) | ||
assert.Equal(t, OpenShiftPlatform, OperatorConfiguration.GetPlatform()) | ||
|
||
// set the error | ||
dcl.ServerResourcesForGroupVersionFunc = func(_ string) (apiGroupList *metav1.APIResourceList, err error) { | ||
|
@@ -208,12 +211,12 @@ func TestAutoDetectOpenShift(t *testing.T) { | |
b.autoDetectCapabilities() | ||
|
||
// verify again | ||
assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform")) | ||
assert.Equal(t, OpenShiftPlatform, OperatorConfiguration.GetPlatform()) | ||
} | ||
|
||
func TestAutoDetectKubernetes(t *testing.T) { | ||
// prepare | ||
viper.Set("platform", v1.FlagPlatformAutoDetect) | ||
viper.Set("platform", "auto-detect") | ||
defer viper.Reset() | ||
|
||
dcl := &fakeDiscoveryClient{} | ||
|
@@ -224,12 +227,12 @@ func TestAutoDetectKubernetes(t *testing.T) { | |
b.autoDetectCapabilities() | ||
|
||
// verify | ||
assert.Equal(t, v1.FlagPlatformKubernetes, viper.GetString("platform")) | ||
assert.Equal(t, KubernetesPlatform, OperatorConfiguration.GetPlatform()) | ||
} | ||
|
||
func TestExplicitPlatform(t *testing.T) { | ||
// prepare | ||
viper.Set("platform", v1.FlagPlatformOpenShift) | ||
OperatorConfiguration.SetPlatform(OpenShiftPlatform) | ||
defer viper.Reset() | ||
|
||
dcl := &fakeDiscoveryClient{} | ||
|
@@ -240,7 +243,7 @@ func TestExplicitPlatform(t *testing.T) { | |
b.autoDetectCapabilities() | ||
|
||
// verify | ||
assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform")) | ||
assert.Equal(t, OpenShiftPlatform, OperatorConfiguration.GetPlatform()) | ||
} | ||
|
||
func TestAutoDetectEsProvisionNoEsOperator(t *testing.T) { | ||
|
@@ -499,7 +502,7 @@ func TestAutoDetectAutoscalingVersion(t *testing.T) { | |
|
||
func TestSkipAuthDelegatorNonOpenShift(t *testing.T) { | ||
// prepare | ||
viper.Set("platform", v1.FlagPlatformKubernetes) | ||
OperatorConfiguration.SetPlatform(KubernetesPlatform) | ||
defer viper.Reset() | ||
|
||
dcl := &fakeDiscoveryClient{} | ||
|
@@ -515,7 +518,7 @@ func TestSkipAuthDelegatorNonOpenShift(t *testing.T) { | |
|
||
func TestNoAuthDelegatorAvailable(t *testing.T) { | ||
// prepare | ||
viper.Set("platform", v1.FlagPlatformOpenShift) | ||
OperatorConfiguration.SetPlatform(OpenShiftPlatform) | ||
defer viper.Reset() | ||
|
||
dcl := &fakeDiscoveryClient{} | ||
|
@@ -534,7 +537,7 @@ func TestNoAuthDelegatorAvailable(t *testing.T) { | |
|
||
func TestAuthDelegatorBecomesAvailable(t *testing.T) { | ||
// prepare | ||
viper.Set("platform", v1.FlagPlatformOpenShift) | ||
OperatorConfiguration.SetPlatform(OpenShiftPlatform) | ||
defer viper.Reset() | ||
|
||
dcl := &fakeDiscoveryClient{} | ||
|
@@ -555,7 +558,7 @@ func TestAuthDelegatorBecomesAvailable(t *testing.T) { | |
|
||
func TestAuthDelegatorBecomesUnavailable(t *testing.T) { | ||
// prepare | ||
viper.Set("platform", v1.FlagPlatformOpenShift) | ||
OperatorConfiguration.SetPlatform(OpenShiftPlatform) | ||
defer viper.Reset() | ||
|
||
dcl := &fakeDiscoveryClient{} | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that a debug leftover?