Skip to content
Draft
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
42 changes: 42 additions & 0 deletions internal/objectpatch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,48 @@ func (p *Patch) Description() string {
return fmt.Sprintf("%v", op)
}

// GetName returns the name of the object to patch.
func (p *Patch) GetName() string {
name, ok := p.patchValues["name"]
if !ok {
return ""
}

// Handle both string and typed names
return fmt.Sprintf("%v", name)
}

// GetNamespace returns the namespace of the object to patch.
func (p *Patch) GetNamespace() string {
ns, ok := p.patchValues["namespace"]
if !ok {
return ""
}

// Handle both string and typed namespaces
return fmt.Sprintf("%v", ns)
}

// SetPrifixName sets the name for the patch operation with a prefix.
func (p *Patch) SetNamePrefix(prefix string) {
// Set the name for the patch operation with a prefix.
// This is used to identify the target object in Kubernetes.
if p.patchValues == nil {
p.patchValues = make(map[string]any)
}
p.patchValues["name"] = fmt.Sprintf("%s-%s", prefix, p.GetName())
}

// SetName sets the name for the patch operation.
func (p *Patch) SetName(name string) {
// Set the name for the patch operation.
// This is used to identify the target object in Kubernetes.
if p.patchValues == nil {
p.patchValues = make(map[string]any)
}
p.patchValues["name"] = name
}

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

type PatchCollectorOption interface {
Expand Down