From 119428561e31b07e81a02fe53574847da60dee66 Mon Sep 17 00:00:00 2001 From: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com> Date: Tue, 23 Apr 2024 00:05:45 +0530 Subject: [PATCH] Allow custom wait rules for kc resources Signed-off-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com> --- pkg/kapp/clusterapply/converged_resource_factory.go | 8 +++++--- pkg/kapp/resourcesmisc/custom_waiting_resource.go | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/kapp/clusterapply/converged_resource_factory.go b/pkg/kapp/clusterapply/converged_resource_factory.go index 775610d41..0c72a52a9 100644 --- a/pkg/kapp/clusterapply/converged_resource_factory.go +++ b/pkg/kapp/clusterapply/converged_resource_factory.go @@ -28,6 +28,10 @@ func (f ConvergedResourceFactory) New(res ctlres.Resource, associatedRsFunc func(ctlres.Resource, []ctlres.ResourceRef) ([]ctlres.Resource, error)) ConvergedResource { specificResFactories := []SpecificResFactory{ + // custom waiting resource waiter deals with reconciliation _and_ deletion + func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) { + return ctlresm.NewCustomWaitingResource(res, f.waitRules), nil + }, // kapp-controller app resource waiter deals with reconciliation _and_ deletion func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) { return ctlresm.NewKappctrlK14sIoV1alpha1App(res), nil @@ -38,14 +42,12 @@ func (f ConvergedResourceFactory) New(res ctlres.Resource, func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) { return ctlresm.NewPackagingCarvelDevV1alpha1PackageRepo(res), nil }, + // Deal with deletion generically since below resource waiters do not not know about that // TODO shoud we make all of them deal with deletion internally? func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) { return ctlresm.NewDeleting(res), nil }, - func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) { - return ctlresm.NewCustomWaitingResource(res, f.waitRules), nil - }, func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) { return ctlresm.NewAPIExtensionsVxCRD(res), nil }, diff --git a/pkg/kapp/resourcesmisc/custom_waiting_resource.go b/pkg/kapp/resourcesmisc/custom_waiting_resource.go index 1fcc3f795..473d5c292 100644 --- a/pkg/kapp/resourcesmisc/custom_waiting_resource.go +++ b/pkg/kapp/resourcesmisc/custom_waiting_resource.go @@ -42,6 +42,11 @@ type customWaitingResourceCondition struct { } func (s CustomWaitingResource) IsDoneApplying() DoneApplyState { + deletingRes := NewDeleting(s.resource) + if deletingRes != nil { + return deletingRes.IsDoneApplying() + } + obj := customWaitingResourceStruct{} err := s.resource.AsUncheckedTypedObj(&obj)