Skip to content

Commit

Permalink
pkg/operator: add nil check for infra.Status.PlatformStatus before sw…
Browse files Browse the repository at this point in the history
…itch stmt

If infra.Status.PlatformStatus is empty it will throw a panic as it is a pointer.
Some baremetal platforms have an empty Platform status which must be accounted for.

Also add basic isCloudConfigRequired unit test

Closes: BZ 1858026
  • Loading branch information
kikisdeliveryservice committed Jul 17, 2020
1 parent f341a7f commit 804796a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/operator/sync.go
Expand Up @@ -112,13 +112,18 @@ func isCloudConfigRequired(infra *configv1.Infrastructure) bool {
if infra.Spec.CloudConfig.Name != "" {
return true
}
switch infra.Status.PlatformStatus.Type {
case configv1.AzurePlatformType,
configv1.GCPPlatformType,
configv1.OpenStackPlatformType,
configv1.VSpherePlatformType:
return true
default:

if infra.Status.PlatformStatus != nil {
switch infra.Status.PlatformStatus.Type {
case configv1.AzurePlatformType,
configv1.GCPPlatformType,
configv1.OpenStackPlatformType,
configv1.VSpherePlatformType:
return true
default:
return false
}
} else {
return false
}
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/operator/sync_test.go
@@ -0,0 +1,14 @@
package operator

import (
configv1 "github.com/openshift/api/config/v1"
"github.com/stretchr/testify/assert"
"testing"
)

func TestIsCloudConfigRequired(t *testing.T) {
testInfra := configv1.Infrastructure{}
testInfra.Status.Platform = "None"
required := isCloudConfigRequired(&testInfra)
assert.False(t, required)
}

0 comments on commit 804796a

Please sign in to comment.