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

Fix autodetect restarting platform from OpenShift to Kubernetes #1003

Merged
merged 3 commits into from
Apr 5, 2020
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
4 changes: 1 addition & 3 deletions pkg/autodetect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ func (b *Background) autoDetectCapabilities() {

apiList, err := b.availableAPIs(ctx)
if err != nil {
log.WithError(err).Info("failed to determine the platform capabilities, auto-detected properties will fallback to their default values.")
viper.Set("platform", v1.FlagPlatformKubernetes)
viper.Set("es-provision", v1.FlagProvisionElasticsearchNo)
log.WithError(err).Info("failed to determine the platform capabilities, auto-detected properties will remain the same until next cycle.")
} else {

b.firstRun.Do(func() {
Expand Down
18 changes: 16 additions & 2 deletions pkg/autodetect/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestStartContinuesInBackground(t *testing.T) {

}

func TestAutoDetectFallback(t *testing.T) {
func TestAutoDetectWithError(t *testing.T) {
// prepare
defer viper.Reset()

Expand All @@ -134,11 +134,14 @@ func TestAutoDetectFallback(t *testing.T) {
return nil, fmt.Errorf("faked error")
}

// Check initial value of "platform"
assert.Equal(t, "", viper.GetString("platform"))

// test
b.autoDetectCapabilities()

// verify
assert.Equal(t, v1.FlagPlatformKubernetes, viper.GetString("platform"))
assert.Equal(t, "", viper.GetString("platform"))
assert.False(t, viper.GetBool("es-provision"))
}

Expand All @@ -164,6 +167,17 @@ func TestAutoDetectOpenShift(t *testing.T) {

// verify
assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform"))

// set the error
dcl.ServerGroupsFunc = func() (apiGroupList *metav1.APIGroupList, err error) {
return nil, fmt.Errorf("faked error")
}

// run autodetect again with failure
b.autoDetectCapabilities()

// verify again
assert.Equal(t, v1.FlagPlatformOpenShift, viper.GetString("platform"))
}

func TestAutoDetectKubernetes(t *testing.T) {
Expand Down