Skip to content

Enhance Helm chart and apply best practices - #229

Merged
jetstack-ci-bot merged 4 commits into
cert-manager:masterfrom
unguiculus:feature/chart-update
Jan 16, 2018
Merged

jetstack-ci-bot merged 4 commits into
cert-manager:masterfrom
unguiculus:feature/chart-update

Conversation

@unguiculus

@unguiculus unguiculus commented Dec 19, 2017 •

Copy link
Copy Markdown
Contributor
action required: Enhance Helm chart in-line with best practices. This may require a change to your values.yaml files/--set flags.

@jetstack-bot jetstack-bot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 19, 2017
@jetstack-bot

Copy link
Copy Markdown
Contributor

Hi @unguiculus. Thanks for your PR.

I'm waiting for a jetstack member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@unguiculus

Copy link
Copy Markdown
Contributor Author

Do you have any plans to move the chart to kubernetes/charts? I could create a PR over there or help you get it in quickly if you like (I'm a charts maintainer).

I have some questions:

  • What's the deal with the parameter createCustomResource? Why would you want to not create the CRDs/TPRs? Also, I think the naming is not ideal because it also refers to TPRs.
  • What K8s versions is cert-manager compatible with? Do we still have to keep the TPRs in the chart? I'm asking because over at the charts repo we have a policy to officially support the current and previous minor versions of K8s. Of course, a chart owner may extend these minimal requirements.
  • I noticed there is no cluster issuer configured using TPRs. Is this not possible with TPRs? Otherwise we should probably add it.

@munnerz

munnerz commented Dec 19, 2017

Copy link
Copy Markdown
Member

Hey - thanks for the work on this! Awesome to see.

So to answer your questions:

  1. I have provided an option to not do this automatically in case the user doesn't have permission to create CRDs/TPRs, or if a user is deploying cert-manager multiple times (I think @mikebryant had previously expressed the need to run cert-manager on a per-namespace basis as opposed to a single cluster wide cert-manager - I wonder if this is something you still require/use Mike?)

  2. I'd like to support as far back as possible really - I think 1.6 is what we have previously aimed to support, and I intend to get e2e tests up and running for 1.6 at some point too. This will obviously change, and I'd imagine by 1.10 I'll be dropping support for 1.6, so I think we aim to support one more k8s version than the charts repo dictates 😄

  3. No it's not possible - we can't have Cluster scoped resources with ThirdPartyResources (it's just not supported). Right now however we have a problem where cert-manager will attempt to watch ClusterIssuer resources regardless, thus causing it to not function properly on 1.6 clusters (see Cert-manager fail on 1.6 clusters #201).

Regarding moving to kubernetes/charts - yes I've been planning on doing it any day now, but need(ed) to clean up the chart first. Once this is cleaned up and up to date, I think we can go ahead and PR it upstream. I'll then update this repo to point to kubernetes/charts for the helm chart.

I'll follow up with a review on this PR shortly 😄

Comment thread contrib/charts/cert-manager/Chart.yaml Outdated
apiVersion: v1
description: A Helm chart for Kubernetes
name: cert-manager
version: 0.1.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although we've not properly bumped versions for the chart previously, we definitely should (#223). Maybe this should be 0.2.0? We have made a breaking change to the values.yaml file.

@@ -1,36 +1,41 @@
apiVersion: extensions/v1beta1
apiVersion: apps/v1beta1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may need another switch here to check if apps/v1beta1 exists before we try and create a resource (in order to support 1.6 deployments)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:
serviceAccount: {{ template "fullname" . }}
serviceAccountName: {{ template "fullname" . }}
serviceAccountName: {{ if .Values.rbac.create }}{{ template "cert-manager.fullname" . }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace "{{ .Values.rbac.serviceAccountName }}" with {{ .Values.rbac.serviceAccountName | quote }}?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternatively move the quotes to the outside of the if/else/end block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, kinda looks ugly.

cpu: 10m
memory: 32Mi

nodeSelector: {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't used in the actual templates from what I can see

@unguiculus unguiculus Dec 19, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. I was actually there before. That's why you don't see it in the diff. I just added the empty default to values.yaml.

Comment thread contrib/charts/cert-manager/values.yaml Outdated

# Optional additional arguments
extraArgs: []
# - --cluster-resource-namespace=ingress

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change 'ingress' to 'kube-system'? That is currently our default for this field, and introducing 'new' namespaces could cause confusion 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was meant as an example. Wouldn't you only set this if you want a different namespace? Maybe we should add a comment making that clear?

Comment thread contrib/charts/cert-manager/values.yaml Outdated
rbac:
enabled: true
create: true
serviceAccountName: default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure on best practice here, but are we better off setting this to empty (i.e. whole line commented out) and using the default function within the templates instead to set it to 'default' if not set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is our best practice in the charts repo. We require new charts to do it like this. I think it makes sense. It's always better to have a default in values.yaml, if just for the sake of documentation. The default function should only be used if its not possible to add defaults to values.yaml.

@whereisaaron whereisaaron Jan 4, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unguiculus isn't it better to create a new ServiceAccount for {{ template "cert-manager.fullname" . }} by default rather than apply extra permissions to the default ServiceAccount. The is potentially a permission leak risk to other pods in the same namespace. Hence this should be blank as @munnerz suggests and default to the 'fullname' in the template.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whereisaaron This is actually what happens. If rbac.create=true a new servive account {{ template "cert-manager.fullname" . }} is created that gets all the permissions. If you don't use RBAC or want to manage RBAC resources outside the chart, set rbac.create=false. Then by default, the default service acount is used which is fine if you don't use RBAC. You may specify another service account with rbac.serviceAccountName. As mentioned in the readme, rbac.serviceAccountName is ignored if rbac.create=false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation @unguiculus, according to the Helm best practices documentation rbac.serviceAccountName must not be ignored. Chart authors are supposed to also support the situation where the user has externally managed RBAC resources. For example, let's say in my cluster I have created a Service Account 'foo' associated with the required RBAC roles for cert-manager. I should be able to deploy the chart with:

rbac.create=false
rbac.serviceAccountName="foo"

In this case the chart should not create RBAC resources (Roles etc.), but the Pod resources must be associated with the "foo" Service Account.

https://docs.helm.sh/chart_best_practices/#using-rbac-resources

rbac.serviceAccountName should set the name of the ServiceAccount to be used by access-controlled resources created by the chart. If rbac.create is true, then a ServiceAccount with this name should be created. If rbac.create is false, then it should not be created, but it should still be associated with the same resources so that manually-created RBAC resources created later that reference it will function correctly. (Note that this effectively makes rbac.serviceAccountName a required value in these charts.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I think I agree with @whereisaaron on this one - rbac and serviceAccounts are separate things and it does confuse things when they are conflated. Right now, if rbac.create=true and rbac.serviceAccountName=foo, I would expect no RBAC resources to be created and a service account named foo to not be created and instead used as the serviceAccountName on pods. Namely because I see create as a sort of toggle for the entire block (akin to enabled).

Splitting these two concepts out in the YAML does make this far clearer and disambiguates the two, and with sane defaults the UX is preserved (i.e. rbac.create=true/false behaves in a similar fashion to the current best practices).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, I am keen to follow whatever is decided as best practice. This discussion is basically the blocker for merge now.

From what I can see, if this is accepted #232 can be closed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid automatically associating chart-created resources with the default service account as a best practice (basically defaulting to more secure rather than less). It makes it hard to grant permissions to things without granting them to a whole hodgepodge of other things that don't need them. If people want the default service account to be used, they should specify it explicitly.

I guess the remaining question is, is it worth adding the complexity of a new top-level key for service accounts to cover the case of "create RBAC resources that use an existing service account"? Pro: My inner control-freak sysadmin says "yes, that's exactly what you'd do", and it allows creating and using multiple service accounts in a chart. Con: it introduces new failure surface for syntax errors in the values file.

I'll start a discussion over in the Helm project and reference this thread, since this is really a "Helm chart best practices" discussion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omkensey Let's discuss this in the next charts call.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd add a layer of key-value abstraction to support multiple service accounts, e.g.:

serviceAccounts:
  client:
    serviceAccountName: client-account
    create: false
  server:
    serviceAccountName: server-account
    create: true

@munnerz munnerz removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 19, 2017
@mikebryant

Copy link
Copy Markdown
Member

@munnerz Not for us - we just want one global one per cluster.

@unguiculus

Copy link
Copy Markdown
Contributor Author

I updated RBAC as discussed in this week's charts call and based on @omkensey's proposal (helm/helm#3320).

@jetstack-ci-bot

Copy link
Copy Markdown
Contributor

@unguiculus PR needs rebase

@jetstack-ci-bot jetstack-ci-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 15, 2018
@jetstack-bot jetstack-bot added release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jan 15, 2018
* Update Chart.yaml
* Make templates namespaced
* Update config table in README.md
* Apply best practices for RBAC
  (see
https://github.com/kubernetes/helm/blob/master/docs/chart_best_practices/rbac.md)
* Add extra args for cert-manager container
* Make list indentation consistent
* Apply standard labels on all resources
* Add some content to NOTES.txt
@munnerz
munnerz force-pushed the feature/chart-update branch from 52f2c90 to 417c428 Compare January 15, 2018 23:27
@jetstack-ci-bot jetstack-ci-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 15, 2018
@munnerz
munnerz force-pushed the feature/chart-update branch from 417c428 to 8a38db9 Compare January 15, 2018 23:28
@munnerz

munnerz commented Jan 15, 2018

Copy link
Copy Markdown
Member

@unguiculus I've rebased your PR on the latest changes since we switched our CI. I've also edited your initial PR body with a release note.

@whereisaaron does this look okay to you now? If so, I'm going to merge this. It'll go out in the 0.3 release series as it's a breaking change to how cert-manager is deployed for some users.

@unguiculus

Copy link
Copy Markdown
Contributor Author

Thanks @munnerz

@munnerz

munnerz commented Jan 16, 2018

Copy link
Copy Markdown
Member

/lgtm
/ok-to-test
/approve

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 16, 2018
@jetstack-ci-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: munnerz

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@jetstack-ci-bot jetstack-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 16, 2018
@jetstack-ci-bot

Copy link
Copy Markdown
Contributor

/test all [submit-queue is verifying that this PR is safe to merge]

@jetstack-ci-bot

Copy link
Copy Markdown
Contributor

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note-action-required Denotes a PR that introduces potentially breaking changes that require user action. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants