Skip to content

Commit d511eab

Browse files
britaniarRyan Zhang
authored andcommitted
address comments to fix bug (Azure#1080)
1 parent 8d01e32 commit d511eab

2 files changed

Lines changed: 4 additions & 26 deletions

File tree

pkg/controllers/workapplier/availability_tracker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ func trackServiceExportAvailability(curObj *unstructured.Unstructured) (Manifest
292292
return ManifestProcessingAvailabilityResultTypeNotYetAvailable, nil
293293
}
294294
// Validate annotation weight. Updating the annotation won't change the object generation,
295-
// so the current status is not reliable and need to validate the annotation again here
295+
// so the current status is not reliable and need to validate the annotation again here.
296296
weight, err := objectmeta.ExtractWeightFromServiceExport(&svcExport)
297297
if err != nil {
298-
klog.Errorf(err.Error(), "ServiceExport has invalid weight", "serviceExport", svcExportObj)
299-
return ManifestProcessingAvailabilityResultTypeNotYetAvailable, err
298+
klog.Error(err, "ServiceExport has invalid weight", "serviceExport", svcExportObj)
299+
return ManifestProcessingAvailabilityResultTypeNotYetAvailable, nil
300300
}
301301
if weight != 0 {
302302
// Check conflict condition for non-zero weight

pkg/controllers/workapplier/availability_tracker_test.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package workapplier
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"testing"
2322

2423
"github.com/google/go-cmp/cmp"
@@ -1013,7 +1012,6 @@ func TestServiceExportAvailability(t *testing.T) {
10131012
weight string
10141013
status fleetnetworkingv1alpha1.ServiceExportStatus
10151014
wantManifestProcessingAvailabilityResultType ManifestProcessingAvailabilityResultType
1016-
err error
10171015
}{
10181016
{
10191017
name: "available svcExport (annotation weight is 0)",
@@ -1029,7 +1027,6 @@ func TestServiceExportAvailability(t *testing.T) {
10291027
},
10301028
},
10311029
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeAvailable,
1032-
err: nil,
10331030
},
10341031
{
10351032
name: "unavailable svcExport (ServiceExportValid is false)",
@@ -1045,7 +1042,6 @@ func TestServiceExportAvailability(t *testing.T) {
10451042
},
10461043
},
10471044
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1048-
err: nil,
10491045
},
10501046
{
10511047
name: "unavailable svcExport (different generation, annotation weight is 0)",
@@ -1061,7 +1057,6 @@ func TestServiceExportAvailability(t *testing.T) {
10611057
},
10621058
},
10631059
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1064-
err: nil,
10651060
},
10661061
{
10671062
name: "available svcExport with no conflict (annotation weight is 1)",
@@ -1083,7 +1078,6 @@ func TestServiceExportAvailability(t *testing.T) {
10831078
},
10841079
},
10851080
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeAvailable,
1086-
err: nil,
10871081
},
10881082
{
10891083
name: "unavailable svcExport with conflict (annotation weight is 1)",
@@ -1105,7 +1099,6 @@ func TestServiceExportAvailability(t *testing.T) {
11051099
},
11061100
},
11071101
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1108-
err: nil,
11091102
},
11101103
{
11111104
name: "unavailable invalid svcExport (annotation weight is 1)",
@@ -1121,7 +1114,6 @@ func TestServiceExportAvailability(t *testing.T) {
11211114
},
11221115
},
11231116
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1124-
err: nil,
11251117
},
11261118
{
11271119
name: "unavailable svcExport (different generation, annotation weight is 1)",
@@ -1143,7 +1135,6 @@ func TestServiceExportAvailability(t *testing.T) {
11431135
},
11441136
},
11451137
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1146-
err: nil,
11471138
},
11481139
{
11491140
name: "unavailable svcExport (no annotation weight, no conflict condition)",
@@ -1159,7 +1150,6 @@ func TestServiceExportAvailability(t *testing.T) {
11591150
},
11601151
},
11611152
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1162-
err: nil,
11631153
},
11641154
{
11651155
name: "available svcExport (no annotation weight)",
@@ -1181,7 +1171,6 @@ func TestServiceExportAvailability(t *testing.T) {
11811171
},
11821172
},
11831173
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeAvailable,
1184-
err: nil,
11851174
},
11861175
{
11871176
name: "unavailable svcExport (no annotation weight with conflict)",
@@ -1203,7 +1192,6 @@ func TestServiceExportAvailability(t *testing.T) {
12031192
},
12041193
},
12051194
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1206-
err: nil,
12071195
},
12081196
{
12091197
name: "unavailable svcExport (no annotation weight, different generation)",
@@ -1225,7 +1213,6 @@ func TestServiceExportAvailability(t *testing.T) {
12251213
},
12261214
},
12271215
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1228-
err: nil,
12291216
},
12301217
{
12311218
name: "unavailable svcExport (no annotation weight, invalid service export)",
@@ -1241,7 +1228,6 @@ func TestServiceExportAvailability(t *testing.T) {
12411228
},
12421229
},
12431230
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1244-
err: nil,
12451231
},
12461232
{
12471233
name: "unavailable svcExport (invalid weight)",
@@ -1257,7 +1243,6 @@ func TestServiceExportAvailability(t *testing.T) {
12571243
},
12581244
},
12591245
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1260-
err: fmt.Errorf("the weight annotation is not a valid integer: a"),
12611246
},
12621247
{
12631248
name: "unavailable svcExport (out of range weight)",
@@ -1273,7 +1258,6 @@ func TestServiceExportAvailability(t *testing.T) {
12731258
},
12741259
},
12751260
wantManifestProcessingAvailabilityResultType: ManifestProcessingAvailabilityResultTypeNotYetAvailable,
1276-
err: fmt.Errorf("the weight annotation is not in the range [0, 1000]: 1002"),
12771261
},
12781262
}
12791263

@@ -1285,14 +1269,8 @@ func TestServiceExportAvailability(t *testing.T) {
12851269
}
12861270
svcExport.Status = tc.status
12871271
gotResTyp, err := trackServiceExportAvailability(toUnstructured(t, svcExport))
1288-
1289-
// Check for errors
12901272
if err != nil {
1291-
if tc.err == nil || err.Error() != tc.err.Error() {
1292-
t.Fatalf("trackServiceExportAvailability() = %v, want %v", err, tc.err)
1293-
}
1294-
} else if tc.err != nil {
1295-
t.Fatalf("trackServiceExportAvailability() = nil, want error: %v", tc.err)
1273+
t.Fatalf("trackServiceExportAvailability() = %v, want no error", err)
12961274
}
12971275

12981276
// Check the result type

0 commit comments

Comments
 (0)