Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions internal/objectpatch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package objectpatch

import (
"fmt"
"strings"

"github.com/deckhouse/module-sdk/pkg"
)
Expand All @@ -27,6 +28,24 @@ func (p *Patch) Description() string {
return fmt.Sprintf("%v", op)
}

// SetObjectPrefix sets prefix for object name.
func (p *Patch) SetObjectPrefix(prefix string) {
if p.patchValues == nil {
return
}

name, ok := p.patchValues["name"]
if !ok {
return
}

if strings.HasPrefix(name.(string), prefix+"-") {
return
}

p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, name.(string))
}

// WithSubresource sets the subresource to patch (e.g., "status", "scale").
func (p *Patch) WithSubresource(subresource string) {
p.patchValues["subresource"] = subresource
Expand Down
1 change: 1 addition & 0 deletions pkg/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type NamespacedPatchCollector interface {
// - filterOperation to modify object via Get-filter-Update process
type PatchCollectorOperation interface {
Description() string
SetObjectPrefix(prefix string)
}

type PatchCollectorOption interface {
Expand Down