kpt icon indicating copy to clipboard operation
kpt copied to clipboard

KRM function "ensure-name-substring" should have a parameter "delimiter"

Open isihu opened this issue 1 year ago • 0 comments

Describe your problem

I want to provide a kpt package for my users. I use this function to ensure consistent naming across the resources of the package. In my kpt package the prefix is set to "example" and added to the resources successfully, e.g. "example-deployment".

When a user clones the kpt package and changes the prefix to "myservice", the name of the deployment becomes "myservice-example-deployment" while I want the name to be "myservice-deployment"

Potential solution

I can provide a delimiter to the functionConfig, like "-". Then the function behaves as follows:

if delimiter in original_resource_name:
  # replace the previous prefix with the new one
  new_resource_name = prefix + delimiter + original_resource_name.split(delimiter, 1)[1] 
else:
  # current behavior
  new_resource_name = prefix + delimiter + original_resource_name 

isihu avatar Apr 03 '24 14:04 isihu