From c979c146c589fdf0c39ef0b7c237fbd898641cb1 Mon Sep 17 00:00:00 2001 From: Sinelnikov Michail Date: Wed, 4 Feb 2026 16:07:53 +0300 Subject: [PATCH 1/4] update interface Signed-off-by: Sinelnikov Michail --- pkg/patch.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/patch.go b/pkg/patch.go index 2302bec..b57ccbf 100644 --- a/pkg/patch.go +++ b/pkg/patch.go @@ -93,6 +93,10 @@ type NamespacedPatchCollector interface { // - filterOperation to modify object via Get-filter-Update process type PatchCollectorOperation interface { Description() string + GetName() string + SetName(name string) + SetNamePrefix(prefix string) + GetNamespace() string } type PatchCollectorOption interface { From 462f9f8f6020fabe5259365f11bb34432760ea6e Mon Sep 17 00:00:00 2001 From: Sinelnikov Michail Date: Wed, 4 Feb 2026 16:27:53 +0300 Subject: [PATCH 2/4] fix Signed-off-by: Sinelnikov Michail --- internal/objectpatch/patch.go | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/internal/objectpatch/patch.go b/internal/objectpatch/patch.go index 071bfa2..67327e3 100644 --- a/internal/objectpatch/patch.go +++ b/internal/objectpatch/patch.go @@ -27,6 +27,48 @@ func (p *Patch) Description() string { return fmt.Sprintf("%v", op) } +// GetName returns the name of the object to patch. +func (p *Patch) GetName() string { + name, ok := p.patchValues["name"] + if !ok { + return "" + } + + // Handle both string and typed names + return fmt.Sprintf("%v", name) +} + +// GetNamespace returns the namespace of the object to patch. +func (p *Patch) GetNamespace() string { + ns, ok := p.patchValues["namespace"] + if !ok { + return "" + } + + // Handle both string and typed namespaces + return fmt.Sprintf("%v", ns) +} + +// SetPrifixName sets the name for the patch operation with a prefix. +func (p *Patch) SetNamePrefix(prefix string) { + // Set the name for the patch operation with a prefix. + // This is used to identify the target object in Kubernetes. + if p.patchValues == nil { + p.patchValues = make(map[string]any) + } + p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, p.GetName()) +} + +// SetName sets the name for the patch operation. +func (p *Patch) SetName(name string) { + // Set the name for the patch operation. + // This is used to identify the target object in Kubernetes. + if p.patchValues == nil { + p.patchValues = make(map[string]any) + } + p.patchValues["name"] = p.GetName() +} + // WithSubresource sets the subresource to patch (e.g., "status", "scale"). func (p *Patch) WithSubresource(subresource string) { p.patchValues["subresource"] = subresource From 42dfaf29a5c51386b76bd1d9ef49e47e5ecb09de Mon Sep 17 00:00:00 2001 From: Sinelnikov Michail Date: Mon, 16 Feb 2026 12:05:41 +0300 Subject: [PATCH 3/4] fix Signed-off-by: Sinelnikov Michail --- internal/objectpatch/patch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/objectpatch/patch.go b/internal/objectpatch/patch.go index 67327e3..470a986 100644 --- a/internal/objectpatch/patch.go +++ b/internal/objectpatch/patch.go @@ -66,7 +66,7 @@ func (p *Patch) SetName(name string) { if p.patchValues == nil { p.patchValues = make(map[string]any) } - p.patchValues["name"] = p.GetName() + p.patchValues["name"] = name } // WithSubresource sets the subresource to patch (e.g., "status", "scale"). From 6b32d34283825a0e162e9ff56e4bf422f9d50cee Mon Sep 17 00:00:00 2001 From: Stepan Paksashvili Date: Wed, 4 Mar 2026 19:06:08 +0300 Subject: [PATCH 4/4] [chore] fix prefix Signed-off-by: Stepan Paksashvili --- internal/objectpatch/patch.go | 43 ++++++++--------------------------- pkg/patch.go | 5 +--- 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/internal/objectpatch/patch.go b/internal/objectpatch/patch.go index 470a986..94768d2 100644 --- a/internal/objectpatch/patch.go +++ b/internal/objectpatch/patch.go @@ -2,6 +2,7 @@ package objectpatch import ( "fmt" + "strings" "github.com/deckhouse/module-sdk/pkg" ) @@ -27,46 +28,22 @@ func (p *Patch) Description() string { return fmt.Sprintf("%v", op) } -// GetName returns the name of the object to patch. -func (p *Patch) GetName() string { - name, ok := p.patchValues["name"] - if !ok { - return "" +// SetObjectPrefix sets prefix for object name. +func (p *Patch) SetObjectPrefix(prefix string) { + if p.patchValues == nil { + return } - // Handle both string and typed names - return fmt.Sprintf("%v", name) -} - -// GetNamespace returns the namespace of the object to patch. -func (p *Patch) GetNamespace() string { - ns, ok := p.patchValues["namespace"] + name, ok := p.patchValues["name"] if !ok { - return "" + return } - // Handle both string and typed namespaces - return fmt.Sprintf("%v", ns) -} - -// SetPrifixName sets the name for the patch operation with a prefix. -func (p *Patch) SetNamePrefix(prefix string) { - // Set the name for the patch operation with a prefix. - // This is used to identify the target object in Kubernetes. - if p.patchValues == nil { - p.patchValues = make(map[string]any) + if strings.HasPrefix(name.(string), prefix+"-") { + return } - p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, p.GetName()) -} -// SetName sets the name for the patch operation. -func (p *Patch) SetName(name string) { - // Set the name for the patch operation. - // This is used to identify the target object in Kubernetes. - if p.patchValues == nil { - p.patchValues = make(map[string]any) - } - p.patchValues["name"] = name + p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, name.(string)) } // WithSubresource sets the subresource to patch (e.g., "status", "scale"). diff --git a/pkg/patch.go b/pkg/patch.go index b57ccbf..3372e33 100644 --- a/pkg/patch.go +++ b/pkg/patch.go @@ -93,10 +93,7 @@ type NamespacedPatchCollector interface { // - filterOperation to modify object via Get-filter-Update process type PatchCollectorOperation interface { Description() string - GetName() string - SetName(name string) - SetNamePrefix(prefix string) - GetNamespace() string + SetObjectPrefix(prefix string) } type PatchCollectorOption interface {