Skip to content

Issues with using helm generated names in resource name with truncation #1071

Closed

Description

@prydonius

I just ran into an issue where I failed to install a chart that was using the name of the release to construct a name for the service:

metadata:
 name: "{{ printf "%s-%s" .Release.Name .Values.Zeppelin.Name | trunc 24 }}"

Due to the truncation (see https://github.com/kubernetes/helm/blob/master/docs/examples/nginx/templates/_helpers.tpl#L10), the name that got constructed was inclined-prawn-zeppelin- (.Values.Zeppelin.Name is zeppelin-controller). Kubernetes failed to validate the chart and returned this error:

Invalid value: "inclined-prawn-zeppelin-": must match the regex [a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)* (e.g. 'example.com')

Is there anything we can do differently to prevent this issue from occasionally happening?

Activity

  1. technosophos commented on Aug 18, 2016

    @technosophos
    Member

    I am wondering if we should just decide on a safe naming convention and compute it prior to rendering templates. Then we could just expose something like Release.Id, Chart.Id, or Template.Id that would meet the Kubernetes restrictions.

    One idea would be to simply compute a hash of the chart path relative to root, and then append that to a release name. Pseudo-code would be something like:

    Chart.Id = Truncate(Release.Name, 17) + "-" + Truncate(SHASum(chartpath), 6)
    

    So Chart.Id would be something like fluffy-panda-aa56c8.

    Since we'd compute against the path to the chart, subcharts could even have duplicate names, but still have unique Chart.Id. Yet Chart.Id would be stable over upgrades.

    In a template, this would just be referenced via the {{.Chart.Id}} computed value.

  2. prydonius commented on Aug 19, 2016

    @prydonius
    MemberAuthor

    Correct me if I'm wrong, but this would mean that multiple of a resource type in the same (parent) chart won't both be able to use {{.Chart.Id}} as the name. This would be an issue if, for example, you had a MariaDB cluster chart with a master and slave service.

    The other (perhaps smaller) issue with this is you lose visibility into what the service is. If my MariaDB deployment is called fluffy-panda-aa56c8, I'll need to run helm list to realise that fluffy-panda is a MariaDB chart.

    What we could do, is truncate the release name so that we always have a deterministic length, and leave enough space for the chart developer to extend the name. So, for example, document that {{.Release.Name}} will always have (at-most) length 14 (n), so the chart developer can extend with 10 (24-n) characters reliably.

    The issue with truncating the release name is that it will be harder to associate it with the actual release, so ideally we can force the moniker to abide by the maximum length. Is that possible?

  3. technosophos commented on Aug 19, 2016

    @technosophos
    Member

    I think we could enforce a max length on the .Release.Name. Lemme give that a try really quickly.

  4. technosophos commented on Aug 19, 2016

    @technosophos
    Member

    Oh... hit a snag. Does that mean I need to enforce a limit on the length of the -n flag for install? That won't be a popular decision, but I can do it.

  5. prydonius commented on Aug 19, 2016

    @prydonius
    MemberAuthor

    Oh yes, there will need to be a limit on custom release names too. I guess as long the maximum length is long enough to minimise a 'release name too long' error, it might be okay? I'm not sure what the ideal length should be though.

    Some examples of service names:

    • mariadb-master 15
    • zeppelin-controller 20 (could be shortened to zeppelin-ctrl 14)
  6. technosophos commented on Aug 19, 2016

    @technosophos
    Member

    Alright, the PR on #1080 limits the release name to 14. It doesn't totally fix the original issue, though, since a release name could accidentally end in -. I will do a separate PR to address that particular fact by providing the trimSuffix function to templates. That way, at least there is a way to run a sanitizing trunc 24 | trimSuffix "-" sequence.

  7. added a commit that references this issue on Aug 19, 2016
    202238d
  8. prydonius commented on Aug 19, 2016

    @prydonius
    MemberAuthor

    Given the examples above, I'm wondering if 14 is too big for the release name?

  9. prydonius commented on Aug 19, 2016

    @prydonius
    MemberAuthor

    Also, wondering if we can add a lint rule to check the reliability of the generated names. A simple check would be to ensure that the length of the generated template name when .Release.Name = "" is <= 10 (in the case where the max for the release name is 14), as this would ensure that the whole name will never be cut off.

  10. technosophos commented on Aug 19, 2016

    @technosophos
    Member

    Oops... #1081 shouldn't really have closed this. Sorry.

  11. technosophos commented on Aug 22, 2016

    @technosophos
    Member

    Okay, so the merged version has 14 as the length. We can shorten later if we need. I'd still be interested in exploring some generated compact unique names or prefixes. Even something like a truncated hash (a la Git commit hashes) might be useful for some of these name fields.

    I'm marking this issue as closed since both related PRs are merged. If we hit additional problems, we should track in a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions