GithubHelp home page GithubHelp logo

gitops-action-kustomize-compare's Introduction

Kustomization builds compare

Github action to print the differences of kustomize build files. Using kustomize cli tool will help you reduce kubernetes yaml definitions that requires differences when deployed to specific environments, but will take away the readability of the end result object definition. Using this tool will help you validate and show the changes that are generated.

The script can be used as a local tool. Simply copy the shell script code into a executable file

# dependencies: yq, kustomize, csplit

sudo vi /usr/local/bin/kustomize-diff
# paste the data from entrypoint.sh
sudo chmod +x /usr/local/bin/kustomize-diff

Point your terminal to the location where you have the main kustomization.yaml file and execute kustomize-diff, or one of the following

kustomize-diff /home/user/projects/my-kubernetes-project/overlays master  > full path directory location, compare with local master branch
kustomize-diff overlays origin/master >  relative path, comparing with last branched off hash from remote master
kustomize-diff "" origin/develop > kustomization.yaml in the current directory, comparing with the same location in remote develop branch 

Inputs

kustomization-location

Required Project relative path of your kustomization.yaml file. Default is the root of the project "./".

compare-branch-name

Required The name of the branch that your current branch is branched of. As this script is fetching the last common commit git hash, you need to make sure that such hash exist in your branch.

Outputs

none

Example usage

Create a github action file in your project such as .github/workflows/kustomize-compare.yaml

name: compare

on:
  pull_request:
    branches:
      - master                                                                 <-- trigger validation on pull requests done against master
jobs:
  kustomize-overlay-staging:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2                                              <-- git checkout helper
      - run: git fetch --unshallow origin master && git checkout ${GITHUB_REF} <-- register origin master as branch to compare to, PLUS checkout current branch 
      - name: +++++ KUSTOMIZE DIFF +++++                                       
        uses: swoop-ltd/[email protected]                <-- use this public github action
        with:
          kustomization-location: overlays                                     <-- location of the this-project/overlays/kustomization.yaml
          compare-branch-name: origin/master                                   <-- build code from branched off hash, present in origin/master

Example on execution

  Set up job                                                            2s
  Build loveholidays/[email protected]              28s
  Run actions/checkout@v2                                               1s
  Run git fetch --unshallow origin master && git checkout ${GITHUB_REF} 3s
  +++++ KUSTOMIZE DIFF +++++                                           10s
  Post actions/checkout@v2                                              0s
  Complete job



 +++++ KUSTOMIZE DIFF +++++

Run loveholidays/[email protected]
/usr/bin/docker run [...]  "overlays" "origin/master"
  ┌───────
  ├ Comparing kustomize builds overlays kustomization.yaml 
  ├ FROM new HEAD
  ├   TO old origin/master branched off commit [some commit long sha]
  ├ Preparing overlays/kustomize_build_temp/origin/master-detached (identifier master-detached)
  ├ HEAD is now at [some short sha] Merge pull request [some commit message]
  ├─ Previous HEAD position was [some short sha] Merge pull request [some commit message]
  ├─ HEAD is now at [some short sha] [some commit message]
  ├ Splitting kustomization build into separate objects
  └ Processing diff

╭─ + NEW OBJECT
│ apiVersion: v1
│ kind: ConfigMap
│ metadata:
│   name: test-add-new-object
│   namespace: default
╰──────────

╭─ * UPDATED OBJECT 
│ apiVersion: apps/v1
│ kind: Deployment
│ metadata:
│   name: some-name
│   namespace: default
╰─┬─────────
  │ @@ -10,7 +10,7 @@ spec:
  │          resources:
  │            limits:
  │              cpu: 100m
  │ -            memory: 256Mi
  │ +            memory: 300Mi
  │            requests:
  │              cpu: 100m
  │              memory: 256Mi
  ╰──────────

╭─ - DELETED OBJECT
│ apiVersion: v1
│ kind: ConfigMap
│ metadata:
│   name: test-delete-object
│   namespace: default
╰──────────

OR
  ╭─
  │ No changes detected for overlays/kustomization.yaml
  ╰─

gitops-action-kustomize-compare's People

Contributors

fbueno avatar sander-swoop avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  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.