@@ -2,6 +2,7 @@ package objectpatch
22
33import (
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").
0 commit comments