Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

[stable/jenkins] Add support for idleMinutes and serviceAccount #13263

Merged
merged 6 commits into from
Apr 26, 2019

Conversation

jbussdieker
Copy link
Contributor

What this PR does / why we need it:

This PR allows setting the idleMinutes and serviceAccount attributes used for provisioning build agents.

Which issue this PR fixes

Special notes for your reviewer:

Checklist

[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]

  • DCO signed
  • Chart Version bumped
  • Variables are documented in the README.md

@helm-bot helm-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 24, 2019
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 24, 2019
@k8s-ci-robot
Copy link
Contributor

Hi @jbussdieker. Thanks for your PR.

I'm waiting for a helm 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.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@jbussdieker
Copy link
Contributor Author

/assign @torstenwalter

@torstenwalter
Copy link
Collaborator

Thnks for the PR. What do you think about managing the service account used by the Jenkins agents in a similar way as the service account for Jenkins itself?

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

So having an option to create it etc.

@jbussdieker
Copy link
Contributor Author

That's a good idea. I'll incorporate https://helm.sh/docs/chart_best_practices/#using-rbac-resources into this PR.

@jbussdieker
Copy link
Contributor Author

Actually now that I think about it the agent should default to not creating rbac even if rbac.create is set to true.

Typically users won't want to set a service account for the build agents unless they are using Jenkins to manage and deploy to the cluster hosting Jenkins so the default rules to create is a bit of a grey area.

What might make sense is to the have agent.rbac.create in addition to rbac.create but I'm not sure if that's a good pattern.

On a side note I have noticed that since Jenkins will be the one launching and assigning the service account to the agents, the permissions on the agent service account need to be equal to or less privileged than the master's service account.

I'll think about it more as I work with the chart. Thanks for the feedback!

@torstenwalter
Copy link
Collaborator

@jbussdieker I agree that it's unclear how rbac for the service account of Jenkins agents should look like. Especially since there are many diffrent ways how people are using it.
It heavily depends on their setup e.g.

  • do they want to use it to deploy to the same or a different kubernetes cluster
  • should agents have permission to deploy to the whole cluster or just specific namespaces
  • ...

Helm best practices suggest to split between service account and rbac setup:

rbac:
  # Specifies whether RBAC resources should be created
  create: true

serviceAccount:
  # Specifies whether a ServiceAccount should be created
  create: true
  # The name of the ServiceAccount to use.
  # If not set and create is true, a name is generated using the fullname template
  name:

That's what we do for the Jenkins master. Even if we don't know how to setup rbac we could still manage the creation of the service account. e.g. introducing something like:

serviceAccountAgent:
  # Specifies whether a ServiceAccount should be created
  create: false
  # The name of the ServiceAccount to use.
  # If not set and create is true, a name is generated using the fullname template
  name:

And use a template like:

{{/*
Create the name of the service account for Jenkins agents to use
*/}}
{{- define "jenkins.serviceAccountAgentName" -}}
{{- if .Values.serviceAccountAgent.create -}}
    {{ default (include "jenkins.fullname" .) .Values.serviceAccountAgent.name }}
{{- else -}}
    {{ default "default" .Values.serviceAccountAgent.name }}
{{- end -}}
{{- end -}}

When creating the service account we could also ensure that it is done in the correct namespace if master.slaveKubernetesNamespace is set.

@helm-bot helm-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 25, 2019
@helm-bot helm-bot added Contribution Allowed If the contributor has signed the DCO or the CNCF CLA (prior to the move to a DCO). and removed Contribution Allowed If the contributor has signed the DCO or the CNCF CLA (prior to the move to a DCO). labels Apr 25, 2019
@helm-bot helm-bot added the Contribution Allowed If the contributor has signed the DCO or the CNCF CLA (prior to the move to a DCO). label Apr 25, 2019
@jbussdieker
Copy link
Contributor Author

@torstenwalter thanks that makes sense.

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
@torstenwalter
Copy link
Collaborator

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 26, 2019
*/}}
{{- define "jenkins.serviceAccountAgentName" -}}
{{- if .Values.serviceAccountAgent.create -}}
{{ default (include "jenkins.fullname" .) .Values.serviceAccountAgent.name }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we have a problem here. If neither Values.serviceAccount.name nor .Values.serviceAccountAgent.name is set then we are trying two service accounts with the same name.

jenkins.serviceAccountName: 
{{ default (include "jenkins.fullname" .) .Values.serviceAccount.name }}

jenkins.serviceAccountAgentName
{{ default (include "jenkins.fullname" .) .Values.serviceAccountAgent.name }}

We could add the "-agent" suffix:

{{ default (printf "%s-%s" (include "jenkins.fullname" .) "agent") .Values.serviceAccountAgent.name }}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I thought there might have been a collision somewhere but I was hung up on there being two different bindings to default but that's not an issue.

…ying their names

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
@torstenwalter
Copy link
Collaborator

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 26, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jbussdieker, torstenwalter

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 26, 2019
@k8s-ci-robot k8s-ci-robot merged commit 4595ee0 into helm:master Apr 26, 2019
@torstenwalter
Copy link
Collaborator

@jbussdieker Thank you for this improvement!

@jbussdieker jbussdieker deleted the jbb-more-jenkins-settings branch April 26, 2019 17:19
legal90 added a commit to volvo-cars/helm-charts that referenced this pull request Apr 27, 2019
* spinnaker-additional-configmaps: (158 commits)
  [stable/spinnaker] Bump chart version
  [stable/spinnaker] Allow to use existing additionalConfigMaps objects
  [stable/instana-agent] Add instana-agent chart to stable (helm#12799)
  [stable/spring-cloud-data-flow] apiGroup extension does not have permissions over Jobs (helm#12174)
  Fluentd - Add option to add environment variables from secrets (helm#12565)
  Fluentd - Allow ingress path to be configurable (helm#12561)
  [stable/openebs]: update NDM image tag to 0.3.5 (helm#13282)
  stable/phabricator: update to 2019.16.0 (helm#13307)
  [stable/jenkins] Add support for idleMinutes and serviceAccount (helm#13263)
  [stable/gocd] Bump up k8 elastic agent to latest and bump up GoCD to v19.3.0 (helm#13301)
  [stable/atlantis] Add `--default-tf-version=` and `--allow-fork-prs` flag (helm#13299)
  stackdriver-exporter: allow google service account (helm#13214)
  SC-4435 Do not start the container if particular token is not provided (helm#13304)
  [stable/spring-cloud-data-flow] Update to new SCDF version 2.0.2 (helm#12951)
  allow to set COCKROACH_ENGINE_MAX_SYNC_DURATION (helm#13244)
  Use same JENKINS_URL no matter if slaves use different namespace (helm#12564)
  stable/concourse: separate worker, web deployments (helm#12920)
  [ci] Upgrade to chart-testing v2.3.3 (helm#13294)
  fixes incompatibility with 1.11 (helm#13261)
  Detect current network and netmask (helm#13250)
  ...

# Conflicts:
#	stable/spinnaker/Chart.yaml
dpkirchner pushed a commit to dpkirchner/charts that referenced this pull request May 9, 2019
…m#13263)

* [stable/jenkins] Add support for idleMinutes and serviceAccount

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Modify agent service account feature to follow best practices

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Conditionally set namespace for agent service account

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Add missing period

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Bump version again

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Fix name collision when creating both service accounts but not specifying their names

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
goshlanguage pushed a commit to goshlanguage/charts that referenced this pull request May 17, 2019
…m#13263)

* [stable/jenkins] Add support for idleMinutes and serviceAccount

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Modify agent service account feature to follow best practices

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Conditionally set namespace for agent service account

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Add missing period

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Bump version again

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Fix name collision when creating both service accounts but not specifying their names

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
eyenx pushed a commit to eyenx/charts that referenced this pull request May 28, 2019
…m#13263)

* [stable/jenkins] Add support for idleMinutes and serviceAccount

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Modify agent service account feature to follow best practices

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Conditionally set namespace for agent service account

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Add missing period

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Bump version again

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Fix name collision when creating both service accounts but not specifying their names

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
wmcdona89 pushed a commit to wmcdona89/charts that referenced this pull request Aug 30, 2020
…m#13263)

* [stable/jenkins] Add support for idleMinutes and serviceAccount

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Modify agent service account feature to follow best practices

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Conditionally set namespace for agent service account

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Add missing period

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Bump version again

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>

* Fix name collision when creating both service accounts but not specifying their names

Signed-off-by: Joshua Bussdieker <jbussdieker@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Contribution Allowed If the contributor has signed the DCO or the CNCF CLA (prior to the move to a DCO). lgtm Indicates that a PR is ready to be merged. ok-to-test size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants