diff --git a/pkg/autodetect/main.go b/pkg/autodetect/main.go index 590c75c2b..10bff8e35 100644 --- a/pkg/autodetect/main.go +++ b/pkg/autodetect/main.go @@ -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() { diff --git a/pkg/autodetect/main_test.go b/pkg/autodetect/main_test.go index b628475ac..11b401af1 100644 --- a/pkg/autodetect/main_test.go +++ b/pkg/autodetect/main_test.go @@ -117,7 +117,7 @@ func TestStartContinuesInBackground(t *testing.T) { } -func TestAutoDetectFallback(t *testing.T) { +func TestAutoDetectWithError(t *testing.T) { // prepare defer viper.Reset() @@ -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")) } @@ -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) {