Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup workload identity via terraform #1130

Merged
merged 86 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
6f1c1c6
Setup workload identity via terraform
yuvipanda Mar 18, 2022
8feb65a
Explicitly enable specific cloud features on a per-hub basis
yuvipanda Mar 18, 2022
265b5cb
Explicitly set hub_namespace in cloud perms config
yuvipanda Mar 18, 2022
b27aab0
Move KSA creation to helm
yuvipanda Mar 29, 2022
d954e00
Rename 'cloud-access.md' to avoid conflict with howto topic
yuvipanda Mar 29, 2022
e4624a2
Add note about buckets' full names
yuvipanda Mar 29, 2022
50af325
Fix some typos
yuvipanda Mar 29, 2022
8b0ad75
Remove redundant staging specific config
yuvipanda Mar 29, 2022
f40f41a
Add some words that were missing
yuvipanda Mar 29, 2022
c86a980
Add documentation on why userServiceAccount is enabled by default
yuvipanda Mar 29, 2022
b651af7
Enable scratch bucket & requestor pays for LEAP hub
yuvipanda Mar 29, 2022
61d1c8f
Enable scratch bucket & requestor pays for LEAP hub
yuvipanda Mar 29, 2022
4a3d7f3
Migrate 2i2c hubs to new setup
yuvipanda Mar 30, 2022
8e5d2b2
Fix typo
yuvipanda Mar 30, 2022
6abc1d5
Validate authenticator config before deploying
GeorgianaElena Mar 28, 2022
bc55d70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2022
f6d8193
Add more comments
GeorgianaElena Mar 28, 2022
6d0d69f
Rename function
GeorgianaElena Mar 28, 2022
115303b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 2022
f205c11
Rename func again
GeorgianaElena Mar 29, 2022
a0c4601
Update deployer/config_validation.py
GeorgianaElena Mar 29, 2022
b4fab46
Add helm_upgrade_decision.py to deployer
sgibson91 Mar 14, 2022
0a3a2d4
Add generate_helm_upgrade_jobs to deploy_actions.py
sgibson91 Mar 14, 2022
e112824
Add generate-helm-upgrade-jobs command to cli.py
sgibson91 Mar 14, 2022
f311ad8
Add rich to requirements.txt
sgibson91 Mar 14, 2022
0fe431e
Add README to tests folder
sgibson91 Mar 14, 2022
2d3fd61
Add some test clusters
sgibson91 Mar 14, 2022
2d23e77
Add pytest-env to requirements.txt
sgibson91 Mar 14, 2022
73f168c
Add pytest config in pyproject.toml file
sgibson91 Mar 14, 2022
e2f547e
Add tests for helm upgrade decision logic
sgibson91 Mar 14, 2022
73f1f48
Add GitHub Action to run tests against the deployer
sgibson91 Mar 14, 2022
e1fbabe
Exclude cluster.yaml files under tests/ unless we are explicitly runn…
sgibson91 Mar 14, 2022
da0b2ed
Fix yaml import
sgibson91 Mar 14, 2022
a42623a
Fix yaml load commands
sgibson91 Mar 14, 2022
5872eae
Fix some comments and be explicit that the RUN_ENV var is so to "test…
sgibson91 Mar 14, 2022
ce5c975
Ensure output of pytest is colourised
sgibson91 Mar 15, 2022
a3d0950
Use correct option for --color flag to pytest
sgibson91 Mar 15, 2022
a1e783a
Remove 'python -m' from workflow files
sgibson91 Mar 15, 2022
588369e
Update generate-helm-upgrade-jobs parser description
sgibson91 Mar 15, 2022
45c96ee
Rename generate_lists_of_filepaths_and_filenames to get_categorised_u…
sgibson91 Mar 15, 2022
903d530
Improve logic in discover_modified_common_files
sgibson91 Mar 15, 2022
2226c20
Add comment about GITHUB_ENV
sgibson91 Mar 15, 2022
1a948c3
Run pre-commit
sgibson91 Mar 15, 2022
e851a11
Reinstate 'python -m' to run pytest in CI
sgibson91 Mar 15, 2022
d5aaf54
Rewrite logic in discover_modified_common_files so it no longer break…
sgibson91 Mar 15, 2022
cf3b823
Update _converted_string_to_list docstring
sgibson91 Mar 16, 2022
83157d0
Add comment about the GITHUB_ENV default environment variable for CI/CD
sgibson91 Mar 16, 2022
510c1df
Change variable names to be clearer
sgibson91 Mar 16, 2022
3159c1d
Only get a list of cluster filepaths, we will deduce what files have …
sgibson91 Mar 16, 2022
464acd0
Find files that have been added/modified by comparing across all file…
sgibson91 Mar 16, 2022
5d623bc
Remove an unnecessary function
sgibson91 Mar 16, 2022
c47bfbd
Update tests and fix functions so they pass the tests
sgibson91 Mar 16, 2022
85e8c6a
Run pre-commit
sgibson91 Mar 16, 2022
d80f178
Rename get_unique_cluster_dirpaths to get_unique_cluster_filepaths fo…
sgibson91 Mar 16, 2022
04e0bd7
Some updates to docstrings/comments
sgibson91 Mar 16, 2022
857449d
Document a reason for redeploy with each job entry and print this in …
sgibson91 Mar 16, 2022
1fee30c
Use print_colour func for print statements
sgibson91 Mar 16, 2022
0a94a12
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2022
b2ed873
Fixup tests
sgibson91 Mar 16, 2022
6725964
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2022
fc1e222
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2022
9102aa4
Remove relative import
sgibson91 Mar 16, 2022
0f576c6
Be consistent on using "upgrade" not "update" in comments
sgibson91 Mar 16, 2022
fcf64ae
Add new functions to separate staging hub and prod hub jobs
sgibson91 Mar 16, 2022
0e5935d
Update update_github_env and pretty_print_matrix_jobs to handle multi…
sgibson91 Mar 16, 2022
ae9253f
Small tweak to formatting of print statements
sgibson91 Mar 16, 2022
e9385c4
Remove pytest-env as a requirement
sgibson91 Mar 29, 2022
c25c4bf
Read in all cluster.yaml files, make test_env a parsed var
sgibson91 Mar 29, 2022
5f96f99
Update generate_hub_matrix_jobs func
sgibson91 Mar 29, 2022
c7dfb6c
Update generate_support_matrix_jobs func
sgibson91 Mar 29, 2022
5dce0b2
Add a function to filter hub jobs into prod and staging
sgibson91 Mar 29, 2022
5cba2ba
Ensure all support/staging jobs have the correct keys
sgibson91 Mar 29, 2022
6424fc4
Assign support/staging jobs for any c.usters that are missing
sgibson91 Mar 29, 2022
4066edd
Update pretty print functions to accept new fields
sgibson91 Mar 29, 2022
1b3a613
Clean-up
sgibson91 Mar 29, 2022
6019c1d
Update generate_helm_upgrade_jobs function
sgibson91 Mar 29, 2022
5db6187
Update tests
sgibson91 Mar 29, 2022
fd2f5a9
run pre-commit, use print_colour func
sgibson91 Mar 29, 2022
b8bd445
Correct name of import
sgibson91 Mar 29, 2022
9efdc7a
Add staging hu to test cluster1
sgibson91 Mar 29, 2022
e7987a0
Add a try/except block to fix imports
sgibson91 Mar 29, 2022
464bdf7
rename test_env var to is_test
sgibson91 Mar 29, 2022
8e5c853
Rename stray test_env to is_test in tests/ dir
sgibson91 Mar 29, 2022
813949b
Remove typehints
sgibson91 Mar 29, 2022
3720218
🔄 Synced file(s) with 2i2c-org/.github (#1157)
choldgraf Mar 31, 2022
dc7d2a1
Explicitly set userServiceAccount creds for pangeo-hubs
yuvipanda Apr 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 9 additions & 33 deletions .github/ISSUE_TEMPLATE/01_new-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,31 @@ name: 💡 General Issue
description: A general template for many kinds of issues.
body:
- type: textarea
id: description
id: context
attributes:
label: Background and proposal
label: Context
description: |
- **What is the problem** that needs to be solved?
- **What is the solution** that would resolve it?
- **What is the opportunity / value** in solving this problem? And for who?

_below is a suggested structure_
value: |
**Context**
Background information: When ___ kind of person is trying to do ___, then ___ happens.
Problem or opportunity: This is a problem because ___. It would be better if ___.

**Proposed solution**
Action to take: We should make it possible to ___ by doing ___.
Value and who benefits: This would allow ___ users to ___.
Any background information that helps others understand this issue and why it is important.

validations:
required: true

- type: textarea
id: implementation
id: proposal
attributes:
label: Implementation guide and constraints
label: Proposal
description: |

_Anything that will help lower the uncertainty in doing this._

- Suggestions to reduce risk and guide others who may want to implement a solution.
- Constraints and "out of scope" ideas that shouldn't be addressed here.
- Time boxes and work planning.
placeholder: |
- The best way to do this would be...
- This work should *not* include...
- We should try to do ___ in a 2-week time box before moving further.

(optional) A clear and concise description of what we should do, if we have a next step in mind.
Add any guidance that will lower our uncertainty in resolving this (e.g., instructions, constraints to follow, red flags to avoid).
validations:
required: false

- type: textarea
id: tasks
attributes:
label: Updates and ongoing work
label: Updates and actions
description: |
Provide updates as we start to plan and do work.
- Sub-issues and tasks to work on
- Links to project boards
- Updates over time
(optional) A place to track ongoing work items or tasks, as we figure them out.

validations:
required: false
34 changes: 34 additions & 0 deletions .github/workflows/test-deployer-code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Run tests on the deployer code

on:
push:
branches:
- master
paths:
- deployer/**
- tests/**
tags:
- "**"
pull_request:
branches:
- master
paths:
- deployer/**
- tests/**
workflow_dispatch:

jobs:
test-deployer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
pip install -U pip
pip install -r requirements.txt
- name: Run tests
run: |
python -m pytest -vvv --color=yes
4 changes: 4 additions & 0 deletions config/clusters/2i2c/catalyst-cooperative.values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: [email protected]

jupyterhub:
singleuser:
image:
Expand Down
3 changes: 3 additions & 0 deletions config/clusters/2i2c/dask-staging.values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: [email protected]
jupyterhub:
custom:
cloudResources:
Expand Down
4 changes: 4 additions & 0 deletions config/clusters/2i2c/ohw.values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: [email protected]

jupyterhub:
prePuller:
continuous:
Expand Down
6 changes: 0 additions & 6 deletions config/clusters/leap/common.values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ basehub:
2i2c:
add_staff_user_ids_to_admin_users: true
add_staff_user_ids_of_type: "github"
cloudResources:
provider: gcp
gcp:
projectId: leap-pangeo
scratchBucket:
enabled: false
homepage:
templateVars:
org:
Expand Down
6 changes: 6 additions & 0 deletions config/clusters/leap/prod.values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: [email protected]
jupyterhub:
singleuser:
extraEnv:
SCRATCH_BUCKET: gcs://leap-scratch/$(JUPYTERHUB_USER)
hub:
config:
GitHubOAuthenticator:
Expand Down
6 changes: 6 additions & 0 deletions config/clusters/leap/staging.values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: [email protected]
jupyterhub:
singleuser:
extraEnv:
SCRATCH_BUCKET: gcs://leap-scratch-staging/$(JUPYTERHUB_USER)
hub:
config:
GitHubOAuthenticator:
Expand Down
2 changes: 2 additions & 0 deletions config/clusters/meom-ige/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ hubs:
# to the helm upgrade command in, and that has meaning. Please check
# that you intend for these files to be applied in this order.
- common.values.yaml
- staging.values.yaml
- name: prod
display_name: "SWOT Ocean Pangeo Team (prod)"
domain: meom-ige.2i2c.cloud
Expand All @@ -32,3 +33,4 @@ hubs:
# to the helm upgrade command in, and that has meaning. Please check
# that you intend for these files to be applied in this order.
- common.values.yaml
- prod.values.yaml
4 changes: 4 additions & 0 deletions config/clusters/meom-ige/prod.values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: [email protected]
4 changes: 4 additions & 0 deletions config/clusters/meom-ige/staging.values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: meom-ige-staging-workload-sa@meom-ige-cnrs.iam.gserviceaccount.com
3 changes: 3 additions & 0 deletions config/clusters/pangeo-hubs/prod.values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: [email protected]
jupyterhub:
hub:
config:
Expand Down
3 changes: 3 additions & 0 deletions config/clusters/pangeo-hubs/staging.values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
basehub:
userServiceAccount:
annotations:
iam.gke.io/gcp-service-account: staging-user-sa@pangeo-integration-te-3eea.iam.gserviceaccount.com
jupyterhub:
hub:
config:
Expand Down
32 changes: 32 additions & 0 deletions deployer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
deploy_support,
deploy_grafana_dashboards,
use_cluster_credentials,
generate_helm_upgrade_jobs,
)
from config_validation import (
validate_cluster_config,
Expand All @@ -16,6 +17,17 @@
)


def _converted_string_to_list(full_str: str) -> list:
"""
Take a SPACE-DELIMITED string and split it into a list.

This function is used by the generate-helm-upgrade-jobs subcommand to ensure that
the list os added or modified files parsed from the command line is transformed
into a list of strings instead of one long string with spaces between the elements
"""
return full_str.split(" ")


def main():
argparser = argparse.ArgumentParser(
description="""A command line tool to perform various functions related
Expand Down Expand Up @@ -92,6 +104,24 @@ def main():
parents=[base_parser],
help="Modify the current kubeconfig with the deployer's access credentials for the named cluster",
)

# generate-helm-upgrade-jobs subcommand
# This subparser does not depend on the base parser.
generate_helm_upgrade_jobs_parser = subparsers.add_parser(
"generate-helm-upgrade-jobs",
help="Generate a set of matrix jobs to perform a helm upgrade in parallel across clusters and hubs. Emit JSON to stdout that can be read by the strategy.matrix field of a GitHub Actions workflow.",
)
generate_helm_upgrade_jobs_parser.add_argument(
"filepaths",
nargs="?",
type=_converted_string_to_list,
help="A singular or space-delimited list of added or modified filepaths in the repo",
)
generate_helm_upgrade_jobs_parser.add_argument(
"--pretty-print",
action="store_true",
help="Pretty print the generated matrix jobs as tables using rich",
)
# === End section ===#

args = argparser.parse_args()
Expand All @@ -113,3 +143,5 @@ def main():
deploy_grafana_dashboards(args.cluster_name)
elif args.action == "use-cluster-credentials":
use_cluster_credentials(args.cluster_name)
elif args.action == "generate-helm-upgrade-jobs":
generate_helm_upgrade_jobs(args.filepaths, pretty_print=args.pretty_print)
50 changes: 50 additions & 0 deletions deployer/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,53 @@ def validate_support_config(cluster_name):
sys.exit(1)
else:
print_colour(f"No support defined for {cluster_name}. Nothing to validate!")


def assert_single_auth_method_enabled(cluster_name, hub_name):
"""
For each hub of a specific cluster, it asserts that only a single auth
method is enabled. An error is raised when an authenticator
other than Auth0 is enabled and `auth0` is not explicitly disabled.
"""
_prepare_helm_charts_dependencies_and_schemas()

config_file_path = find_absolute_path_to_cluster_file(cluster_name)
with open(config_file_path) as f:
cluster = Cluster(yaml.load(f), config_file_path.parent)

hubs = []
if hub_name:
hubs = [h for h in cluster.hubs if h.spec["name"] == hub_name]
else:
hubs = cluster.hubs

for i, hub in enumerate(hubs):
print_colour(
f"{i+1} / {len(hubs)}: Validating authenticator config for {hub.spec['name']}..."
)

authenticator_class = "auth0"
for values_file_name in hub.spec["helm_chart_values_files"]:
if "secret" not in os.path.basename(values_file_name):
values_file = config_file_path.parent.joinpath(values_file_name)
# Load the hub extra config from its specific values files
config = yaml.load(values_file)
# Check if there's config that specifies an authenticator class
try:
if hub.spec["helm_chart"] != "basehub":
authenticator_class = config["basehub"]["jupyterhub"]["hub"][
"config"
]["JupyterHub"]["authenticator_class"]
else:
authenticator_class = config["jupyterhub"]["hub"]["config"][
"JupyterHub"
]["authenticator_class"]
except KeyError:
pass

# If the authenticator class is other than auth0, then raise an error
# if auth0 is not explicitly disabled from the cluster config
if authenticator_class != "auth0" and hub.spec["auth0"].get("enabled", True):
raise ValueError(
f"Please disable auth0 for {hub.spec['name']} hub before using another authenticator class!"
)
Loading