Skip to content

Commit c495d5c

Browse files
committed
minor fixes
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
1 parent 92f96f1 commit c495d5c

File tree

3 files changed

+147
-6
lines changed

3 files changed

+147
-6
lines changed

pkg/controllers/workgenerator/controller.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req controllerruntime.Reques
223223
switch {
224224
case workDeleted:
225225
// Some Work object(s) are being deleted; set a False Applied condition which signals
226-
// that resources are in the process of being applied.
226+
// that resources are in the process of being deleted.
227227
klog.V(2).InfoS("Some work being deleted", "resourceBinding", bindingRef)
228228
setBindingStatus(workDeleted, works, &resourceBinding)
229229
syncErr = controller.NewUserError(fmt.Errorf("some work objects are being deleted"))
@@ -553,7 +553,6 @@ func (r *Reconciler) syncAllWork(ctx context.Context, resourceBinding *fleetv1be
553553
}
554554

555555
// delete the works that are not associated with any resource snapshot
556-
deletedWork := make([]*fleetv1beta1.Work, len(existingWorks))
557556
for i := range existingWorks {
558557
work := existingWorks[i]
559558
if _, exist := activeWork[work.Name]; exist {
@@ -566,9 +565,7 @@ func (r *Reconciler) syncAllWork(ctx context.Context, resourceBinding *fleetv1be
566565
return controller.NewAPIServerError(false, err)
567566
}
568567
}
569-
deletedWork = append(deletedWork, work)
570568
klog.V(2).InfoS("Deleted the work that is not associated with any resource snapshot", "work", klog.KObj(work))
571-
//updateAny.Store(true)
572569
deletedAny.Store(true)
573570
return nil
574571
})

pkg/controllers/workgenerator/controller_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ var _ = Describe("Test Work Generator Controller", func() {
596596
})
597597
})
598598

599-
Context("Test Bound ClusterResourceBinding with a single resource snapshot with envelop objects", Serial, func() {
599+
Context("Test Bound ClusterResourceBinding with a single resource snapshot with envelop objects", func() {
600600
var masterSnapshot *placementv1beta1.ClusterResourceSnapshot
601601

602602
BeforeEach(func() {

pkg/controllers/workgenerator/controller_test.go

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ func TestSetBindingStatus(t *testing.T) {
12961296
tests := map[string]struct {
12971297
works map[string]*fleetv1beta1.Work
12981298
applyStrategy *fleetv1beta1.ApplyStrategy
1299+
workDeleted bool
12991300
maxFailedResourcePlacementLimit *int
13001301
wantFailedResourcePlacements []fleetv1beta1.FailedResourcePlacement
13011302
maxDriftedResourcePlacementLimit *int
@@ -1522,6 +1523,7 @@ func TestSetBindingStatus(t *testing.T) {
15221523
},
15231524
},
15241525
},
1526+
15251527
"One work has one not available and one work has one not applied (exceed the maxFailedResourcePlacementLimit)": {
15261528
works: map[string]*fleetv1beta1.Work{
15271529
"work1": {
@@ -2366,6 +2368,148 @@ func TestSetBindingStatus(t *testing.T) {
23662368
},
23672369
},
23682370
},
2371+
"Some work has been applied and some has been deleted": {
2372+
works: map[string]*fleetv1beta1.Work{
2373+
"work1": {
2374+
Status: fleetv1beta1.WorkStatus{
2375+
ManifestConditions: []fleetv1beta1.ManifestCondition{
2376+
{
2377+
Identifier: fleetv1beta1.WorkResourceIdentifier{
2378+
Ordinal: 0,
2379+
Group: "",
2380+
Version: "v1",
2381+
Kind: "ConfigMap",
2382+
Name: "config-name",
2383+
Namespace: "config-namespace",
2384+
},
2385+
Conditions: []metav1.Condition{
2386+
{
2387+
Type: fleetv1beta1.WorkConditionTypeApplied,
2388+
Status: metav1.ConditionTrue,
2389+
},
2390+
{
2391+
Type: fleetv1beta1.WorkConditionTypeAvailable,
2392+
Status: metav1.ConditionFalse,
2393+
},
2394+
},
2395+
},
2396+
{
2397+
Identifier: fleetv1beta1.WorkResourceIdentifier{
2398+
Ordinal: 1,
2399+
Group: "",
2400+
Version: "v1",
2401+
Kind: "Service",
2402+
Name: "svc-name",
2403+
Namespace: "svc-namespace",
2404+
},
2405+
Conditions: []metav1.Condition{
2406+
{
2407+
Type: fleetv1beta1.WorkConditionTypeApplied,
2408+
Status: metav1.ConditionTrue,
2409+
},
2410+
{
2411+
Type: fleetv1beta1.WorkConditionTypeAvailable,
2412+
Status: metav1.ConditionTrue,
2413+
},
2414+
},
2415+
},
2416+
},
2417+
Conditions: []metav1.Condition{
2418+
{
2419+
Type: fleetv1beta1.WorkConditionTypeApplied,
2420+
Status: metav1.ConditionTrue,
2421+
},
2422+
{
2423+
Type: fleetv1beta1.WorkConditionTypeAvailable,
2424+
Status: metav1.ConditionFalse,
2425+
},
2426+
},
2427+
},
2428+
},
2429+
"work2": {
2430+
Status: fleetv1beta1.WorkStatus{
2431+
ManifestConditions: []fleetv1beta1.ManifestCondition{
2432+
{
2433+
Identifier: fleetv1beta1.WorkResourceIdentifier{
2434+
Ordinal: 0,
2435+
Group: "",
2436+
Version: "v1",
2437+
Kind: "ConfigMap",
2438+
Name: "config-name-1",
2439+
Namespace: "config-namespace",
2440+
},
2441+
Conditions: []metav1.Condition{
2442+
{
2443+
Type: fleetv1beta1.WorkConditionTypeApplied,
2444+
Status: metav1.ConditionTrue,
2445+
},
2446+
{
2447+
Type: fleetv1beta1.WorkConditionTypeAvailable,
2448+
Status: metav1.ConditionTrue,
2449+
},
2450+
},
2451+
},
2452+
{
2453+
Identifier: fleetv1beta1.WorkResourceIdentifier{
2454+
Ordinal: 1,
2455+
Group: "",
2456+
Version: "v1",
2457+
Kind: "Service",
2458+
Name: "svc-name-1",
2459+
Namespace: "svc-namespace",
2460+
},
2461+
Conditions: []metav1.Condition{
2462+
{
2463+
Type: fleetv1beta1.WorkConditionTypeApplied,
2464+
Status: metav1.ConditionFalse,
2465+
},
2466+
},
2467+
},
2468+
},
2469+
Conditions: []metav1.Condition{
2470+
{
2471+
Type: fleetv1beta1.WorkConditionTypeApplied,
2472+
Status: metav1.ConditionFalse,
2473+
},
2474+
{
2475+
Type: fleetv1beta1.WorkConditionTypeAvailable,
2476+
Status: metav1.ConditionFalse,
2477+
},
2478+
},
2479+
},
2480+
},
2481+
// "work3" was deleted
2482+
},
2483+
workDeleted: true,
2484+
wantFailedResourcePlacements: []fleetv1beta1.FailedResourcePlacement{
2485+
{
2486+
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
2487+
Group: "",
2488+
Version: "v1",
2489+
Kind: "ConfigMap",
2490+
Name: "config-name",
2491+
Namespace: "config-namespace",
2492+
},
2493+
Condition: metav1.Condition{
2494+
Type: fleetv1beta1.WorkConditionTypeAvailable,
2495+
Status: metav1.ConditionFalse,
2496+
},
2497+
},
2498+
{
2499+
ResourceIdentifier: fleetv1beta1.ResourceIdentifier{
2500+
Group: "",
2501+
Version: "v1",
2502+
Kind: "Service",
2503+
Name: "svc-name-1",
2504+
Namespace: "svc-namespace",
2505+
},
2506+
Condition: metav1.Condition{
2507+
Type: fleetv1beta1.WorkConditionTypeApplied,
2508+
Status: metav1.ConditionFalse,
2509+
},
2510+
},
2511+
},
2512+
},
23692513
}
23702514

23712515
originalMaxFailedResourcePlacementLimit := maxFailedResourcePlacementLimit
@@ -2401,7 +2545,7 @@ func TestSetBindingStatus(t *testing.T) {
24012545
ApplyStrategy: tt.applyStrategy,
24022546
},
24032547
}
2404-
setBindingStatus(false, tt.works, binding)
2548+
setBindingStatus(tt.workDeleted, tt.works, binding)
24052549
got := binding.Status.FailedPlacements
24062550
// setBindingStatus is using map to populate the placements.
24072551
// There is no default order in traversing the map.

0 commit comments

Comments
 (0)