Giter Site home page Giter Site logo

hronom / argocd-commenter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from int128/argocd-commenter

0.0 0.0 0.0 1.29 MB

Notify ArgoCD Application status via Pull Request comment or GitHub Deployment API

License: Apache License 2.0

Shell 0.77% Go 88.17% Makefile 10.01% Dockerfile 1.04%

argocd-commenter's Introduction

argocd-commenter docker

This is a Kubernetes Controller to notify a change of Argo CD Application status.

Example: Pull Request notification

In the GitOps way, you merge a pull request to deploy a change to Kubernetes cluster. argocd-commenter allows you to receive a notification comment after merging.

When an Application is syncing, synced or healthy, argocd-commenter will create a comment.

image

When the sync was failed, argocd-commenter will create a comment.

image

See the examples in e2e-test fixtures.

Sequence diagram

Here is the sequence diagram of the deployment flow.

sequenceDiagram
  actor User

  User ->>+ GitHub Repository: git push
  GitHub Repository -->>- User: pushed

  loop Argo CD reconciler
    Argo CD Application ->>+ GitHub Repository: git checkout
    GitHub Repository -->>- Argo CD Application: manifest
    note over Argo CD Application: Out of Sync
    Argo CD Application ->>+ Kubernetes Deployment: kubectl apply
    note over Argo CD Application: Syncing
    Kubernetes Deployment -->>- Argo CD Application: applied
    note over Argo CD Application: Synced
  end

  loop Kubernetes reconciler
    Kubernetes Deployment ->>+ Kubernetes Pod: create
    note over Argo CD Application: Progressing
    Kubernetes Pod -->>- Kubernetes Deployment: ready
    note over Argo CD Application: Healthy
  end

Example: GitHub Deployment notification

In a complex deployment flow, you can receive a notification using GitHub Deployments API. For example, when you deploy a preview environment for a pull request, you can receive the deployment statuses.

To receive a deployment status, set the following annotation to the Argo CD Application:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  annotations:
    argocd-commenter.int128.github.io/deployment-url: https://api.github.com/repos/OWNER/REPO/deployments/ID

Here is an example of workflow to deploy a preview environment:

jobs:
  deploy:
    steps:
      # Create a deployment
      - uses: int128/deployment-action@v1
        id: deployment

      # Generate the manifests for a preview environment
      - uses: actions/checkout@v2
        with:
          repository: your/manifests-repository
          path: manifests-repository
          token: # PAT or GitHub App token is required to write
      - run: |
          cp -a manifests "manifests-repository/pr-${{ github.event.pull_request.number }}"
          cd "manifests-repository/pr-${{ github.event.pull_request.number }}"
          sed -e 's|DEPLOYMENT_URL|${{ steps.deployment.outputs.url }}|g' applications/*.yaml

      # Push the manifests for a preview environment
      - run: |
          git add .
          git commit -m 'Deploy pr-${{ github.event.pull_request.number }}'
          git push manifests-repository main

When the Application status is changed, argocd-commenter will create a deployment status.

image

See the e2e test for details.

Sequence diagram

Here is the sequence diagram of the deployment flow.

sequenceDiagram
  actor User

  User ->>+ Application Repository: git push
  Application Repository -->>- User: pushed

  Application Repository ->>+ GitHub Actions: start
  GitHub Actions ->>+ GitHub Deployment: create
  GitHub Deployment -->>- GitHub Actions: created
  note over GitHub Deployment: Pending
  GitHub Actions ->>+ Manifest Repository: git push
  Manifest Repository -->>- GitHub Actions: pushed
  GitHub Actions -->>- Application Repository: success

  loop Argo CD reconciler
    Argo CD Application ->>+ Manifest Repository: git checkout
    Manifest Repository -->>- Argo CD Application: manifest
    note over Argo CD Application: Out of Sync
    note over GitHub Deployment: Queued
    Argo CD Application ->>+ Kubernetes Deployment: kubectl apply
    note over Argo CD Application: Syncing
    Kubernetes Deployment -->>- Argo CD Application: applied
    note over Argo CD Application: Synced
    note over GitHub Deployment: In progress
  end

  loop Kubernetes reconciler
    Kubernetes Deployment ->>+ Kubernetes Pod: create
    note over Argo CD Application: Progressing
    Kubernetes Pod -->>- Kubernetes Deployment: ready
    note over Argo CD Application: Healthy
    note over GitHub Deployment: Active
  end

Getting Started

Prerequisite

Argo CD is running in your Kubernetes cluster.

Setup

To deploy the manifest:

kubectl apply -f https://github.com/int128/argocd-commenter/releases/download/v1.8.0/argocd-commenter.yaml

You need to create either Personal Access Token or GitHub App.

  • Personal Access Token
    • Belong to a user
    • Share the rate limit in a user
  • GitHub App
    • Belong to a user or organization
    • Have each rate limit for an installation

Option 1: Using a Personal Access Token

  1. Open https://github.com/settings/tokens
  2. Generate a new token
  3. Create a secret as follows:
    kubectl -n argocd-commenter-system create secret generic controller-manager \
      --from-literal="GITHUB_TOKEN=$YOUR_PERSONAL_ACCESS_TOKEN"

Option 2: Using a GitHub App

  1. Create your GitHub App from either link:
  2. Get the App ID from the setting page
  3. Download a private key of the GitHub App
  4. Set a custom badge for the GitHub App
  5. Install your GitHub App on your repository or organization
  6. Get the Installation ID from the URL, like https://github.com/settings/installations/ID
  7. Create a secret as follows:
    kubectl -n argocd-commenter-system create secret generic controller-manager \
      --from-literal="GITHUB_APP_ID=$YOUR_GITHUB_APP_ID" \
      --from-literal="GITHUB_APP_INSTALLATION_ID=$YOUR_GITHUB_APP_INSTALLATION_ID" \
      --from-file="GITHUB_APP_PRIVATE_KEY=/path/to/private-key.pem"

Verify setup

Make sure the controller is running.

kubectl -n argocd-commenter-system rollout status deployment argocd-commenter-controller-manager

Configuration

GitHub Enterprise Server

Set the environment variable GITHUB_ENTERPRISE_URL.

kubectl -n argocd-commenter-system create secret generic controller-manager \
  --from-literal="GITHUB_TOKEN=$YOUR_PERSONAL_ACCESS_TOKEN" \
  --from-literal="GITHUB_ENTERPRISE_URL=$YOUR_GITHUB_ENTERPRISE_URL"

Contribution

This is an open source software. Feel free to contribute to it.

argocd-commenter's People

Contributors

renovate[bot] avatar int128 avatar matthiaswinzeler avatar quentinplessis avatar hronom avatar yuya-takeyama avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.