Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Fix autodetect restarting platform from OpenShift to Kubernetes (jaeg…
Browse files Browse the repository at this point in the history
…ertracing#1003)

* Fix autodetect restarting platform from OpenShift to Kubernetes

Signed-off-by: Gary Brown <gary@brownuk.com>

* Add extra check

Signed-off-by: Gary Brown <gary@brownuk.com>

* Further change to trigger tests

Signed-off-by: Gary Brown <gary@brownuk.com>
  • Loading branch information
objectiser committed Apr 5, 2020
1 parent b11e9ea commit 1d56efe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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

0 comments on commit 1d56efe

Please sign in to comment.