Skip to content

Commit

Permalink
features: adapt to new o/api features package
Browse files Browse the repository at this point in the history
Features moved to a new package in openshift/api in:
openshift/api@e00b981

This commit just adapts the installer to use the new packages.
  • Loading branch information
patrickdillon committed Apr 24, 2024
1 parent 4f67415 commit 62e2d44
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 39 deletions.
3 changes: 2 additions & 1 deletion pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"sigs.k8s.io/yaml"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
machinev1 "github.com/openshift/api/machine/v1"
machinev1alpha1 "github.com/openshift/api/machine/v1alpha1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
Expand Down Expand Up @@ -270,7 +271,7 @@ func (m *Master) Generate(dependencies asset.Parents) error {
// so we don't want to include target pools in the control plane machineset.
// TODO(padillon): once this feature gate is the default and we are
// no longer using Terraform, we can update ConfigMasters not to populate this.
if ic.EnabledFeatureGates().Enabled(configv1.FeatureGateClusterAPIInstall) {
if ic.EnabledFeatureGates().Enabled(features.FeatureGateClusterAPIInstall) {
for _, machine := range machines {
providerSpec, ok := machine.Spec.ProviderSpec.Value.Object.(*machinev1beta1.GCPMachineProviderSpec)
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/asset/manifests/capiutils/helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package capiutils

import (
v1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/ipnet"
)
Expand All @@ -21,7 +21,7 @@ func CIDRFromInstallConfig(installConfig *installconfig.InstallConfig) *ipnet.IP

// IsEnabled returns true if the feature gate is enabled.
func IsEnabled(installConfig *installconfig.InstallConfig) bool {
return installConfig.Config.EnabledFeatureGates().Enabled(v1.FeatureGateClusterAPIInstall)
return installConfig.Config.EnabledFeatureGates().Enabled(features.FeatureGateClusterAPIInstall)
}

// GenerateBoostrapMachineName generates the Cluster API Machine used for bootstrapping
Expand Down
4 changes: 2 additions & 2 deletions pkg/destroy/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/installer/pkg/asset/cluster/metadata"
osp "github.com/openshift/installer/pkg/destroy/openstack"
"github.com/openshift/installer/pkg/infrastructure/openstack/preprovision"
Expand Down Expand Up @@ -73,7 +73,7 @@ func Destroy(ctx context.Context, dir string) (err error) {
// Get cluster profile for new FeatureGate access. Blank is no longer an option, so default to
// SelfManaged.
clusterProfile := types.GetClusterProfileName()
featureSets, ok := configv1.AllFeatureSets()[clusterProfile]
featureSets, ok := features.AllFeatureSets()[clusterProfile]
if !ok {
return fmt.Errorf("no feature sets for cluster profile %q", clusterProfile)
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/infrastructure/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package platform
import (
"fmt"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/installer/pkg/infrastructure"
awscapi "github.com/openshift/installer/pkg/infrastructure/aws/clusterapi"
awsinfra "github.com/openshift/installer/pkg/infrastructure/aws/sdk"
Expand Down Expand Up @@ -50,15 +50,15 @@ import (
func ProviderForPlatform(platform string, fg featuregates.FeatureGate) (infrastructure.Provider, error) {
switch platform {
case awstypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(&awscapi.Provider{}), nil
}
if fg.Enabled(configv1.FeatureGateInstallAlternateInfrastructureAWS) {
if fg.Enabled(features.FeatureGateInstallAlternateInfrastructureAWS) {
return awsinfra.InitializeProvider(), nil
}
return terraform.InitializeProvider(aws.PlatformStages), nil
case azuretypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(&azureinfra.Provider{}), nil
}
return terraform.InitializeProvider(azure.PlatformStages), nil
Expand All @@ -67,36 +67,36 @@ func ProviderForPlatform(platform string, fg featuregates.FeatureGate) (infrastr
case baremetaltypes.Name:
return baremetalinfra.InitializeProvider(), nil
case gcptypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(gcpcapi.Provider{}), nil
}
return terraform.InitializeProvider(gcp.PlatformStages), nil
case ibmcloudtypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(ibmcloudcapi.Provider{}), nil
}
return terraform.InitializeProvider(ibmcloud.PlatformStages), nil
case libvirttypes.Name:
return terraform.InitializeProvider(libvirt.PlatformStages), nil
case nutanixtypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(nutanixcapi.Provider{}), nil
}
return terraform.InitializeProvider(nutanix.PlatformStages), nil
case powervstypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(&powervscapi.Provider{}), nil
}
return terraform.InitializeProvider(powervs.PlatformStages), nil
case openstacktypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(openstackcapi.Provider{}), nil
}
return terraform.InitializeProvider(openstack.PlatformStages), nil
case ovirttypes.Name:
return terraform.InitializeProvider(ovirt.PlatformStages), nil
case vspheretypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(vspherecapi.Provider{}), nil
}
return terraform.InitializeProvider(vsphere.PlatformStages), nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/infrastructure/platform/platform_altinfra.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package platform
import (
"fmt"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/installer/pkg/infrastructure"
awscapi "github.com/openshift/installer/pkg/infrastructure/aws/clusterapi"
awsinfra "github.com/openshift/installer/pkg/infrastructure/aws/sdk"
Expand All @@ -33,40 +33,40 @@ import (
func ProviderForPlatform(platform string, fg featuregates.FeatureGate) (infrastructure.Provider, error) {
switch platform {
case awstypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(&awscapi.Provider{}), nil
}
return awsinfra.InitializeProvider(), nil
case azuretypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(&azurecapi.Provider{}), nil
}
return nil, nil
case gcptypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(gcpcapi.Provider{}), nil
}
return nil, nil
case ibmcloudtypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(ibmcloudcapi.Provider{}), nil
}
return nil, nil
case vspheretypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(vspherecapi.Provider{}), nil
}
case powervstypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(powervscapi.Provider{}), nil
}
return nil, nil
case openstacktypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(openstackcapi.Provider{}), nil
}
case nutanixtypes.Name:
if fg.Enabled(configv1.FeatureGateClusterAPIInstall) {
if fg.Enabled(features.FeatureGateClusterAPIInstall) {
return clusterapi.InitializeProvider(nutanixcapi.Provider{}), nil
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/types/featuregates/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"k8s.io/apimachinery/pkg/util/sets"

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

func toFeatureGateNames(in []configv1.FeatureGateDescription) []configv1.FeatureGateName {
func toFeatureGateNames(in []features.FeatureGateDescription) []configv1.FeatureGateName {
out := []configv1.FeatureGateName{}
for _, curr := range in {
out = append(out, curr.FeatureGateAttributes.Name)
Expand All @@ -21,7 +22,7 @@ func toFeatureGateNames(in []configv1.FeatureGateDescription) []configv1.Feature
}

// completeFeatureGates identifies every known feature and ensures that is explicitly on or explicitly off.
func completeFeatureGates(knownFeatureSets map[configv1.FeatureSet]*configv1.FeatureGateEnabledDisabled, enabled, disabled []configv1.FeatureGateName) ([]configv1.FeatureGateName, []configv1.FeatureGateName) {
func completeFeatureGates(knownFeatureSets map[configv1.FeatureSet]*features.FeatureGateEnabledDisabled, enabled, disabled []configv1.FeatureGateName) ([]configv1.FeatureGateName, []configv1.FeatureGateName) {
specificallyEnabledFeatureGates := sets.New[configv1.FeatureGateName]()
specificallyEnabledFeatureGates.Insert(enabled...)

Expand All @@ -41,7 +42,7 @@ func completeFeatureGates(knownFeatureSets map[configv1.FeatureSet]*configv1.Fea
}

// FeatureGateFromFeatureSets creates a FeatureGate from the active feature sets.
func FeatureGateFromFeatureSets(knownFeatureSets map[configv1.FeatureSet]*configv1.FeatureGateEnabledDisabled, fs configv1.FeatureSet, customFS *configv1.CustomFeatureGates) FeatureGate {
func FeatureGateFromFeatureSets(knownFeatureSets map[configv1.FeatureSet]*features.FeatureGateEnabledDisabled, fs configv1.FeatureSet, customFS *configv1.CustomFeatureGates) FeatureGate {
if customFS != nil {
completeEnabled, completeDisabled := completeFeatureGates(knownFeatureSets, customFS.Enabled, customFS.Disabled)
return newFeatureGate(completeEnabled, completeDisabled)
Expand Down
8 changes: 4 additions & 4 deletions pkg/types/gcp/validation/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package validation
import (
"k8s.io/apimachinery/pkg/util/validation/field"

configv1 "github.com/openshift/api/config/v1"
features "github.com/openshift/api/features"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/featuregates"
"github.com/openshift/installer/pkg/types/gcp"
Expand All @@ -15,17 +15,17 @@ func GatedFeatures(c *types.InstallConfig) []featuregates.GatedInstallConfigFeat
g := c.GCP
return []featuregates.GatedInstallConfigFeature{
{
FeatureGateName: configv1.FeatureGateGCPLabelsTags,
FeatureGateName: features.FeatureGateGCPLabelsTags,
Condition: len(g.UserLabels) > 0,
Field: field.NewPath("platform", "gcp", "userLabels"),
},
{
FeatureGateName: configv1.FeatureGateGCPLabelsTags,
FeatureGateName: features.FeatureGateGCPLabelsTags,
Condition: len(g.UserTags) > 0,
Field: field.NewPath("platform", "gcp", "userTags"),
},
{
FeatureGateName: configv1.FeatureGateGCPClusterHostedDNS,
FeatureGateName: features.FeatureGateGCPClusterHostedDNS,
Condition: g.UserProvisionedDNS == gcp.UserProvisionedDNSEnabled,
Field: field.NewPath("platform", "gcp", "userProvisionedDNS"),
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

configv1 "github.com/openshift/api/config/v1"
features "github.com/openshift/api/features"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/azure"
Expand Down Expand Up @@ -549,7 +550,7 @@ func (c *InstallConfig) EnabledFeatureGates() featuregates.FeatureGate {
}

clusterProfile := GetClusterProfileName()
featureSets, ok := configv1.AllFeatureSets()[clusterProfile]
featureSets, ok := features.AllFeatureSets()[clusterProfile]
if !ok {
logrus.Warnf("no feature sets for cluster profile %q", clusterProfile)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/sirupsen/logrus"

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

// StringsToIPs is used to convert list of strings to list of IP addresses.
Expand Down Expand Up @@ -42,15 +43,15 @@ func MachineNetworksToCIDRs(nets []MachineNetworkEntry) []configv1.CIDR {

// GetClusterProfileName utility method to retrieve the cluster profile setting. This is used
// when dealing with openshift api to get FeatureSets.
func GetClusterProfileName() configv1.ClusterProfileName {
func GetClusterProfileName() features.ClusterProfileName {
// Get cluster profile for new FeatureGate access. Blank is no longer an option, so default to
// SelfManaged.
clusterProfile := configv1.SelfManaged
clusterProfile := features.SelfManaged
if cp := os.Getenv("OPENSHIFT_INSTALL_EXPERIMENTAL_CLUSTER_PROFILE"); cp != "" {
logrus.Warnf("Found override for Cluster Profile: %q", cp)
// All profiles when getting FeatureSets need to have "include.release.openshift.io/" at the beginning.
// See vendor/openshift/api/config/v1/feature_gates.go for more info.
clusterProfile = configv1.ClusterProfileName(fmt.Sprintf("%s%s", "include.release.openshift.io/", cp))
clusterProfile = features.ClusterProfileName(fmt.Sprintf("%s%s", "include.release.openshift.io/", cp))
}
return clusterProfile
}
5 changes: 3 additions & 2 deletions pkg/types/validation/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
utilsnet "k8s.io/utils/net"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
operv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/installer/pkg/hostcrypt"
"github.com/openshift/installer/pkg/ipnet"
Expand Down Expand Up @@ -1229,14 +1230,14 @@ func ValidateFeatureSet(c *types.InstallConfig) field.ErrorList {
allErrs := field.ErrorList{}

clusterProfile := types.GetClusterProfileName()
featureSets, ok := configv1.AllFeatureSets()[clusterProfile]
featureSets, ok := features.AllFeatureSets()[clusterProfile]
if !ok {
logrus.Warnf("no feature sets for cluster profile %q", clusterProfile)
}
if _, ok := featureSets[c.FeatureSet]; c.FeatureSet != configv1.CustomNoUpgrade && !ok {
sortedFeatureSets := func() []string {
v := []string{}
for n := range configv1.AllFeatureSets()[clusterProfile] {
for n := range features.AllFeatureSets()[clusterProfile] {
v = append(v, string(n))
}
// Add CustomNoUpgrade since it is not part of features sets for profiles
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/vsphere/validation/featuregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package validation
import (
"k8s.io/apimachinery/pkg/util/validation/field"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/api/features"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/featuregates"
)
Expand All @@ -14,7 +14,7 @@ func GatedFeatures(c *types.InstallConfig) []featuregates.GatedInstallConfigFeat
v := c.VSphere
return []featuregates.GatedInstallConfigFeature{
{
FeatureGateName: configv1.FeatureGateVSphereStaticIPs,
FeatureGateName: features.FeatureGateVSphereStaticIPs,
Condition: len(v.Hosts) > 0,
Field: field.NewPath("platform", "vsphere", "hosts"),
},
Expand Down

0 comments on commit 62e2d44

Please sign in to comment.