Skip to content

Commit

Permalink
update the comment action in PR and README
Browse files Browse the repository at this point in the history
  • Loading branch information
fcjack committed Jan 15, 2025
1 parent 7943e01 commit 5f87c8c
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 91 deletions.
7 changes: 0 additions & 7 deletions .github/actions/setup-k3d/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,3 @@ runs:
shell: bash
run: |
k3d kubeconfig merge k3d-cluster --kubeconfig-switch-context
# - name: Verify k3d installation
# shell: bash
# run: |
# k3d --version
# kubectl version
# kubectl get node
177 changes: 103 additions & 74 deletions .github/workflows/helm-diff-ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
name: Helm Loki Diff CI
on: [pull_request]
# paths:
# - "production/helm/loki/**"
on:
pull_request:
paths:
- 'production/helm/loki/**'

permissions:
contents: read
Expand All @@ -12,6 +13,7 @@ jobs:
single-binary-diff:
name: Single Binary Scenario
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Checkout code
Expand Down Expand Up @@ -52,9 +54,7 @@ jobs:
- name: Convert Helm Diff Output to Markdown
id: convert_diff
run: |
echo '```diff' >> formatted_diff_output.md
cat helm_diff_output.txt >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
- name: Upload diff output as artifact
id: upload_diff
Expand Down Expand Up @@ -107,9 +107,7 @@ jobs:
- name: Convert Helm Diff Output to Markdown
id: convert_diff
run: |
echo '```diff' >> formatted_diff_output.md
cat helm_diff_output.txt >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
- name: Upload diff output as artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -162,9 +160,7 @@ jobs:
- name: Convert Helm Diff Output to Markdown
id: convert_diff
run: |
echo '```diff' >> formatted_diff_output.md
cat helm_diff_output.txt >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
- name: Upload diff output as artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -217,9 +213,7 @@ jobs:
- name: Convert Helm Diff Output to Markdown
id: convert_diff
run: |
echo '```diff' >> formatted_diff_output.md
cat helm_diff_output.txt >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
- name: Upload diff output as artifact
uses: actions/upload-artifact@v4
Expand All @@ -229,64 +223,52 @@ jobs:
path: formatted_diff_output.md
retention-days: 2

# simple-scalable-aws-kube-irsa-values-diff:
# name: Simple Scalable AWS Kube IRSA Values Scenario
# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Setup Helm
# uses: azure/setup-helm@v4

# - name: Add required Helm repositories
# run: |
# helm repo add minio https://charts.min.io/
# helm repo add grafana https://grafana.github.io/helm-charts
# helm repo add grafana-operator https://grafana.github.io/helm-charts
# helm repo update

# - name: Setup K3D
# uses: ./.github/actions/setup-k3d

# - name: Setup Helm plugins
# run: |
# helm plugin install https://github.com/databus23/helm-diff

# - name: Build helm dependencies
# run: |
# helm dependency build production/helm/loki

# - name: Install latest helm release
# run: |
# helm install --create-namespace loki-release grafana/loki -f production/helm/loki/scenarios/simple-scalable-aws-kube-irsa-values.yaml

# - name: Run helm diff
# id: helm-diff
# env:
# HELM_DIFF_USE_UPGRADE_DRY_RUN: true
# run: |
# helm diff upgrade loki-release -f production/helm/loki/scenarios/simple-scalable-aws-kube-irsa-values.yaml production/helm/loki | tee helm_diff_output.txt

# - name: Convert Helm Diff Output to Markdown
# id: convert_diff
# run: |
# echo "### Helm Diff Output" > formatted_diff_output.md
# echo '```diff' >> formatted_diff_output.md
# cat helm_diff_output.txt >> formatted_diff_output.md
# echo '```' >> formatted_diff_output.md
# cat formatted_diff_output.md

# - name: Post diff as PR comment
# uses: marocchino/sticky-pull-request-comment@v2
# with:
# header: "Helm Diff Output - Simple Scalable AWS Kube IRSA Values Scenario"
# skip_unchanged: true
# hide_and_recreate: true
# append: true
# hide_classify: "OUTDATED"
# path: formatted_diff_output.md
simple-scalable-aws-kube-irsa-values-diff:
name: Simple Scalable AWS Kube IRSA Values Scenario
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Helm
uses: azure/setup-helm@v4

- name: Add required Helm repositories
run: |
helm repo add minio https://charts.min.io/
helm repo add grafana https://grafana.github.io/helm-charts
helm repo add grafana-operator https://grafana.github.io/helm-charts
helm repo update
- name: Build helm dependencies
run: |
helm dependency build production/helm/loki
- name: Generate latest manifests
run: |
helm template loki-release grafana/loki -f production/helm/loki/scenarios/simple-scalable-aws-kube-irsa-values.yaml > release-manifest.yaml
- name: Generate current manifest
run: |
helm template loki-release production/helm/loki -f production/helm/loki/scenarios/simple-scalable-aws-kube-irsa-values.yaml > current-manifest.yaml
- name: Compare manifests
run: |
diff current-manifest.yaml release-manifest.yaml > helm_diff_output.txt || true
- name: Convert Helm Diff Output to Markdown
id: convert_diff
run: |
cat helm_diff_output.txt >> formatted_diff_output.md
- name: Upload diff output as artifact
uses: actions/upload-artifact@v4
id: upload_diff
with:
name: simple-scalable-aws-kube-irsa-diff-output
path: formatted_diff_output.md
retention-days: 2

summary-diff-outputs:
name: Summary Diffs
Expand All @@ -296,7 +278,7 @@ jobs:
- default-values-diff
- ingress-values-diff
- legacy-monitoring-values-diff
# - simple-scalable-aws-kube-irsa-values-diff
- simple-scalable-aws-kube-irsa-values-diff

steps:
- name: Checkout code
Expand All @@ -322,17 +304,64 @@ jobs:
name: legacy-monitoring-diff-output
path: legacy-monitoring-values-diff

- uses: actions/download-artifact@v4
with:
name: simple-scalable-aws-kube-irsa-diff-output
path: simple-scalable-aws-kube-irsa-values-diff

- name: Combine diff outputs
run: |
echo "## Helm Diff Output - Summary" > formatted_diff_output.md
echo "### Single Binary Scenario" >> formatted_diff_output.md
echo "<details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<summary>Single Binary Scenario</summary>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo '```diff' >> formatted_diff_output.md
cat single-binary-diff/formatted_diff_output.md >> formatted_diff_output.md
echo "### Default Values Scenario" >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
echo "</details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<summary>Default Values Scenario</summary>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo '```diff' >> formatted_diff_output.md
cat default-values-diff/formatted_diff_output.md >> formatted_diff_output.md
echo "### Ingress Values Scenario" >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
echo "</details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<summary>Ingress Values Scenario</summary>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo '```diff' >> formatted_diff_output.md
cat ingress-values-diff/formatted_diff_output.md >> formatted_diff_output.md
echo "### Legacy Monitoring Values Scenario" >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
echo "</details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<summary>Legacy Monitoring Scenario</summary>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo '```diff' >> formatted_diff_output.md
cat legacy-monitoring-values-diff/formatted_diff_output.md >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
echo "</details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo "<summary>Simple Scalable AWS Kube IRSA Scenario</summary>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
echo '```diff' >> formatted_diff_output.md
cat simple-scalable-aws-kube-irsa-values-diff/formatted_diff_output.md >> formatted_diff_output.md
echo '```' >> formatted_diff_output.md
echo "</details>" >> formatted_diff_output.md
echo "" >> formatted_diff_output.md
- name: Post diff as PR comment
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
64 changes: 54 additions & 10 deletions production/helm/loki/scenarios/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
These scenarios are used by Github Workflow: [Publish Rendered Helm Chart Diff](../../../../.github/workflows/helm-loki-ci.yml).
# Loki Helm Scenarios

Each scenario is used as the values file for the Loki Helm chart to render Kubernetes manifests in `base` and `PR's` branch to compare the content and report the diff on Pull Request as a comment([example](https://github.com/grafana/loki/pull/14127#issuecomment-2348360828)). It gives the ability to the reviewer to understand how the changes in the chart modify resulting manifests.
These scenarios are used by Github Workflow: [Publish Rendered Helm Chart Diff](../../../../.github/workflows/helm-diff-ci.yml).

![img.png](images/img.png)
Each scenario is used in a different job execution that will be used to deploy loki inside a K3D cluster in our github action workflow.

The workflow reports three types of changes for each scenario:
We deploy the scenario with the latest release and then we execute a helm diff with the current version in the workspace, the diff between the release deployed will be posted in the pull request inside a comment like [this](https://github.com/grafana/loki/pull/15734#issuecomment-2592439539) making clear to review.

1. Added files - the manifests that are added in the current PR and that did not exist in `base` branch.
>*NOTE*: the helm diff output file will be available for each scenario inside github action to download for 2 days, after this you may need to re-run the job if you would like to download the output files.
![added.png](images/added.png)
## Run scenarios locally

All this process that we run in the CI can be done locally, the following steps would explain how.

2. Modified files - the manifests that exist in both branches but the changes in PRs branch modify them.
![modified.png](images/modified.png)
## Requirements

3. Removed files - the manifests that exist in `base` branch but do not exist in PRs branch.
To run locally you will need the following tools in your local environment

![removed.png](images/removed.png)
* k3d or any kubernetes cluster
* helm
* [helm-diff plugin](https://github.com/databus23/helm-diff)

## Run

Make sure that you are pointing to the kubernetes cluster that you want to apply the chart and validate.

Create a `${scenario}-values.yaml` file with the configuration that you would like to validate.

Deploy in your kubernetes cluster the latest released version of the helm chart with your config file:

```shell
helm install --create-namespace loki-release grafana/loki -f ${scenario}-values.yaml
```

Then run the helm diff plugin to compare the local helm chart to see the upgrade changes that will happen:

```shell
HELM_DIFF_USE_UPGRADE_DRY_RUN: true helm diff upgrade loki-release -f ${scenario}-values.yaml production/helm/loki
```

The helm diff plugin will compare all manifests that are created in your local development kubernetes cluster and the generated by helm upgrade operation, the output will be printed in your terminal.

### Configs for CSP specific

To compare the changes specifically for a cloud provider the process is similar, the main difference that you will need to have access to the kubernetes cluster with the right permissions inside the cloud provider.

In case that is not possible, the quick validation can be done in a different way, instead of deploy to the kubernetes cluster, we generate the manifests with helm like this:

```shell
helm template loki-release grafana/loki -f ${scenario}-values.yaml > release-manifest.yaml
```

Then we make the same process with local chart version

```shell
helm template loki-release production/helm/loki -f ${scenario}-values.yaml > current-manifest.yaml
```

As the last step you need to run a diff between both files:

```shell
diff current-manifest.yaml release-manifest.yaml
```

0 comments on commit 5f87c8c

Please sign in to comment.