Skip to content

Commit e50e0e3

Browse files
committed
Get unit tests green after kube 1.18 deps update
This commit mostly ensures we set the API version in the expected objects otherwise equality.Semantic.DeepEqual fails to compare with what is coming from the fake client.
1 parent 8d16ab9 commit e50e0e3

File tree

6 files changed

+44
-19
lines changed

6 files changed

+44
-19
lines changed

hack/fetch_ext_bins.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ if [ -n "$TRACE" ]; then
2626
set -x
2727
fi
2828

29-
# k8s_version=1.10.1
30-
k8s_version=1.14.1
29+
k8s_version=1.16.4
3130
goarch=amd64
3231
goos="unknown"
3332

pkg/apis/vsphereprovider/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/machinehealthcheck/machinehealthcheck_controller_test.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,8 @@ func TestGetTargetsFromMHC(t *testing.T) {
936936
Labels: map[string]string{},
937937
},
938938
TypeMeta: metav1.TypeMeta{
939-
Kind: "Node",
939+
Kind: "Node",
940+
APIVersion: "v1",
940941
},
941942
Status: corev1.NodeStatus{
942943
Conditions: []corev1.NodeCondition{},
@@ -963,7 +964,8 @@ func TestGetTargetsFromMHC(t *testing.T) {
963964
Labels: map[string]string{},
964965
},
965966
TypeMeta: metav1.TypeMeta{
966-
Kind: "Node",
967+
Kind: "Node",
968+
APIVersion: "v1",
967969
},
968970
Status: corev1.NodeStatus{
969971
Conditions: []corev1.NodeCondition{},
@@ -979,7 +981,8 @@ func TestGetTargetsFromMHC(t *testing.T) {
979981
Labels: map[string]string{},
980982
},
981983
TypeMeta: metav1.TypeMeta{
982-
Kind: "Node",
984+
Kind: "Node",
985+
APIVersion: "v1",
983986
},
984987
Status: corev1.NodeStatus{
985988
Conditions: []corev1.NodeCondition{},
@@ -1000,7 +1003,8 @@ func TestGetTargetsFromMHC(t *testing.T) {
10001003
Labels: map[string]string{},
10011004
},
10021005
TypeMeta: metav1.TypeMeta{
1003-
Kind: "Node",
1006+
Kind: "Node",
1007+
APIVersion: "v1",
10041008
},
10051009
Status: corev1.NodeStatus{
10061010
Conditions: []corev1.NodeCondition{},
@@ -1020,7 +1024,8 @@ func TestGetTargetsFromMHC(t *testing.T) {
10201024
Labels: map[string]string{},
10211025
},
10221026
TypeMeta: metav1.TypeMeta{
1023-
Kind: "Node",
1027+
Kind: "Node",
1028+
APIVersion: "v1",
10241029
},
10251030
Status: corev1.NodeStatus{
10261031
Conditions: []corev1.NodeCondition{},
@@ -1100,7 +1105,7 @@ func TestGetTargetsFromMHC(t *testing.T) {
11001105
t.Run(tc.testCase, func(t *testing.T) {
11011106
got, err := newFakeReconciler(objects...).getTargetsFromMHC(*tc.mhc)
11021107
if !equality.Semantic.DeepEqual(got, tc.expectedTargets) {
1103-
t.Errorf("Case: %v. Got: %v, expected: %v", tc.testCase, got, tc.expectedTargets)
1108+
t.Errorf("Case: %v. Got: %+v, expected: %+v", tc.testCase, got, tc.expectedTargets)
11041109
}
11051110
if tc.expectedError != (err != nil) {
11061111
t.Errorf("Case: %v. Got: %v, expected error: %v", tc.testCase, err, tc.expectedError)
@@ -1162,7 +1167,8 @@ func TestGetNodeFromMachine(t *testing.T) {
11621167
Labels: map[string]string{},
11631168
},
11641169
TypeMeta: metav1.TypeMeta{
1165-
Kind: "Node",
1170+
Kind: "Node",
1171+
APIVersion: "v1",
11661172
},
11671173
Status: corev1.NodeStatus{
11681174
Conditions: []corev1.NodeCondition{},
@@ -1883,7 +1889,10 @@ func TestRemediate(t *testing.T) {
18831889
testCase: "no master",
18841890
target: &target{
18851891
Machine: mapiv1beta1.Machine{
1886-
TypeMeta: metav1.TypeMeta{Kind: "Machine"},
1892+
TypeMeta: metav1.TypeMeta{
1893+
Kind: "Machine",
1894+
APIVersion: "machine.openshift.io/v1beta1",
1895+
},
18871896
ObjectMeta: metav1.ObjectMeta{
18881897
Annotations: make(map[string]string),
18891898
Name: "test",
@@ -1918,7 +1927,10 @@ func TestRemediate(t *testing.T) {
19181927
testCase: "node master",
19191928
target: &target{
19201929
Machine: mapiv1beta1.Machine{
1921-
TypeMeta: metav1.TypeMeta{Kind: "Machine"},
1930+
TypeMeta: metav1.TypeMeta{
1931+
Kind: "Machine",
1932+
APIVersion: "machine.openshift.io/v1beta1",
1933+
},
19221934
ObjectMeta: metav1.ObjectMeta{
19231935
Annotations: make(map[string]string),
19241936
Name: "test",
@@ -1956,7 +1968,10 @@ func TestRemediate(t *testing.T) {
19561968
testCase: "machine master",
19571969
target: &target{
19581970
Machine: mapiv1beta1.Machine{
1959-
TypeMeta: metav1.TypeMeta{Kind: "Machine"},
1971+
TypeMeta: metav1.TypeMeta{
1972+
Kind: "Machine",
1973+
APIVersion: "machine.openshift.io/v1beta1",
1974+
},
19601975
ObjectMeta: metav1.ObjectMeta{
19611976
Annotations: make(map[string]string),
19621977
Name: "test",
@@ -1989,7 +2004,7 @@ func TestRemediate(t *testing.T) {
19892004
}
19902005
assertEvents(t, tc.testCase, tc.expectedEvents, recorder.Events)
19912006
machine := &mapiv1beta1.Machine{}
1992-
err := r.client.Get(context.TODO(), namespacedName(machine), machine)
2007+
err := r.client.Get(context.TODO(), namespacedName(&tc.target.Machine), machine)
19932008
if tc.deletion {
19942009
if err != nil {
19952010
if !errors.IsNotFound(err) {
@@ -2001,7 +2016,7 @@ func TestRemediate(t *testing.T) {
20012016
}
20022017
if !tc.deletion {
20032018
if !equality.Semantic.DeepEqual(*machine, tc.target.Machine) {
2004-
t.Errorf("Case: %v. Got: %v, expected: %v", tc.testCase, *machine, tc.target.Machine)
2019+
t.Errorf("Case: %v. Got: %+v, expected: %+v", tc.testCase, *machine, tc.target.Machine)
20052020
}
20062021
}
20072022
})

pkg/controller/machineset/machineset_controller_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ var expectedRequest = reconcile.Request{NamespacedName: types.NamespacedName{Nam
3535

3636
const timeout = time.Second * 5
3737

38+
// TODO: drop this in favour of ginkgo like validations
39+
// similar to https://github.com/kubernetes-sigs/cluster-api/blob/master/controllers/machineset_controller_test.go
3840
func TestReconcile(t *testing.T) {
3941
// Setup the Manager and Controller. Wrap the Controller Reconcile function so it writes each request to a
4042
// channel when it is finished.
@@ -158,12 +160,18 @@ func TestReconcile(t *testing.T) {
158160
}
159161

160162
defer func() {
161-
c.Delete(context.TODO(), tc.instance)
163+
err := c.Delete(context.TODO(), tc.instance)
164+
if err != nil {
165+
t.Logf("error deleting %v: %v", tc.instance, err)
166+
}
167+
162168
select {
163169
case recv := <-requests:
164170
if recv != tc.expectedRequest {
165171
t.Error("received request does not match expected request")
166172
}
173+
174+
t.Logf("Last reconcile %v", <-requests)
167175
case <-time.After(timeout):
168176
t.Error("timed out waiting for request")
169177
}
@@ -172,7 +180,7 @@ func TestReconcile(t *testing.T) {
172180
select {
173181
case recv := <-requests:
174182
if recv != tc.expectedRequest {
175-
t.Error("received request does not match expected request")
183+
t.Errorf("received request does not match expected request. Got: %v, expected: %v", recv, tc.expectedRequest)
176184
}
177185
case <-time.After(timeout):
178186
t.Error("timed out waiting for request")

pkg/controller/vsphere/machine_scope_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ func TestPatchMachine(t *testing.T) {
326326
Namespace: namespace,
327327
},
328328
TypeMeta: metav1.TypeMeta{
329-
Kind: "Machine",
329+
Kind: "Machine",
330+
APIVersion: "machine.openshift.io/v1beta1",
330331
},
331332
Spec: machinev1.MachineSpec{
332333
ProviderSpec: machinev1.ProviderSpec{
@@ -384,6 +385,7 @@ func TestPatchMachine(t *testing.T) {
384385
t.Fatal(err)
385386
}
386387

388+
expectedMachine.ResourceVersion = "2"
387389
if !equality.Semantic.DeepEqual(gotMachine, expectedMachine) {
388390
t.Errorf("expected: %+v, got: %+v", expectedMachine, gotMachine)
389391
}

pkg/operator/operator_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,15 @@ func TestOperatorSync_NoOp(t *testing.T) {
132132
stopCh := make(<-chan struct{})
133133
optr := newFakeOperator(nil, []runtime.Object{infra}, stopCh)
134134
optr.queue.Add("trigger")
135-
go optr.Run(2, stopCh)
135+
go optr.Run(1, stopCh)
136136

137137
err := wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
138138
_, err := optr.deployLister.Deployments(targetNamespace).Get(deploymentName)
139139
if err != nil {
140140
t.Logf("Failed to get %q deployment: %v", deploymentName, err)
141141
return false, nil
142142
}
143+
t.Logf("Found deployment: %q", deploymentName)
143144
return true, nil
144145
})
145146

0 commit comments

Comments
 (0)