@@ -3,6 +3,7 @@ package object_patch
33import (
44 "fmt"
55 "log/slog"
6+ "strings"
67
78 "github.com/deckhouse/deckhouse/pkg/log"
89 sdkpkg "github.com/deckhouse/module-sdk/pkg"
@@ -99,36 +100,20 @@ func (op *createOperation) Description() string {
99100 return fmt .Sprintf ("Create object %s/%s/%s/%s" , u .GetAPIVersion (), u .GetKind (), u .GetNamespace (), u .GetName ())
100101}
101102
102- func (op * createOperation ) GetName () string {
103- u , err := toUnstructured (op .object )
104- if err != nil {
105- return ""
106- }
107- return u .GetName ()
108- }
109-
110- func (op * createOperation ) SetName (name string ) {
103+ // SetObjectPrefix sets prefix for object name.
104+ func (op * createOperation ) SetObjectPrefix (prefix string ) {
111105 u , err := toUnstructured (op .object )
112106 if err != nil {
113107 return
114108 }
115- u .SetName (name )
116- op .object = u
117- }
118109
119- func (op * createOperation ) SetNamePrefix (prefix string ) {
120- name := op .GetName ()
121- if name != "" {
122- op .SetName (prefix + name )
110+ name := u .GetName ()
111+ if strings .HasPrefix (name , prefix ) {
112+ return
123113 }
124- }
125114
126- func (op * createOperation ) GetNamespace () string {
127- u , err := toUnstructured (op .object )
128- if err != nil {
129- return ""
130- }
131- return u .GetNamespace ()
115+ u .SetName (fmt .Sprintf ("%s-%s" , prefix , name ))
116+ op .object = u
132117}
133118
134119func (op * createOperation ) WithSubresource (subresource string ) {
@@ -163,20 +148,13 @@ func (op *deleteOperation) WithSubresource(subresource string) {
163148 op .subresource = subresource
164149}
165150
166- func (op * deleteOperation ) GetName () string {
167- return op .name
168- }
169-
170- func (op * deleteOperation ) SetName (name string ) {
171- op .name = name
172- }
173-
174- func (op * deleteOperation ) SetNamePrefix (prefix string ) {
175- op .name = prefix + op .name
176- }
151+ // SetObjectPrefix sets prefix for object name.
152+ func (op * deleteOperation ) SetObjectPrefix (prefix string ) {
153+ if strings .HasPrefix (op .name , prefix ) {
154+ return
155+ }
177156
178- func (op * deleteOperation ) GetNamespace () string {
179- return op .namespace
157+ op .name = fmt .Sprintf ("%s-%s" , prefix , op .name )
180158}
181159
182160type patchOperation struct {
@@ -198,24 +176,17 @@ type patchOperation struct {
198176 ignoreHookError bool
199177}
200178
201- func (op * patchOperation ) GetName () string {
202- return op .name
203- }
204-
205- func (op * patchOperation ) SetName (name string ) {
206- op .name = name
207- }
208-
209- func (op * patchOperation ) SetNamePrefix (prefix string ) {
210- op .name = prefix + op .name
179+ func (op * patchOperation ) Description () string {
180+ return fmt .Sprintf ("Filter object %s/%s/%s/%s" , op .apiVersion , op .kind , op .namespace , op .name )
211181}
212182
213- func (op * patchOperation ) GetNamespace () string {
214- return op .namespace
215- }
183+ // SetObjectPrefix sets prefix for object name.
184+ func (op * patchOperation ) SetObjectPrefix (prefix string ) {
185+ if strings .HasPrefix (op .name , prefix ) {
186+ return
187+ }
216188
217- func (op * patchOperation ) Description () string {
218- return fmt .Sprintf ("Filter object %s/%s/%s/%s" , op .apiVersion , op .kind , op .namespace , op .name )
189+ op .name = fmt .Sprintf ("%s-%s" , prefix , op .name )
219190}
220191
221192func (op * patchOperation ) hasFilterFn () bool {
0 commit comments