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

Streamline k8s deploy process #3205

Merged
merged 26 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f191f01
feat(ci): streamline Kubernetes preview and deploy workflows
themightychris Jan 1, 2024
f482c85
fix(ci): apply diff formatting to markdown content
themightychris Jan 1, 2024
02802ba
feat(ci): add support for including secret helm values when diffing
themightychris Jan 3, 2024
72847d9
fix(ci): capture activeDeadlineSeconds already applied to cluster
themightychris Jan 3, 2024
5edb2b1
fix(ci): configure sentry to use existing secret
themightychris Jan 3, 2024
5d38e27
fix(ci): move diff newline
themightychris Jan 3, 2024
7b1eb8c
fix(ci): remove sentry secrets that aren't needed
themightychris Jan 3, 2024
1c62621
fix(ci): update workflow title
themightychris Jan 3, 2024
1ae2bc4
fix(ci): bio download path
themightychris Jan 3, 2024
09a8de0
fix(ci): configure git user
themightychris Jan 3, 2024
34dad83
fix(ci): correct diff filename
themightychris Jan 3, 2024
90a0d34
fix(ci): remove deprecated RELEASE_CHANNEL variable
themightychris Jan 3, 2024
0c0e462
docs(ci): move k8s GitOps to kubernetes/README.md
themightychris Jan 3, 2024
d56e81b
docs(ci): fix header
themightychris Jan 3, 2024
aee3805
fix(ci): update holobranch name
themightychris Jan 3, 2024
761a79d
fix(ci): delete workflow for cleaning up deprecated candidate branches
themightychris Jan 3, 2024
fd33f78
docs(ci): update github workflows docs
themightychris Jan 3, 2024
6c75ed2
docs(ci): update hologit docs
themightychris Jan 3, 2024
1279cc3
fix(ci): update workflow step name
themightychris Jan 3, 2024
d8aa877
fix(ci): exclude hooks from helm diff
themightychris Jan 3, 2024
865b0c3
fix(docs): update links to gitops
themightychris Jan 3, 2024
c5383b8
fix(ci): update path filters for new workflows
themightychris Jan 3, 2024
20e7d16
docs(ci): add warnings about diff limitations
themightychris Jan 3, 2024
8007660
feat(ci): add deploy-kubernetes workflow
themightychris Jan 4, 2024
a508bf2
chore(ci): delint inline comments
themightychris Jan 4, 2024
0d557cc
chore(ci): delint trailing comma
themightychris Jan 4, 2024
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
29 changes: 7 additions & 22 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,18 @@ While we're using GCP Composer, "deployment" of Airflow consists of two parts:

This workflow builds a static website from the Svelte app and deploys it to Netlify.

## deploy-kubernetes.yml

This workflow deploys changes to the production Kubernetes cluster when they get merged into the `main` branch.

## build-\*.yml workflows

Workflows prefixed with `build-` generally lint, test, and (usually) publish either a Python package or a Docker image.

## service-\*.yml workflows
## preview-\*.yml workflows

Workflows prefixed with `service-` deal with Kubernetes deployments.
Workflows prefixed with `preview-` deal with generating previews for pull request changes

- `service-release-candidate.yml` creates candidate branches, using [hologit](https://github.com/JarvusInnovations/hologit) to bring in external Helm charts and remove irrelevant (i.e. non-infra) code
- `service-release-diff.yml` renders kubectl diffs on PRs targeting release branches
- `service-release-channel.yml` deploys to a given channel (i.e. environment) on updates to a release branch
- `preview-kubernetes.yml` renders kubectl diffs on PRs changing cluster content

Some of these workflows use hologit or invoke. See the READMEs in [.holo](../../.holo) and [ci](../../ci) for documentation regarding hologit and invoke, respectively.

## GitOps

The workflows described above also define their triggers. In general, developer workflows should follow these steps.

1. Check out a feature branch
2. Put up a PR for that feature branch, targeting `main`
- `service-release-candidate` will run and create a remote branch named `candidate/<feature-branch-name`
3. Create and merge a PR from the candidate branch to `releases/test`
- `service-release-diff` will run on the PR and print the expected changes
- `service-release-channel` will run on merge (i.e. push on `releases/test`) and deploy
4. Merge the original PR
- `service-release-candidate` will then update the remote `candidates/main` branch
5. Create and merge a PR from `candidates/main` to `releases/prod`
- `service-release-channel` will run and deploy to `prod` this time

Note: One alternative would be to use `candidates/main` to deploy into both `test` and `prod`. This is very possible but can be a bit annoying if GitHub is configured to delete branches on merge and the `cleanup-release-candidates` action then deletes `candidates/main` after it has been merged into `releases/test`.
33 changes: 0 additions & 33 deletions .github/workflows/cleanup-release-candidates.yml

This file was deleted.

65 changes: 65 additions & 0 deletions .github/workflows/deploy-kubernetes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Generate diff of Kubernetes changes

on:
push:
branches:
- 'main'
paths:
- '.holo/config.toml'
- '.holo/sources/jarvus-cluster-template.toml'
- '.holo/branches/releases/**'
- '.github/workflows/*-kubernetes.yml'
- 'ci/**'
- 'kubernetes/apps/**'
- 'kubernetes/system/**'

env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_TOKEN }}

jobs:
preview-kubernetes:
runs-on: ubuntu-latest
env:
CLOUDSDK_CORE_PROJECT: cal-itp-data-infra
GKE_NAME: data-infra-apps
GKE_REGION: us-west1
USE_GKE_GCLOUD_AUTH_PLUGIN: True
steps:
# Setup
- uses: actions/checkout@v4

- uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'
- uses: google-github-actions/setup-gcloud@v2
- run: gcloud components install gke-gcloud-auth-plugin
- uses: google-github-actions/get-gke-credentials@v1
with:
cluster_name: ${{ env.GKE_NAME }}
location: ${{ env.GKE_REGION }}
- run: curl -sSL https://install.python-poetry.org | python -
- name: Set up hologit
env:
BIO_RELEASE: 1.6.821
run: |
curl -LO "https://github.com/biome-sh/biome/releases/download/v${BIO_RELEASE}/bio-${BIO_RELEASE}-x86_64-linux.tar.gz"
tar xzvf "bio-${BIO_RELEASE}-x86_64-linux.tar.gz"
sudo mv bio /usr/local/bin/bio
sudo bio pkg install --binlink jarvus/hologit

git config user.name "Github Action $GITHUB_JOB"
git config user.email "$(whoami)@$(uname -n)"

# Render Kubernetes content with parent underlay and checkout
- run: git holo project kubernetes-workspace --commit-to=kubernetes
- run: git checkout kubernetes

# Diff and write back to PR
- id: diff
name: Run poetry invoke
shell: bash
working-directory: ci
run: |
poetry install
poetry run invoke secrets -f "./channels/prod.yaml"
poetry run invoke release -f "./channels/prod.yaml"
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
name: Show diff for release channel
name: Generate diff of Kubernetes changes

on:
pull_request:
branches:
- 'releases/*'
types:
- opened
- synchronize
- reopened
- 'main'
paths:
- '.holo/config.toml'
- '.holo/sources/jarvus-cluster-template.toml'
- '.holo/branches/releases/**'
- '.github/workflows/*-kubernetes.yml'
- 'ci/**'
- 'kubernetes/apps/**'
- 'kubernetes/system/**'

env:
GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_TOKEN }}

jobs:
release:
preview-kubernetes:
runs-on: ubuntu-latest
env:
CLOUDSDK_CORE_PROJECT: cal-itp-data-infra
Expand All @@ -22,9 +26,7 @@ jobs:
USE_GKE_GCLOUD_AUTH_PLUGIN: True
steps:
# Setup
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/checkout@v4

- uses: 'google-github-actions/auth@v2'
with:
Expand All @@ -36,17 +38,30 @@ jobs:
cluster_name: ${{ env.GKE_NAME }}
location: ${{ env.GKE_REGION }}
- run: curl -sSL https://install.python-poetry.org | python -
- name: Set up hologit
env:
BIO_RELEASE: 1.6.821
run: |
curl -LO "https://github.com/biome-sh/biome/releases/download/v${BIO_RELEASE}/bio-${BIO_RELEASE}-x86_64-linux.tar.gz"
tar xzvf "bio-${BIO_RELEASE}-x86_64-linux.tar.gz"
sudo mv bio /usr/local/bin/bio
sudo bio pkg install --binlink jarvus/hologit

git config user.name "Github Action $GITHUB_JOB"
git config user.email "$(whoami)@$(uname -n)"

# Render Kubernetes content with parent underlay and checkout
- run: git holo project kubernetes-workspace --commit-to=kubernetes
- run: git checkout kubernetes

# Diff and write back to PR
- id: diff
name: Run poetry invoke
shell: bash
working-directory: ci
run: |
export RELEASE_CHANNEL=${GITHUB_BASE_REF#releases/}
printf 'WORKFLOW: service-release-diff; RELEASE_CHANNEL=%s\n' "$RELEASE_CHANNEL"
poetry install
poetry run invoke diff -f "./channels/$RELEASE_CHANNEL.yaml" --outfile=diff.txt
poetry run invoke diff -f "./channels/prod.yaml" --outfile=diff.md

- uses: peter-evans/find-comment@v2
id: fc
Expand All @@ -58,5 +73,5 @@ jobs:
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body-file: "ci/diff.txt"
body-file: "ci/diff.md"
edit-mode: replace
67 changes: 0 additions & 67 deletions .github/workflows/service-release-candidate.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/workflows/service-release-channel.yml

This file was deleted.

14 changes: 5 additions & 9 deletions .holo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ hologit allows:
3. Applying transformations to files as part of #1
- These transformations are called "lenses"

In this repository, we declare one holobranch named [release-candidate](../branches/release-candidate).
By projecting this holobranch in GitHub Actions, individual "candidate" branches end up containing
only the code relevant to infra/Kubernetes as well as Kubernetes code from the upstream [cluster-template](https://github.com/JarvusInnovations/cluster-template)
repository. Then, a PR from a `candidate/<some-branch>` to `releases/<env>` (such as `releases/test`) will only show changes/content
relevant to infra in addition to `releases/*` branches only ever containing infra code. For example:
In this repository, we declare one holobranch named [kubernetes-workspace](../branches/kubernetes-workspace).
By projecting this holobranch in GitHub Actions, a tree containing only the code relevant to infra/Kubernetes
as well as Kubernetes code from the upstream [cluster-template](https://github.com/JarvusInnovations/cluster-template)
Copy link
Contributor

Choose a reason for hiding this comment

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

We may need to fork a version of this into Cal-ITP controlled space eventually - probably not actionable right this second, but worth creating a follow-up Issue for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm not sure about the best strategy there. This is a repository we actively maintain for many public/community/client consumers. Cal-ITP is pinned to a specific tagged version and it's a public open repo so it's ensured to stay static until someone bumps to a newer version. Eventually dependencies will need to be updated and at that point whoever is maintaining the infra can either fork the template or bump up to a new version. Most likely Jarvus will have already tested and documented the upgrade path to newer dependency mixes.

While there is a goal to minimize Jarvus dependencies, the project is depending on a lot of random public/community GitHub repositories for lots of things like GitHub actions and helm charts and it would be an anti-pattern to go through and fork every dependency. In cases where a Jarvus repository is linked that's just a fork of something else or a single-use repository, I'd agree with prioritizing eliminating that external dependency, but in this case this is a first-class maintained community project so I'm not sure it makes sense as a goal to just fork it into ITP preemptively

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SorenSpicknall That said it would be a good issue to search for "Jarvus" throughout the codebase and make sure if any forks of community repos are being linked against, we're doing work to get any needed patches moved upstream so we can move the link back to targeting the upstream directly

repository is generated.

1. Create a [PR making an infra-related change](https://github.com/cal-itp/data-infra/pull/2828)
2. Create and merge a [PR to deploy a candidate branch to test](https://github.com/cal-itp/data-infra/pull/2829)
3. Merge the PR from #1
4. After merge, [PR to deploy the main candidate branch to prod](https://github.com/cal-itp/data-infra/pull/2832)
See [`ci/README.md`](../ci/README.md) for details on the pull request workflow for previewing and deploying Kubernetes changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[holomapping]
files = [ "ci/**", "kubernetes/apps/**", "kubernetes/system/**", ".github/workflows/service-*" ]
files = [ "ci/**", "kubernetes/apps/**", "kubernetes/system/**", ".github/workflows/*-kubernetes.yml" ]
before = "*"
2 changes: 2 additions & 0 deletions ci/channels/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ calitp:
namespace: jupyterhub
helm_name: jupyterhub
helm_chart: kubernetes/apps/charts/jupyterhub
secret_helm_values:
- jupyterhub_jupyterhub-sensitive-helm-values
secrets:
- jupyterhub_jupyterhub-gcloud-service-key
- jupyterhub_jupyterhub-github-config
Expand Down
Loading
Loading