GenerateName like helper function for naming ephemeral resources #295
Labels
enhancement
New feature or request
go
Pull requests that update Go code
good first issue
Good for newcomers
help wanted
Extra attention is needed
Description
In kubestr we create a number of ephemeral resources like Pods, PVCs, etc. that get cleaned up after the command execution. However, while naming these resources in code, developers generally append names of an existing resource to a hardcoded string. To associate the ephemeral resource with the existing resource.
Example
While writing a new command one might have to define a temporary PVC using an existing PVC named
application-persistent-volume-claim
. And if the hardcoded string defined here isephemeral-persistent-volume-claim
the resultant temporary PVC could be namedephemeral-persistent-volume-claim-for-application-persistent-volume-claim
.Problem
This temporary PVC name is
73 characters
long and it is not considered a good practice to havestring
names with more than64 characters
.Proposed Changes
This could be resolved with a helper function that hashes names longer than 64 characters and then replaces the last 5 characters of the 64 character name with the first 5 characters (base 64) of the hash. Developers can then call this helper function to shorten the names of the ephemeral resources they create.
As part of this issue, please also make sure to update the names of ephemeral resources for all existing commands. By calling the new helper function instead of passing a
string
name.The text was updated successfully, but these errors were encountered: