Skip to content

distinguish unset and empty values for storageClassName #2600

Closed

Description

@bryanlarsen

In a Kubernetes 1.6 PVC, storageClassName has different behaviour when passed an empty string versus not specified. An empty string means disable dynamic provisioning, not specified means use the default provisioner.

Charts should enable this behaviour, but I can't figure out how to make it happen using the go template syntax. go template's if treats the empty string as falsy, and everything i try to use to distinguish an empty string either works the same on an undefined value (len), or crashes (eq nil).

Perhaps this is why Hugo added the 'isset' function. Something like this would likely work if we had isset:

  {{- if (isset .Values.alertmanager.persistentVolume "storageClass") }}
  storageClassName: "{{ .Values.alertmanager.persistentVolume.storageClass }}"
  {{- end }}

Is there any way to do this? If not can we pull in Hugo's isset or some other way to do it?

Activity

  1. seh commented on Jun 21, 2017

    @seh
    Contributor

    While I agree that isset is a nicer solution, one workaround to consider is to honor a sentinel storage class name that's invalid. A valid name must be a DNS subdomain. Following that down into kubernetes/apimachinery, we find the governing regular expression, which is a lowercase letter or digit, followed by any number of lowercase letters, digits, or hyphens, followed by a lowercase letter or digit. In other words, hyphens are only allowed in the middle. Hence, the following are invalid storage class names:

    • -default
    • default-
    • !default

    You can imagine many more. What if you chose one of them and said that that's the value an release uses to choose the default provisioner?

  2. bryanlarsen commented on Jun 21, 2017

    @bryanlarsen
    Author

    That's a very reasonable solution for my own charts, but it's fairly hacky to get adopted as the right way to do things for public charts. I'll try a PR for the prometheus chart using:

    {{- if .Values.alertmanager.persistentVolume.storageClass }}
    {{- if (eq "-" .Values.alertmanager.persistentVolume.storageClass) }}
      storageClassName: ""
    {{- else }}
      storageClassName: "{{ .Values.alertmanager.persistentVolume.storageClass }}"
    {{- end }}
    {{- end }}
    
  3. seh commented on Jun 21, 2017

    @seh
    Contributor

    Yes, Bryan, I wasn't trying to knock your proposed enhancement. I was just trying to help you make progress in the meantime.

  4. thomastaylor312 commented on Jun 23, 2017

    @thomastaylor312
    Contributor

    Thanks for the request here @bryanlarsen. I'll tag it as a feature. If you wanted to submit something for this, please let us know!

  5. added
    help wanted
    on Jun 23, 2017
  6. technosophos commented on Sep 7, 2017

    @technosophos
    Member

    A PR on Sprig would be the best way to do this. I'll be rolling a new Sprig release for the upcoming Helm update.

  7. fejta-bot commented on Jan 4, 2018

    @fejta-bot

    Issues go stale after 90d of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.

    Prevent issues from auto-closing with an /lifecycle frozen comment.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
    /lifecycle stale

  8. thomastaylor312 commented on Jan 9, 2018

    @thomastaylor312
    Contributor

    /remove-lifecycle stale

  9. fejta-bot commented on Apr 9, 2018

    @fejta-bot

    Issues go stale after 90d of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /lifecycle stale

  10. fejta-bot commented on May 9, 2018

    @fejta-bot

    Stale issues rot after 30d of inactivity.
    Mark the issue as fresh with /remove-lifecycle rotten.
    Rotten issues close after an additional 30d of inactivity.

    If this issue is safe to close now please do so with /close.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /lifecycle rotten
    /remove-lifecycle stale

  11. fejta-bot commented on Jun 8, 2018

    @fejta-bot

    Rotten issues close after 30d of inactivity.
    Reopen the issue with /reopen.
    Mark the issue as fresh with /remove-lifecycle rotten.

    Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
    /close

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

    featurehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions