Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPCLOUD-2514: Cloud Provider External no longer depends on a feature gate #1680

Merged
merged 1 commit into from Feb 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 5 additions & 44 deletions pkg/cloudprovider/external.go
Expand Up @@ -3,8 +3,6 @@ package cloudprovider
import (
"fmt"

"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"

configv1 "github.com/openshift/api/config/v1"
)

Expand All @@ -27,24 +25,15 @@ var (
// IsCloudProviderExternal is used to check whether external cloud provider settings should be used in a component.
// It checks whether the ExternalCloudProvider feature gate is enabled and whether the ExternalCloudProvider feature
// has been implemented for the platform.
func IsCloudProviderExternal(platformStatus *configv1.PlatformStatus, featureGateAccessor featuregates.FeatureGateAccess) (bool, error) {
if !featureGateAccessor.AreInitialFeatureGatesObserved() {
return false, fmt.Errorf("featureGates have not been read yet")
}
func IsCloudProviderExternal(platformStatus *configv1.PlatformStatus) (bool, error) {
if platformStatus == nil {
return false, fmt.Errorf("platformStatus is required")
}
switch platformStatus.Type {
case configv1.GCPPlatformType:
// Platforms that are external based on feature gate presence
return isExternalFeatureGateEnabled(featureGateAccessor, ExternalCloudProviderFeature, ExternalCloudProviderFeatureGCP)
case configv1.AzurePlatformType:
if isAzureStackHub(platformStatus) {
return true, nil
}
return isExternalFeatureGateEnabled(featureGateAccessor, ExternalCloudProviderFeature, ExternalCloudProviderFeatureAzure)
case configv1.AlibabaCloudPlatformType,
configv1.AWSPlatformType,
configv1.AzurePlatformType,
configv1.GCPPlatformType,
configv1.IBMCloudPlatformType,
configv1.KubevirtPlatformType,
configv1.NutanixPlatformType,
Expand All @@ -53,23 +42,14 @@ func IsCloudProviderExternal(platformStatus *configv1.PlatformStatus, featureGat
configv1.VSpherePlatformType:
return true, nil
case configv1.ExternalPlatformType:
return isExternalPlatformCCMEnabled(platformStatus, featureGateAccessor)
return isExternalPlatformCCMEnabled(platformStatus)
default:
// Platforms that do not have external cloud providers implemented
return false, nil
}
}

func isAzureStackHub(platformStatus *configv1.PlatformStatus) bool {
return platformStatus.Azure != nil && platformStatus.Azure.CloudName == configv1.AzureStackCloud
}

func isExternalPlatformCCMEnabled(platformStatus *configv1.PlatformStatus, featureGateAccessor featuregates.FeatureGateAccess) (bool, error) {
featureEnabled, err := isExternalFeatureGateEnabled(featureGateAccessor, ExternalCloudProviderFeature, ExternalCloudProviderFeatureExternal)
if err != nil || !featureEnabled {
return featureEnabled, err
}

func isExternalPlatformCCMEnabled(platformStatus *configv1.PlatformStatus) (bool, error) {
if platformStatus == nil || platformStatus.External == nil {
return false, nil
}
Expand All @@ -80,22 +60,3 @@ func isExternalPlatformCCMEnabled(platformStatus *configv1.PlatformStatus, featu

return false, nil
}

// isExternalFeatureGateEnabled determines whether the ExternalCloudProvider feature gate is present in the current
// feature set.
func isExternalFeatureGateEnabled(featureGateAccess featuregates.FeatureGateAccess, featureGateNames ...configv1.FeatureGateName) (bool, error) {
featureGates, err := featureGateAccess.CurrentFeatureGates()
if err != nil {
return false, fmt.Errorf("unable to read current featuregates: %w", err)
}

// If any of the desired feature gates are enabled, then the external cloud provider should be used.
for _, featureGateName := range featureGateNames {
if featureGates.Enabled(featureGateName) {
return true, nil
}
}

// No explicit opinion on the feature gate, assume it's not enabled.
return false, nil
}