Skip to content

Commit 45974cd

Browse files
authored
Merge pull request #11921 from sbueringer/pr-set-feature-gate-tests-correctly
🌱 Set MachinePool feature gates in tests correctly with testutil
2 parents 4fd9458 + d5a235a commit 45974cd

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/types"
3131
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
32+
utilfeature "k8s.io/component-base/featuregate/testing"
3233
"k8s.io/utils/ptr"
3334
ctrl "sigs.k8s.io/controller-runtime"
3435
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -725,7 +726,7 @@ func TestReconcileIfJoinCertificatesAvailableConditioninNodesAndControlPlaneIsRe
725726
}
726727

727728
func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {
728-
_ = feature.MutableGates.Set("MachinePool=true")
729+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachinePool, true)
729730

730731
cluster := builder.Cluster(metav1.NamespaceDefault, "cluster").Build()
731732
cluster.Status.InfrastructureReady = true
@@ -1250,7 +1251,7 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
12501251
}
12511252

12521253
func TestBootstrapTokenRotationMachinePool(t *testing.T) {
1253-
_ = feature.MutableGates.Set("MachinePool=true")
1254+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachinePool, true)
12541255
g := NewWithT(t)
12551256

12561257
cluster := builder.Cluster(metav1.NamespaceDefault, "cluster").Build()
@@ -1515,7 +1516,7 @@ func TestBootstrapTokenRefreshIfTokenSecretCleaned(t *testing.T) {
15151516
g.Expect(l.Items).To(BeEmpty())
15161517
})
15171518
t.Run("should recreate the token for MachinePools", func(t *testing.T) {
1518-
_ = feature.MutableGates.Set("MachinePool=true")
1519+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachinePool, true)
15191520
g := NewWithT(t)
15201521

15211522
cluster := builder.Cluster(metav1.NamespaceDefault, "cluster").Build()
@@ -2002,7 +2003,7 @@ func TestKubeadmConfigReconciler_Reconcile_AlwaysCheckCAVerificationUnlessReques
20022003
// If a cluster object changes then all associated KubeadmConfigs should be re-reconciled.
20032004
// This allows us to not requeue a kubeadm config while we wait for InfrastructureReady.
20042005
func TestKubeadmConfigReconciler_ClusterToKubeadmConfigs(t *testing.T) {
2005-
_ = feature.MutableGates.Set("MachinePool=true")
2006+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachinePool, true)
20062007
g := NewWithT(t)
20072008

20082009
cluster := builder.Cluster(metav1.NamespaceDefault, "my-cluster").Build()

bootstrap/util/configowner_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2727
"k8s.io/apimachinery/pkg/runtime"
28+
utilfeature "k8s.io/component-base/featuregate/testing"
2829
"k8s.io/utils/ptr"
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
"sigs.k8s.io/controller-runtime/pkg/client/fake"
@@ -87,7 +88,7 @@ func TestGetConfigOwner(t *testing.T) {
8788
})
8889

8990
t.Run("should get the owner when present (MachinePool)", func(t *testing.T) {
90-
_ = feature.MutableGates.Set("MachinePool=true")
91+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachinePool, true)
9192

9293
g := NewWithT(t)
9394
myPool := &expv1.MachinePool{

controlplane/kubeadm/internal/controllers/controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"k8s.io/apimachinery/pkg/util/intstr"
4141
"k8s.io/client-go/tools/clientcmd"
4242
"k8s.io/client-go/tools/record"
43+
utilfeature "k8s.io/component-base/featuregate/testing"
4344
"k8s.io/utils/ptr"
4445
ctrl "sigs.k8s.io/controller-runtime"
4546
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -3602,7 +3603,7 @@ func TestKubeadmControlPlaneReconciler_reconcileDelete(t *testing.T) {
36023603
})
36033604

36043605
t.Run("does not remove any control plane Machines if MachinePools exist", func(t *testing.T) {
3605-
_ = feature.MutableGates.Set("MachinePool=true")
3606+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachinePool, true)
36063607
g := NewWithT(t)
36073608

36083609
cluster, kcp, _ := createClusterWithControlPlane(metav1.NamespaceDefault)

internal/controllers/cluster/cluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ func (b *machinePoolBuilder) build() expv1.MachinePool {
720720
}
721721

722722
func TestFilterOwnedDescendants(t *testing.T) {
723-
_ = feature.MutableGates.Set("MachinePool=true")
723+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachinePool, true)
724724

725725
c := clusterv1.Cluster{
726726
TypeMeta: metav1.TypeMeta{

0 commit comments

Comments
 (0)