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
91 changes: 19 additions & 72 deletions pkg/operator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@ import (
const (
// TODO(alberto): move to "quay.io/openshift/origin-kubemark-machine-controllers:v4.0.0" once available
clusterAPIControllerKubemark = "docker.io/gofed/kubemark-machine-controllers:v1.0"
// AWSPlatformType is used to install on AWS
AWSProvider = Provider("aws")
// LibvirtPlatformType is used to install of libvirt
LibvirtProvider = Provider("libvirt")
// OpenStackPlatformType is used to install on OpenStack
OpenStackProvider = Provider("openstack")
// KubemarkPlatformType is used to install on Kubemark
KubemarkProvider = Provider("kubemark")
// BareMetalPlatformType is used for install using managed Bare Metal
BareMetalProvider = Provider("baremetal")
AzureProvider = Provider("azure")
NoneProvider = Provider("none")
clusterAPIControllerNoOp = "no-op"
kubemarkPlatform = configv1.PlatformType("kubemark")
bareMetalPlatform = configv1.PlatformType("baremetal")
)

type Provider string
Expand All @@ -52,54 +43,11 @@ type Images struct {
ClusterAPIControllerAzure string `json:"clusterAPIControllerAzure"`
}

// InstallConfig contains the mao relevant config coming from the install config, i.e provider
type InstallConfig struct {
InstallPlatform `json:"platform"`
}

// InstallPlatform is the configuration for the specific platform upon which to perform
// the installation. Only one of the platform configuration should be set
type InstallPlatform struct {
// AWS is the configuration used when running on AWS
AWS interface{} `json:"aws,omitempty"`

// Libvirt is the configuration used when running on libvirt
Libvirt interface{} `json:"libvirt,omitempty"`

// OpenStack is the configuration used when running on OpenStack
OpenStack interface{} `json:"openstack,omitempty"`

// Kubemark is the configuration used when running with Kubemark
Kubemark interface{} `json:"kubemark,omitempty"`

// BareMetal is the configuration used when running on managed Bare Metal
BareMetal interface{} `json:"baremetal,omitempty"`

// Azure is the configuration used when running on managed Azure
Azure interface{} `json:"azure,omitempty"`

// None is the configuration used when running on unmanaged UPI
None interface{} `json:"none,omitempty"`
}

func getProviderFromInfrastructure(infra *configv1.Infrastructure) (Provider, error) {
switch infra.Status.Platform {
case configv1.AWSPlatform:
return AWSProvider, nil
case configv1.LibvirtPlatform:
return LibvirtProvider, nil
case configv1.OpenStackPlatform:
return OpenStackProvider, nil
case configv1.AzurePlatform:
return AzureProvider, nil
case configv1.NonePlatform:
return NoneProvider, nil
case configv1.PlatformType("kubemark"):
return KubemarkProvider, nil
case configv1.PlatformType("baremetal"):
return BareMetalProvider, nil
func getProviderFromInfrastructure(infra *configv1.Infrastructure) (configv1.PlatformType, error) {
if infra.Status.Platform == "" {
return "", fmt.Errorf("no platform provider found on install config")
}
return "", fmt.Errorf("no platform provider found on install config")
return infra.Status.Platform, nil
}

func getImagesFromJSONFile(filePath string) (*Images, error) {
Expand All @@ -115,24 +63,23 @@ func getImagesFromJSONFile(filePath string) (*Images, error) {
return &i, nil
}

func getProviderControllerFromImages(provider Provider, images Images) (string, error) {
switch provider {
case AWSProvider:
func getProviderControllerFromImages(platform configv1.PlatformType, images Images) (string, error) {
switch platform {
case configv1.AWSPlatform:
return images.ClusterAPIControllerAWS, nil
case LibvirtProvider:
case configv1.LibvirtPlatform:
return images.ClusterAPIControllerLibvirt, nil
case OpenStackProvider:
case configv1.OpenStackPlatform:
return images.ClusterAPIControllerOpenStack, nil
case KubemarkProvider:
return clusterAPIControllerKubemark, nil
case BareMetalProvider:
return images.ClusterAPIControllerBareMetal, nil
case AzureProvider:
case configv1.AzurePlatform:
return images.ClusterAPIControllerAzure, nil
case NoneProvider:
return "None", nil
case bareMetalPlatform:
return images.ClusterAPIControllerBareMetal, nil
case kubemarkPlatform:
return clusterAPIControllerKubemark, nil
default:
return clusterAPIControllerNoOp, nil
}
return "", fmt.Errorf("not known platform provider given %s", provider)
}

func getMachineAPIOperatorFromImages(images Images) (string, error) {
Expand Down
49 changes: 30 additions & 19 deletions pkg/operator/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,56 @@ var (
func TestGetProviderFromInfrastructure(t *testing.T) {
tests := []struct {
infra *configv1.Infrastructure
expected Provider
expected configv1.PlatformType
}{{
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.AWSPlatform,
},
},
expected: AWSProvider,
expected: configv1.AWSPlatform,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.LibvirtPlatform,
},
},
expected: LibvirtProvider,
expected: configv1.LibvirtPlatform,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.NonePlatform,
Platform: configv1.OpenStackPlatform,
},
},
expected: NoneProvider,
expected: configv1.OpenStackPlatform,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.OpenStackPlatform,
Platform: configv1.AzurePlatform,
},
},
expected: OpenStackProvider,
expected: configv1.AzurePlatform,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.PlatformType("baremetal"),
Platform: bareMetalPlatform,
},
},
expected: BareMetalProvider,
expected: bareMetalPlatform,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.AzurePlatform,
Platform: kubemarkPlatform,
},
},
expected: AzureProvider,
expected: kubemarkPlatform,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.NonePlatform,
},
},
expected: configv1.NonePlatform,
}}

for _, test := range tests {
Expand Down Expand Up @@ -99,31 +106,35 @@ func TestGetImagesFromJSONFile(t *testing.T) {

func TestGetProviderControllerFromImages(t *testing.T) {
tests := []struct {
provider Provider
provider configv1.PlatformType
expectedImage string
}{{
provider: AWSProvider,
provider: configv1.AWSPlatform,
expectedImage: expectedAWSImage,
},
{
provider: LibvirtProvider,
provider: configv1.LibvirtPlatform,
expectedImage: expectedLibvirtImage,
},
{
provider: OpenStackProvider,
provider: configv1.OpenStackPlatform,
expectedImage: expectedOpenstackImage,
},
{
provider: BareMetalProvider,
provider: bareMetalPlatform,
expectedImage: expectedBareMetalImage,
},
{
provider: AzureProvider,
provider: configv1.AzurePlatform,
expectedImage: expectedAzureImage,
},
{
provider: NoneProvider,
expectedImage: "None",
provider: kubemarkPlatform,
expectedImage: clusterAPIControllerKubemark,
},
{
provider: configv1.NonePlatform,
expectedImage: clusterAPIControllerNoOp,
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func (optr *Operator) sync(key string) error {
glog.Errorf("Failed getting operator config: %v", err)
return err
}
if operatorConfig.Controllers.Provider == "None" {
glog.V(1).Info("`None` provider specified, reporting available")
if operatorConfig.Controllers.Provider == clusterAPIControllerNoOp {
glog.V(1).Info("No-op provider specified, reporting available")
if err := optr.statusAvailable(); err != nil {
glog.Errorf("Error syncing ClusterOperatorStatus: %v", err)
return fmt.Errorf("error syncing ClusterOperatorStatus: %v", err)
Expand Down