From 5f87c8c35b59a12b7b5d149dcd13acbf42af8cec Mon Sep 17 00:00:00 2001 From: Jackson Coelho Date: Tue, 14 Jan 2025 17:35:37 +0100 Subject: [PATCH] update the comment action in PR and README --- .github/actions/setup-k3d/action.yaml | 7 - .github/workflows/helm-diff-ci.yml | 177 +++++++++++++---------- production/helm/loki/scenarios/README.md | 64 ++++++-- 3 files changed, 157 insertions(+), 91 deletions(-) diff --git a/.github/actions/setup-k3d/action.yaml b/.github/actions/setup-k3d/action.yaml index fe3fc85c7d1ff..e2ffb6465f554 100644 --- a/.github/actions/setup-k3d/action.yaml +++ b/.github/actions/setup-k3d/action.yaml @@ -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 diff --git a/.github/workflows/helm-diff-ci.yml b/.github/workflows/helm-diff-ci.yml index eab8eaf966271..64e966140cbe1 100644 --- a/.github/workflows/helm-diff-ci.yml +++ b/.github/workflows/helm-diff-ci.yml @@ -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 @@ -12,6 +13,7 @@ jobs: single-binary-diff: name: Single Binary Scenario runs-on: ubuntu-latest + timeout-minutes: 10 steps: - name: Checkout code @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + echo "Single Binary Scenario" >> 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 "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + + echo "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + echo "Default Values Scenario" >> 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 "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + + echo "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + echo "Ingress Values Scenario" >> 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 "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + + echo "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + echo "Legacy Monitoring Scenario" >> 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 "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + + echo "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md + echo "Simple Scalable AWS Kube IRSA Scenario" >> 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 "
" >> formatted_diff_output.md + echo "" >> formatted_diff_output.md - name: Post diff as PR comment uses: marocchino/sticky-pull-request-comment@v2 diff --git a/production/helm/loki/scenarios/README.md b/production/helm/loki/scenarios/README.md index 1ec8692618613..b84c186e23684 100644 --- a/production/helm/loki/scenarios/README.md +++ b/production/helm/loki/scenarios/README.md @@ -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) \ No newline at end of file +* 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 +```