From 054ebee9345a32897f83cd32f9d544162e340e3a Mon Sep 17 00:00:00 2001 From: Enxebre Date: Mon, 1 Apr 2019 16:21:22 +0200 Subject: [PATCH] Reuse configv1 for handling platforms --- pkg/operator/config.go | 91 ++++++++----------------------------- pkg/operator/config_test.go | 49 ++++++++++++-------- pkg/operator/operator.go | 4 +- 3 files changed, 51 insertions(+), 93 deletions(-) diff --git a/pkg/operator/config.go b/pkg/operator/config.go index 7bb187b30..231a4e46a 100644 --- a/pkg/operator/config.go +++ b/pkg/operator/config.go @@ -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 @@ -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) { @@ -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) { diff --git a/pkg/operator/config_test.go b/pkg/operator/config_test.go index 041293e76..5de2c387e 100644 --- a/pkg/operator/config_test.go +++ b/pkg/operator/config_test.go @@ -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 { @@ -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, }, } diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 0452b28f9..33ab5b6f5 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -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)