From 39709638e9ead04de8271a8e22fad8e79d272899 Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Tue, 2 Jul 2024 19:07:19 -0700 Subject: [PATCH 1/2] feat: Enable server-side-apply on direct applier This will fix the "annotation too long" problem when the managed manifests are too large. --- pkg/patterns/declarative/pkg/applier/direct.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/patterns/declarative/pkg/applier/direct.go b/pkg/patterns/declarative/pkg/applier/direct.go index 95d58c87..dfe46a67 100644 --- a/pkg/patterns/declarative/pkg/applier/direct.go +++ b/pkg/patterns/declarative/pkg/applier/direct.go @@ -170,6 +170,7 @@ func (d *DirectApplier) Apply(ctx context.Context, opt ApplierOptions) error { applyOpts.PruneResources = append(applyOpts.PruneResources, r...) } + applyOpts.ServerSideApply = true applyOpts.ForceConflicts = opt.Force applyOpts.Namespace = opt.Namespace applyOpts.SetObjects(infos) From cdfac9605903c16ed0f8e1c6a37fa910d70fa192 Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Fri, 6 Sep 2024 18:11:12 +0000 Subject: [PATCH 2/2] change direct-applier ssa as an option --- pkg/patterns/declarative/pkg/applier/direct.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/patterns/declarative/pkg/applier/direct.go b/pkg/patterns/declarative/pkg/applier/direct.go index dfe46a67..52a0e230 100644 --- a/pkg/patterns/declarative/pkg/applier/direct.go +++ b/pkg/patterns/declarative/pkg/applier/direct.go @@ -27,13 +27,20 @@ import ( ) type DirectApplier struct { - inner directApplierSite + // Whether to apply the KRM resources using server-side apply. https://kubernetes.io/docs/reference/using-api/server-side-apply/ + // Note: The server-side apply is stable in Kubernetes v1.22, users should take the responsibility to make sure the cluster + // server can support this feature. + serverSideApplyPreferred bool + inner directApplierSite +} + +func (d *DirectApplier) UseServerSideApply() { + d.serverSideApplyPreferred = true } var _ Applier = &DirectApplier{} -type directApplier struct { -} +type directApplier struct{} type directApplierSite interface { Run(a *apply.ApplyOptions) error @@ -170,7 +177,7 @@ func (d *DirectApplier) Apply(ctx context.Context, opt ApplierOptions) error { applyOpts.PruneResources = append(applyOpts.PruneResources, r...) } - applyOpts.ServerSideApply = true + applyOpts.ServerSideApply = d.serverSideApplyPreferred applyOpts.ForceConflicts = opt.Force applyOpts.Namespace = opt.Namespace applyOpts.SetObjects(infos)