diff --git a/internal/objectpatch/patch.go b/internal/objectpatch/patch.go index 071bfa2..470a986 100644 --- a/internal/objectpatch/patch.go +++ b/internal/objectpatch/patch.go @@ -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 diff --git a/pkg/patch.go b/pkg/patch.go index 2302bec..b57ccbf 100644 --- a/pkg/patch.go +++ b/pkg/patch.go @@ -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 {