Skip to content

Commit ba04837

Browse files
RottenRatipaqsa
andauthored
chore: prefix object patches (#91)
Signed-off-by: Sinelnikov Michail <mikhail.sinelnikov@flant.com> Signed-off-by: Stepan Paksashvili <stepan.paksashvili@flant.com> Co-authored-by: Stepan Paksashvili <stepan.paksashvili@flant.com>
1 parent 4a3d83e commit ba04837

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

internal/objectpatch/patch.go

Lines changed: 19 additions & 0 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,6 +28,24 @@ func (p *Patch) Description() string {
2728
return fmt.Sprintf("%v", op)
2829
}
2930

31+
// SetObjectPrefix sets prefix for object name.
32+
func (p *Patch) SetObjectPrefix(prefix string) {
33+
if p.patchValues == nil {
34+
return
35+
}
36+
37+
name, ok := p.patchValues["name"]
38+
if !ok {
39+
return
40+
}
41+
42+
if strings.HasPrefix(name.(string), prefix+"-") {
43+
return
44+
}
45+
46+
p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, name.(string))
47+
}
48+
3049
// WithSubresource sets the subresource to patch (e.g., "status", "scale").
3150
func (p *Patch) WithSubresource(subresource string) {
3251
p.patchValues["subresource"] = subresource

pkg/patch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type NamespacedPatchCollector interface {
9393
// - filterOperation to modify object via Get-filter-Update process
9494
type PatchCollectorOperation interface {
9595
Description() string
96+
SetObjectPrefix(prefix string)
9697
}
9798

9899
type PatchCollectorOption interface {

0 commit comments

Comments
 (0)