Skip to content

Commit f243782

Browse files
committed
Remove work deletion from spoke, will be moved to hub GC
Signed-off-by: Ben Perry <[email protected]>
1 parent 2d296cf commit f243782

File tree

4 files changed

+7
-92
lines changed

4 files changed

+7
-92
lines changed

pkg/registration/hub/manifests/rbac/managedcluster-work-clusterrole.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ rules:
99
- apiGroups: ["", "events.k8s.io"]
1010
resources: ["events"]
1111
verbs: ["create", "patch", "update"]
12-
# Allow work agent to get/list/watch/update/delete manifestworks
12+
# Allow work agent to get/list/watch/update manifestworks
1313
- apiGroups: ["work.open-cluster-management.io"]
1414
resources: ["manifestworks"]
15-
verbs: ["get", "list", "watch", "update", "patch", "delete"]
15+
verbs: ["get", "list", "watch", "update", "patch"]
1616
# Allow work agent to update the status of manifestwork
1717
- apiGroups: ["work.open-cluster-management.io"]
1818
resources: ["manifestworks/status"]

pkg/work/spoke/controllers/manifestcontroller/manifestwork_controller.go

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func (m *ManifestWorkController) sync(ctx context.Context, controllerContext fac
136136
}
137137

138138
// work that is completed does not receive any updates
139-
if isComplete, err := m.manifestWorkCompletion(ctx, controllerContext, manifestWork); isComplete || err != nil {
140-
return err
139+
if meta.IsStatusConditionTrue(manifestWork.Status.Conditions, workapiv1.WorkComplete) {
140+
return nil
141141
}
142142

143143
// Apply appliedManifestWork
@@ -215,45 +215,3 @@ func (m *ManifestWorkController) applyAppliedManifestWork(ctx context.Context, w
215215
_, err = m.appliedManifestWorkPatcher.PatchSpec(ctx, appliedManifestWork, requiredAppliedWork.Spec, appliedManifestWork.Spec)
216216
return appliedManifestWork, err
217217
}
218-
219-
func (m *ManifestWorkController) manifestWorkCompletion(
220-
ctx context.Context, controllerContext factory.SyncContext, manifestWork *workapiv1.ManifestWork,
221-
) (bool, error) {
222-
complete := meta.FindStatusCondition(manifestWork.Status.Conditions, workapiv1.WorkComplete)
223-
if complete != nil && complete.Status == metav1.ConditionTrue {
224-
var err error
225-
// check if work has TTL set and it has elapsed since completion
226-
if ttl, ok := remainingTtl(complete.LastTransitionTime, manifestWork.Spec.DeleteOption); ok {
227-
if ttl <= 0 {
228-
// Only delete if resourceVersion matches in case complete condition has changed
229-
deleteOpts := metav1.DeleteOptions{Preconditions: &metav1.Preconditions{ResourceVersion: &manifestWork.ResourceVersion}}
230-
err = m.manifestWorkClient.Delete(ctx, manifestWork.Name, deleteOpts)
231-
if err == nil {
232-
controllerContext.Recorder().Eventf(
233-
"ManifestWorkDeleted", "Deleted ManifestWork %s because its TTL elapsed after completion", manifestWork.Name,
234-
)
235-
}
236-
} else {
237-
// Requeue after TTL to delete the manifestwork
238-
controllerContext.Queue().AddAfter(manifestWork.Name, ttl)
239-
}
240-
}
241-
return true, err
242-
}
243-
return false, nil
244-
}
245-
246-
// remainingTtl returns the remaining duration before a completed manifestwork should be deleted, if configured
247-
func remainingTtl(completedAt metav1.Time, deleteOption *workapiv1.DeleteOption) (time.Duration, bool) {
248-
if deleteOption == nil || deleteOption.TTLSecondsAfterFinished == nil {
249-
return 0, false
250-
}
251-
252-
ttl := *deleteOption.TTLSecondsAfterFinished
253-
if ttl <= 0 {
254-
return 0, true
255-
}
256-
257-
remaining := time.Second*time.Duration(ttl) - time.Since(completedAt.Time)
258-
return remaining, true
259-
}

pkg/work/spoke/controllers/manifestcontroller/manifestwork_reconciler_test.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
fakedynamic "k8s.io/client-go/dynamic/fake"
2020
fakekube "k8s.io/client-go/kubernetes/fake"
2121
clienttesting "k8s.io/client-go/testing"
22-
"k8s.io/utils/ptr"
2322

2423
fakeworkclient "open-cluster-management.io/api/client/work/clientset/versioned/fake"
2524
workinformers "open-cluster-management.io/api/client/work/informers/externalversions"
@@ -166,11 +165,6 @@ func (t *testCase) withManifestConfig(configs ...workapiv1.ManifestConfigOption)
166165
return t
167166
}
168167

169-
func (t *testCase) withDeleteOption(deleteOption *workapiv1.DeleteOption) *testCase {
170-
t.deleteOption = deleteOption
171-
return t
172-
}
173-
174168
func (t *testCase) withSpokeObject(objects ...runtime.Object) *testCase {
175169
t.spokeObject = objects
176170
return t
@@ -370,33 +364,10 @@ func TestSync(t *testing.T) {
370364
expectedCondition(workapiv1.ManifestApplied, metav1.ConditionTrue),
371365
expectedCondition(workapiv1.ManifestApplied, metav1.ConditionTrue)).
372366
withExpectedWorkCondition(expectedCondition(workapiv1.WorkApplied, metav1.ConditionTrue)),
373-
newTestCase("ignore completed manifestwork with no TTL").
367+
newTestCase("ignore completed manifestwork").
374368
withWorkManifest(testingcommon.NewUnstructured("v1", "Secret", "ns1", "test")).
375369
withSpokeObject(spoketesting.NewSecret("test", "ns1", "value2")).
376370
withExistingWorkCondition(metav1.Condition{Type: workapiv1.WorkComplete, Status: metav1.ConditionTrue}),
377-
newTestCase("ignore completed manifestwork with unsatisfied TTL").
378-
withWorkManifest(testingcommon.NewUnstructured("v1", "Secret", "ns1", "test")).
379-
withSpokeObject(spoketesting.NewSecret("test", "ns1", "value2")).
380-
withDeleteOption(&workapiv1.DeleteOption{TTLSecondsAfterFinished: ptr.To[int64](30)}).
381-
withExistingWorkCondition(
382-
metav1.Condition{
383-
Type: workapiv1.WorkComplete,
384-
Status: metav1.ConditionTrue,
385-
LastTransitionTime: metav1.NewTime(time.Now().Add(-1 * time.Second)),
386-
},
387-
),
388-
newTestCase("delete completed manifestwork with satisfied TTL").
389-
withWorkManifest(testingcommon.NewUnstructured("v1", "Secret", "ns1", "test")).
390-
withSpokeObject(spoketesting.NewSecret("test", "ns1", "value2")).
391-
withDeleteOption(&workapiv1.DeleteOption{TTLSecondsAfterFinished: ptr.To[int64](10)}).
392-
withExistingWorkCondition(
393-
metav1.Condition{
394-
Type: workapiv1.WorkComplete,
395-
Status: metav1.ConditionTrue,
396-
LastTransitionTime: metav1.NewTime(time.Now().Add(-11 * time.Second)),
397-
},
398-
).
399-
withExpectedWorkAction("delete"),
400371
}
401372

402373
for _, c := range cases {

test/integration/work/work_test.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"k8s.io/apimachinery/pkg/util/rand"
1818
"k8s.io/client-go/dynamic"
1919
"k8s.io/client-go/util/retry"
20-
"k8s.io/utils/ptr"
2120

2221
workapiv1 "open-cluster-management.io/api/work/v1"
2322
"open-cluster-management.io/sdk-go/pkg/cloudevents/clients/common"
@@ -879,17 +878,13 @@ var _ = ginkgo.Describe("ManifestWork", func() {
879878
})
880879
})
881880

882-
ginkgo.Context("With completion TTL", func() {
881+
ginkgo.Context("Work completion", func() {
883882
ginkgo.BeforeEach(func() {
884883
manifests = []workapiv1.Manifest{
885884
util.ToManifest(util.NewConfigmap(commOptions.SpokeClusterName, cm1, map[string]string{"a": "b"}, nil)),
886885
util.ToManifest(util.NewConfigmap(commOptions.SpokeClusterName, cm2, map[string]string{"c": "d"}, nil)),
887886
}
888887
workOpts = append(workOpts, func(work *workapiv1.ManifestWork) {
889-
work.Spec.DeleteOption = &workapiv1.DeleteOption{
890-
TTLSecondsAfterFinished: ptr.To[int64](min(5, eventuallyTimeout/2)),
891-
PropagationPolicy: "Foreground",
892-
}
893888
work.Spec.ManifestConfigs = []workapiv1.ManifestConfigOption{
894889
{
895890
ResourceIdentifier: workapiv1.ResourceIdentifier{
@@ -937,29 +932,20 @@ var _ = ginkgo.Describe("ManifestWork", func() {
937932
context.Background(), updatedWork.Name, types.MergePatchType, pathBytes, metav1.PatchOptions{})
938933
gomega.Expect(err).ToNot(gomega.HaveOccurred())
939934

940-
// ManifestWork should be marked completed and eventually be deleted
935+
// ManifestWork should be marked completed
941936
gomega.Eventually(func() error {
942937
work, err := hubWorkClient.WorkV1().ManifestWorks(commOptions.SpokeClusterName).Get(context.Background(), work.Name, metav1.GetOptions{})
943938
if err != nil {
944-
if errors.IsNotFound(err) {
945-
return nil
946-
}
947939
return err
948940
}
949941

950-
// If ManifestWork still exists we expect it to be marked complete
951942
if err := util.CheckExpectedConditions(work.Status.Conditions, metav1.Condition{
952943
Type: workapiv1.WorkComplete,
953944
Status: metav1.ConditionTrue,
954945
Reason: "ConditionRulesAggregated",
955946
}); err != nil {
956947
return fmt.Errorf("%s: %v", work.Name, err)
957948
}
958-
959-
// If marked complete and still exists, we expect deletion timestamp to be set
960-
if work.DeletionTimestamp.IsZero() {
961-
return fmt.Errorf("Expected work %s to be deleted", work.Name)
962-
}
963949
return nil
964950
}, eventuallyTimeout, eventuallyInterval).Should(gomega.Succeed())
965951
})

0 commit comments

Comments
 (0)