Skip to content
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
29 changes: 13 additions & 16 deletions pkg/operator/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net"
"strings"
"text/template"

"github.com/Masterminds/sprig"
Expand Down Expand Up @@ -67,23 +68,19 @@ func createDiscoveredControllerConfigSpec(infra *configv1.Infrastructure, networ
return nil, err
}

infraPlatformString := ""
// The PlatformStatus field is set in cluster versions >= 4.2
// Otherwise use the Platform field
if infra.Status.PlatformStatus != nil {
infraPlatformString = string(infra.Status.PlatformStatus.Type)
} else {
//nolint:staticcheck
infraPlatformString = string(infra.Status.Platform)
}

platform := "none"
//nolint:staticcheck
switch infra.Status.Platform {
case configv1.AWSPlatformType:
platform = "aws"
case configv1.AzurePlatformType:
platform = "azure"
case configv1.BareMetalPlatformType:
platform = "baremetal"
case configv1.GCPPlatformType:
platform = "gcp"
case configv1.OpenStackPlatformType:
platform = "openstack"
case configv1.LibvirtPlatformType:
platform = "libvirt"
case configv1.VSpherePlatformType:
platform = "vsphere"
if infraPlatformString != "" {
platform = strings.ToLower(infraPlatformString)
}

ccSpec := &mcfgv1.ControllerConfigSpec{
Expand Down
96 changes: 96 additions & 0 deletions pkg/operator/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package operator

import (
"fmt"
configv1 "github.com/openshift/api/config/v1"
"strings"
"testing"
)
Expand Down Expand Up @@ -102,3 +103,98 @@ func TestRenderAsset(t *testing.T) {
})
}
}

func TestCreateDiscoveredControllerConfigSpec(t *testing.T) {
tests := []struct {
Infra *configv1.Infrastructure
Network *configv1.Network
Proxy *configv1.Proxy
Error bool
}{{
Infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
PlatformStatus: &configv1.PlatformStatus{
Type: configv1.AWSPlatformType,
},
EtcdDiscoveryDomain: "tt.testing",
}},
Network: &configv1.Network{
Spec: configv1.NetworkSpec{ServiceNetwork: []string{"192.168.1.1/24"}}},
Proxy: &configv1.Proxy{
Status: configv1.ProxyStatus{
HTTPProxy: "test.proxy"}},
}, {
Infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
PlatformStatus: &configv1.PlatformStatus{
Type: configv1.AWSPlatformType,
},
EtcdDiscoveryDomain: "tt.testing",
}},
Network: &configv1.Network{
Spec: configv1.NetworkSpec{ServiceNetwork: []string{"192.168.1.1/99999999"}}},
Error: true,
}, {
Infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
PlatformStatus: &configv1.PlatformStatus{},
EtcdDiscoveryDomain: "tt.testing",
}},
Network: &configv1.Network{
Spec: configv1.NetworkSpec{ServiceNetwork: []string{"192.168.1.1/24"}}},
}, {
Infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
PlatformStatus: &configv1.PlatformStatus{
Type: configv1.AWSPlatformType,
},
EtcdDiscoveryDomain: "tt.testing",
}},
Network: &configv1.Network{
Spec: configv1.NetworkSpec{ServiceNetwork: []string{}}},
Error: true,
}, {
// Test old Platform field instead of PlatformStatus
Infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.AWSPlatformType,
EtcdDiscoveryDomain: "tt.testing",
},
},
Network: &configv1.Network{
Spec: configv1.NetworkSpec{ServiceNetwork: []string{"192.168.1.1/24"}}},
}}

for idx, test := range tests {
t.Run(fmt.Sprintf("case#%d", idx), func(t *testing.T) {
desc := fmt.Sprintf("Infra(%#v), Network(%#v)", test.Infra, test.Network)
controllerConfigSpec, err := createDiscoveredControllerConfigSpec(test.Infra, test.Network, test.Proxy)
if err != nil {
if !test.Error {
t.Fatalf("%s failed: %s", desc, err.Error())
} else {
// If Err flag is true and err is found, stop testing
return
}
}
if controllerConfigSpec == nil {
t.Fatalf("Controller config spec did not get initialized")
} else if controllerConfigSpec.Platform == "" {
t.Fatalf("Error setting controller config platform")
}
etcdDomain := controllerConfigSpec.EtcdDiscoveryDomain
testDomain := test.Infra.Status.EtcdDiscoveryDomain
if etcdDomain != testDomain {
t.Fatalf("%s failed: got = %s want = %s", desc, etcdDomain, testDomain)
}
if test.Proxy != nil {
testURL := test.Proxy.Status.HTTPProxy
controllerURL := controllerConfigSpec.Proxy.HTTPProxy
if controllerURL != testURL {
t.Fatalf("%s failed: got = %s want = %s", desc, controllerURL, testURL)
}
}
})
}

}