Skip to content

Commit 0a32aa5

Browse files
committed
fix deprecated tests
1 parent eec55ae commit 0a32aa5

File tree

6 files changed

+43
-61
lines changed

6 files changed

+43
-61
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ linters:
366366
- linters:
367367
- govet
368368
text: non-constant format string in call to sigs\.k8s\.io\/cluster-api\/util\/conditions\.
369+
- linters:
370+
- govet
371+
text: non-constant format string in call to sigs\.k8s\.io\/cluster-api\/util\/deprecated\/v1beta1\/conditions\.
369372
- linters:
370373
- goconst
371374
path: (.+)_test\.go

util/deprecated/v1beta1/conditions/getter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func mirror(from Getter, targetCondition clusterv1.ConditionType, options ...Mir
235235
case true:
236236
condition = TrueCondition(targetCondition)
237237
case false:
238-
condition = FalseCondition(targetCondition, mirrorOpt.fallbackReason, mirrorOpt.fallbackSeverity, mirrorOpt.fallbackMessage)
238+
condition = FalseCondition(targetCondition, mirrorOpt.fallbackReason, mirrorOpt.fallbackSeverity, "%s", mirrorOpt.fallbackMessage)
239239
}
240240
}
241241

util/deprecated/v1beta1/conditions/merge.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ func merge(conditions []localizedCondition, targetCondition clusterv1.ConditionT
7676
targetReason := getReason(g, options)
7777
targetMessage := getMessage(g, options)
7878
if g.TopGroup().status == corev1.ConditionFalse {
79-
return FalseCondition(targetCondition, targetReason, g.TopGroup().severity, targetMessage)
79+
return FalseCondition(targetCondition, targetReason, g.TopGroup().severity, "%s", targetMessage)
8080
}
81-
return UnknownCondition(targetCondition, targetReason, targetMessage)
81+
return UnknownCondition(targetCondition, targetReason, "%s", targetMessage)
8282
}
8383

8484
// getConditionGroups groups a list of conditions according to status, severity values.

util/deprecated/v1beta1/patch/patch_test.go

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2828
"k8s.io/apimachinery/pkg/types"
29-
"k8s.io/utils/ptr"
3029
"sigs.k8s.io/controller-runtime/pkg/client"
3130

3231
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -52,7 +51,7 @@ func TestPatchHelper(t *testing.T) {
5251
obj := &unstructured.Unstructured{
5352
Object: map[string]interface{}{
5453
"kind": "GenericBootstrapConfig",
55-
"apiVersion": "bootstrap.cluster.x-k8s.io/v1beta1",
54+
"apiVersion": "bootstrap.cluster.x-k8s.io/v1beta2",
5655
"metadata": map[string]interface{}{
5756
"generateName": "test-bootstrap-",
5857
"namespace": ns.Name,
@@ -171,8 +170,8 @@ func TestPatchHelper(t *testing.T) {
171170
}, timeout).Should(BeTrue())
172171
})
173172

174-
t.Run("on a clusterv1.Cluster object", func(t *testing.T) {
175-
obj := &clusterv1.Cluster{
173+
t.Run("on a Phase1 object", func(t *testing.T) {
174+
obj := &builder.Phase1Obj{
176175
ObjectMeta: metav1.ObjectMeta{
177176
GenerateName: "test-",
178177
Namespace: ns.Name,
@@ -317,10 +316,8 @@ func TestPatchHelper(t *testing.T) {
317316
g.Expect(err).ToNot(HaveOccurred())
318317

319318
t.Log("Changing the object spec, status, and adding Ready=True condition")
320-
obj.Spec.Paused = true
321-
obj.Spec.ControlPlaneEndpoint.Host = "test://endpoint"
322-
obj.Spec.ControlPlaneEndpoint.Port = 8443
323-
obj.Status.Phase = "Provisioning"
319+
obj.Spec.Foo = "Foo"
320+
obj.Status.Bar = "Bar"
324321
conditions.MarkTrue(obj, clusterv1.ReadyCondition)
325322

326323
t.Log("Patching the object")
@@ -353,9 +350,8 @@ func TestPatchHelper(t *testing.T) {
353350
return false
354351
}
355352

356-
return obj.Spec.Paused == objAfter.Spec.Paused &&
357-
obj.Spec.ControlPlaneEndpoint == objAfter.Spec.ControlPlaneEndpoint &&
358-
obj.Status.Phase == objAfter.Status.Phase
353+
return obj.Spec.Foo == objAfter.Spec.Foo &&
354+
obj.Status.Bar == objAfter.Status.Bar
359355
}, timeout).Should(BeTrue(), cmp.Diff(obj, objAfter))
360356
})
361357

@@ -514,8 +510,8 @@ func TestPatchHelper(t *testing.T) {
514510
})
515511
})
516512

517-
t.Run("Should patch a clusterv1.Cluster", func(t *testing.T) {
518-
obj := &clusterv1.Cluster{
513+
t.Run("Should patch a Phase1Obj", func(t *testing.T) {
514+
obj := &builder.Phase1Obj{
519515
ObjectMeta: metav1.ObjectMeta{
520516
GenerateName: "test-",
521517
Namespace: ns.Name,
@@ -624,12 +620,7 @@ func TestPatchHelper(t *testing.T) {
624620
g.Expect(err).ToNot(HaveOccurred())
625621

626622
t.Log("Updating the object spec")
627-
obj.Spec.Paused = true
628-
obj.Spec.InfrastructureRef = &corev1.ObjectReference{
629-
Kind: "test-kind",
630-
Name: "test-ref",
631-
Namespace: ns.Name,
632-
}
623+
obj.Spec.Foo = "Foo"
633624

634625
t.Log("Patching the object")
635626
g.Expect(patcher.Patch(ctx, obj)).To(Succeed())
@@ -641,8 +632,7 @@ func TestPatchHelper(t *testing.T) {
641632
return false
642633
}
643634

644-
return objAfter.Spec.Paused &&
645-
cmp.Equal(obj.Spec.InfrastructureRef, objAfter.Spec.InfrastructureRef)
635+
return obj.Spec.Foo == objAfter.Spec.Foo
646636
}, timeout).Should(BeTrue())
647637
})
648638

@@ -669,7 +659,7 @@ func TestPatchHelper(t *testing.T) {
669659
g.Expect(err).ToNot(HaveOccurred())
670660

671661
t.Log("Updating the object status")
672-
obj.Status.InfrastructureReady = true
662+
obj.Status.Bar = "Bar"
673663

674664
t.Log("Patching the object")
675665
g.Expect(patcher.Patch(ctx, obj)).To(Succeed())
@@ -707,15 +697,10 @@ func TestPatchHelper(t *testing.T) {
707697
g.Expect(err).ToNot(HaveOccurred())
708698

709699
t.Log("Updating the object spec")
710-
obj.Spec.Paused = true
711-
obj.Spec.InfrastructureRef = &corev1.ObjectReference{
712-
Kind: "test-kind",
713-
Name: "test-ref",
714-
Namespace: ns.Name,
715-
}
700+
obj.Spec.Foo = "Foo"
716701

717702
t.Log("Updating the object status")
718-
obj.Status.InfrastructureReady = true
703+
obj.Status.Bar = "Bar"
719704

720705
t.Log("Setting Ready condition")
721706
conditions.MarkTrue(obj, clusterv1.ReadyCondition)
@@ -730,7 +715,7 @@ func TestPatchHelper(t *testing.T) {
730715
return false
731716
}
732717

733-
return obj.Status.InfrastructureReady == objAfter.Status.InfrastructureReady &&
718+
return cmp.Equal(obj.Status.Bar, objAfter.Status.Bar) &&
734719
conditions.IsTrue(objAfter, clusterv1.ReadyCondition) &&
735720
cmp.Equal(obj.Spec, objAfter.Spec)
736721
}, timeout).Should(BeTrue())
@@ -788,19 +773,11 @@ func TestPatchHelper(t *testing.T) {
788773
})
789774

790775
t.Run("Should update Status.ObservedGeneration when using WithStatusObservedGeneration option", func(t *testing.T) {
791-
obj := &clusterv1.MachineSet{
776+
obj := &builder.Phase1Obj{
792777
ObjectMeta: metav1.ObjectMeta{
793778
GenerateName: "test-ms",
794779
Namespace: ns.Name,
795780
},
796-
Spec: clusterv1.MachineSetSpec{
797-
ClusterName: "test1",
798-
Template: clusterv1.MachineTemplateSpec{
799-
Spec: clusterv1.MachineSpec{
800-
ClusterName: "test1",
801-
},
802-
},
803-
},
804781
}
805782

806783
t.Run("when updating spec", func(t *testing.T) {
@@ -826,7 +803,7 @@ func TestPatchHelper(t *testing.T) {
826803
g.Expect(err).ToNot(HaveOccurred())
827804

828805
t.Log("Updating the object spec")
829-
obj.Spec.Replicas = ptr.To[int32](10)
806+
obj.Spec.Foo = "Foo"
830807

831808
t.Log("Patching the object")
832809
g.Expect(patcher.Patch(ctx, obj, WithStatusObservedGeneration{})).To(Succeed())
@@ -866,11 +843,10 @@ func TestPatchHelper(t *testing.T) {
866843
g.Expect(err).ToNot(HaveOccurred())
867844

868845
t.Log("Updating the object spec")
869-
obj.Spec.Replicas = ptr.To[int32](10)
846+
obj.Spec.Foo = "Foo"
870847

871848
t.Log("Updating the object status")
872-
obj.Status.AvailableReplicas = 6
873-
obj.Status.ReadyReplicas = 6
849+
obj.Status.Bar = "Bar"
874850

875851
t.Log("Updating the object metadata")
876852
obj.ObjectMeta.Annotations = map[string]string{
@@ -936,26 +912,18 @@ func TestPatchHelper(t *testing.T) {
936912
t.Run("Should error if the object isn't the same", func(t *testing.T) {
937913
g := NewWithT(t)
938914

939-
cluster := &clusterv1.Cluster{
915+
cluster := &builder.Phase0Obj{
940916
ObjectMeta: metav1.ObjectMeta{
941917
GenerateName: "test-",
942918
Namespace: ns.Name,
943919
},
944920
}
945921

946-
machineSet := &clusterv1.MachineSet{
922+
machineSet := &builder.Phase1Obj{
947923
ObjectMeta: metav1.ObjectMeta{
948-
GenerateName: "test-ms",
924+
GenerateName: "test-2",
949925
Namespace: ns.Name,
950926
},
951-
Spec: clusterv1.MachineSetSpec{
952-
ClusterName: "test1",
953-
Template: clusterv1.MachineTemplateSpec{
954-
Spec: clusterv1.MachineSpec{
955-
ClusterName: "test1",
956-
},
957-
},
958-
},
959927
}
960928

961929
g.Expect(env.Create(ctx, cluster)).To(Succeed())
@@ -975,13 +943,13 @@ func TestPatchHelper(t *testing.T) {
975943

976944
t.Run("Should not error if there are no finalizers and deletion timestamp is not nil", func(t *testing.T) {
977945
g := NewWithT(t)
978-
cluster := &clusterv1.Cluster{
946+
cluster := &builder.Phase1Obj{
979947
ObjectMeta: metav1.ObjectMeta{
980948
Name: "test-cluster",
981949
Namespace: ns.Name,
982950
Finalizers: []string{"block-deletion"},
983951
},
984-
Status: clusterv1.ClusterStatus{},
952+
Status: builder.Phase1ObjStatus{},
985953
}
986954
key := client.ObjectKey{Name: cluster.GetName(), Namespace: cluster.GetNamespace()}
987955
g.Expect(env.Create(ctx, cluster)).To(Succeed())
@@ -998,7 +966,7 @@ func TestPatchHelper(t *testing.T) {
998966
patcher, err := NewHelper(cluster, env)
999967
g.Expect(err).ToNot(HaveOccurred())
1000968
cluster.Finalizers = []string{}
1001-
cluster.Status.Phase = "Running"
969+
cluster.Status.Bar = "Bar"
1002970
g.Expect(patcher.Patch(ctx, cluster)).To(Succeed())
1003971
})
1004972
}

util/deprecated/v1beta1/patch/suite_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ package patch
1818

1919
import (
2020
"os"
21+
"path/filepath"
2122
"testing"
2223
"time"
2324

25+
"k8s.io/apimachinery/pkg/runtime"
2426
ctrl "sigs.k8s.io/controller-runtime"
2527

28+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
2629
"sigs.k8s.io/cluster-api/internal/test/envtest"
30+
"sigs.k8s.io/cluster-api/util/deprecated/v1beta1/test/builder"
2731
)
2832

2933
const (
@@ -39,5 +43,12 @@ func TestMain(m *testing.M) {
3943
os.Exit(envtest.Run(ctx, envtest.RunInput{
4044
M: m,
4145
SetupEnv: func(e *envtest.Environment) { env = e },
46+
AdditionalCRDDirectoryPaths: []string{
47+
filepath.Join("util", "deprecated", "v1beta1", "test", "builder", "crd"),
48+
},
49+
AdditionalSchemeBuilder: runtime.NewSchemeBuilder(
50+
builder.AddTransitionV1Beta2ToScheme,
51+
clusterv1beta1.AddToScheme,
52+
),
4253
}))
4354
}

util/deprecated/v1beta1/patch/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"k8s.io/apimachinery/pkg/runtime/schema"
2727

2828
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
29-
"sigs.k8s.io/cluster-api/util/test/builder"
29+
"sigs.k8s.io/cluster-api/util/deprecated/v1beta1/test/builder"
3030
)
3131

3232
func TestToUnstructured(t *testing.T) {

0 commit comments

Comments
 (0)