Skip to content

Commit 6b32d34

Browse files
committed
[chore] fix prefix
Signed-off-by: Stepan Paksashvili <stepan.paksashvili@flant.com>
1 parent 42dfaf2 commit 6b32d34

2 files changed

Lines changed: 11 additions & 37 deletions

File tree

internal/objectpatch/patch.go

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package objectpatch
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/deckhouse/module-sdk/pkg"
78
)
@@ -27,46 +28,22 @@ func (p *Patch) Description() string {
2728
return fmt.Sprintf("%v", op)
2829
}
2930

30-
// GetName returns the name of the object to patch.
31-
func (p *Patch) GetName() string {
32-
name, ok := p.patchValues["name"]
33-
if !ok {
34-
return ""
31+
// SetObjectPrefix sets prefix for object name.
32+
func (p *Patch) SetObjectPrefix(prefix string) {
33+
if p.patchValues == nil {
34+
return
3535
}
3636

37-
// Handle both string and typed names
38-
return fmt.Sprintf("%v", name)
39-
}
40-
41-
// GetNamespace returns the namespace of the object to patch.
42-
func (p *Patch) GetNamespace() string {
43-
ns, ok := p.patchValues["namespace"]
37+
name, ok := p.patchValues["name"]
4438
if !ok {
45-
return ""
39+
return
4640
}
4741

48-
// Handle both string and typed namespaces
49-
return fmt.Sprintf("%v", ns)
50-
}
51-
52-
// SetPrifixName sets the name for the patch operation with a prefix.
53-
func (p *Patch) SetNamePrefix(prefix string) {
54-
// Set the name for the patch operation with a prefix.
55-
// This is used to identify the target object in Kubernetes.
56-
if p.patchValues == nil {
57-
p.patchValues = make(map[string]any)
42+
if strings.HasPrefix(name.(string), prefix+"-") {
43+
return
5844
}
59-
p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, p.GetName())
60-
}
6145

62-
// SetName sets the name for the patch operation.
63-
func (p *Patch) SetName(name string) {
64-
// Set the name for the patch operation.
65-
// This is used to identify the target object in Kubernetes.
66-
if p.patchValues == nil {
67-
p.patchValues = make(map[string]any)
68-
}
69-
p.patchValues["name"] = name
46+
p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, name.(string))
7047
}
7148

7249
// WithSubresource sets the subresource to patch (e.g., "status", "scale").

pkg/patch.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ type NamespacedPatchCollector interface {
9393
// - filterOperation to modify object via Get-filter-Update process
9494
type PatchCollectorOperation interface {
9595
Description() string
96-
GetName() string
97-
SetName(name string)
98-
SetNamePrefix(prefix string)
99-
GetNamespace() string
96+
SetObjectPrefix(prefix string)
10097
}
10198

10299
type PatchCollectorOption interface {

0 commit comments

Comments
 (0)