Logo

0x3d.Site

is designed for aggregating information.
Welcome
check repository here

Crab 🦀

Dynamic configuration file templating tool for kubernetes manifest or general configuration files

codecov Go Reference Go Report Card Generate release-artifacts Mentioned in Awesome Go

How to install

Download according to your computer architecture at release page go to release page

OSPlatformStatus
Ubuntu, Debianamd64, arm64, 386available
MacOS, Darwinamd64, arm64, 386available
Windowsamd64, arm64, 386available

Extract using command like :

tar -xzf crab-cli-v0.1.0-darwin-amd64.tar.gz -C crab

Move to /usr/local/bin (Optional) :

cp crab/crab /usr/local/bin

Then check crab cli working properly :

Build From Source

  • clone this repository
  • make sure you have go version 18
  • run make build

How to use

basic command fromat :

  crab -f <fileinputpath> -r <keyvalue> -o <outputfilepath>

Flags :

FlagDescriptionRequireddefault
-ffile input path location eg. ./manifest/nginx.yaml (accept any config file ext, .env, json, yml, yaml etc.)true-
-owrite output file location eg. ./manifest/nginx-result.yamlfalsesame as input file path (overwrite)
-rkey value replacabletrue-
-qkey value replacable with quotesfalse-
-vverbose processfalsefalse

Case 1 Standart replace

First add {{replacableName}} to your file :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: {{namespace}}
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: {{exposePort}}

crab cli will replace {{replacableName}} as the key, based on the example above :

  • {{namespace}}
  • {{exposePort}}

then run crab command :

  crab -f inputfile.yaml -r namespace=production -r exposePort=8081

yes you can override multiple key values ✔️

write output to another file add -o flag:

  crab -f inputfile.yaml -r namespace=production -r exposePort=8081 -o result.yaml

to make verbose add -v flag:

  crab -f inputfile.yaml -r namespace=production -r exposePort=8081 -o result.yaml -v

verbose output :

[REPLACED] from namespace to production
[REPLACED] from exposePort to 8081
[DONE] Crab output result at result.yaml

the result will be :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: production
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: 8081

Click to watch the demo : asciicast

Youtube demo video :

Case 2 Quotes replace

sometimes your config file needs string quotes, (like for env vars or connection string):

  namespace="production"

template file example :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: {{namespace}}
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: {{exposePort}}

let's say we need a quote in the namespace :

  crab -f inputfile.yaml -q namespace=production -r exposePort=8081 -o result.yaml -v

yass you can simultaneously Replace multiple key values with quotes or not ✔️

result will be :

apiVersion: v1
kind: Service
metadata:
    name: nginx
    namespace: "production"
spec:
    ports:
      - targetPort: 80
        name: nginxhttp
        port: 8081

Sample Github Action

name: Demo deployment using crab

on:
  workflow_dispatch:

jobs:
  crab-manifest:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: mock job
        run: pwd

  deploy-test:
    runs-on: ubuntu-latest
    needs: crab-manifest
    steps:
      - uses: actions/checkout@v3
      - name: install crab cli
        run: wget -c https://github.com/alfiankan/crab-config-files-templating/releases/download/v1.0.5/crab-v1.0.5-linux-amd64.tar.gz -O - | tar -xz crab
      - name: recreate deployment manifest on test
        run: |
          ./crab -f example/manifest/nginx.yaml \
          -r namespace=test \
          -r publishPort=8000 \
          -q portName=test-server \
          -o nginx-test.yaml \
          -v
      - name: view manifest
        run: cat nginx-test.yaml
                    
  
  deploy-production:
    runs-on: ubuntu-latest
    needs: crab-manifest
    steps:
      - uses: actions/checkout@v3
      - name: install crab cli
        run: wget -c https://github.com/alfiankan/crab-config-files-templating/releases/download/v1.0.5/crab-v1.0.5-linux-amd64.tar.gz -O - | tar -xz crab
      - name: recreate deployment manifest on production
        run: |
          ./crab -f example/manifest/nginx.yaml \
          -r namespace=production \
          -r publishPort=80 \
          -q portName=prod-server \
          -o nginx-prod.yaml \
          -v
      - name: view manifest
        run: cat nginx-prod.yaml

Related article

  • Replacing kubernetes manifest value dynamicly (coming soon on medium)
Golang
Golang
Golang, or Go, is a statically typed programming language developed by Google. It’s known for its simplicity, performance, and support for concurrent programming. Go is widely used in cloud computing, server-side applications, and microservices.
GitHub - goyek/goyek: Task automation Go library
GitHub - goyek/goyek: Task automation Go library
gommon/color at master · labstack/gommon
gommon/color at master · labstack/gommon
GitHub - blevesearch/bleve: A modern text/numeric/geo-spatial/vector indexing library for go
GitHub - blevesearch/bleve: A modern text/numeric/geo-spatial/vector indexing library for go
GitHub - schollz/progressbar: A really basic thread-safe progress bar for Golang applications
GitHub - schollz/progressbar: A really basic thread-safe progress bar for Golang applications
GitHub - free/concurrent-writer: Highly concurrent drop-in replacement for bufio.Writer
GitHub - free/concurrent-writer: Highly concurrent drop-in replacement for bufio.Writer
GitHub - mattn/go-colorable
GitHub - mattn/go-colorable
GitHub - StudioSol/set: A simple Set data structure implementation in Go (Golang) using LinkedHashMap.
GitHub - StudioSol/set: A simple Set data structure implementation in Go (Golang) using LinkedHashMap.
GitHub - essentialkaos/branca: Authenticated encrypted API tokens (IETF XChaCha20-Poly1305 AEAD) for Golang
GitHub - essentialkaos/branca: Authenticated encrypted API tokens (IETF XChaCha20-Poly1305 AEAD) for Golang
Cloud Native Computing Foundation
Cloud Native Computing Foundation
GitHub - sakirsensoy/genv: Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables to be loaded from the .env file.
GitHub - sakirsensoy/genv: Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables to be loaded from the .env file.
GitHub - heetch/confita: Load configuration in cascade from multiple backends into a struct
GitHub - heetch/confita: Load configuration in cascade from multiple backends into a struct
GitHub - brianvoe/sjwt: Simple JWT Golang
GitHub - brianvoe/sjwt: Simple JWT Golang
GitHub - subpop/go-ini: Go package that encodes and decodes INI-files
GitHub - subpop/go-ini: Go package that encodes and decodes INI-files
GitHub - DylanMeeus/GoAudio: Go tools for audio processing & creation 🎶
GitHub - DylanMeeus/GoAudio: Go tools for audio processing & creation 🎶
GitHub - daviddengcn/go-colortext: Change the color of console text.
GitHub - daviddengcn/go-colortext: Change the color of console text.
GitHub - andOTP/andOTP: [Unmaintained] Open source two-factor authentication for Android
GitHub - andOTP/andOTP: [Unmaintained] Open source two-factor authentication for Android
GitHub - alfiankan/crab-config-files-templating: Dynamic configuration file templating tool for kubernetes manifest or general configuration files
GitHub - alfiankan/crab-config-files-templating: Dynamic configuration file templating tool for kubernetes manifest or general configuration files
GitHub - viney-shih/go-cache: A flexible multi-layer Go caching library to deal with in-memory and shared cache by adopting Cache-Aside pattern.
GitHub - viney-shih/go-cache: A flexible multi-layer Go caching library to deal with in-memory and shared cache by adopting Cache-Aside pattern.
GitHub - TreyBastian/colourize: An ANSI colour terminal package for Go
GitHub - TreyBastian/colourize: An ANSI colour terminal package for Go
GitHub - Evertras/bubble-table: A customizable, interactive table component for the Bubble Tea framework
GitHub - Evertras/bubble-table: A customizable, interactive table component for the Bubble Tea framework
GitHub - deatil/go-array: A Go package that read or set data from map, slice or json
GitHub - deatil/go-array: A Go package that read or set data from map, slice or json
GitHub - cometbft/cometbft: CometBFT (fork of Tendermint Core): A distributed, Byzantine fault-tolerant, deterministic state machine replication engine
GitHub - cometbft/cometbft: CometBFT (fork of Tendermint Core): A distributed, Byzantine fault-tolerant, deterministic state machine replication engine
GitHub - icza/session: Go session management for web servers (including support for Google App Engine - GAE).
GitHub - icza/session: Go session management for web servers (including support for Google App Engine - GAE).
GitHub - cristalhq/jwt: Safe, simple and fast JSON Web Tokens for Go
GitHub - cristalhq/jwt: Safe, simple and fast JSON Web Tokens for Go
GitHub - lrita/cmap: a thread-safe concurrent map for go
GitHub - lrita/cmap: a thread-safe concurrent map for go
GitHub - wzshiming/ctc: Console Text Colors - The non-invasive cross-platform terminal color library does not need to modify the Print method
GitHub - wzshiming/ctc: Console Text Colors - The non-invasive cross-platform terminal color library does not need to modify the Print method
GitHub - goradd/maps: map library using Go generics that offers a standard interface, go routine synchronization, and sorting
GitHub - goradd/maps: map library using Go generics that offers a standard interface, go routine synchronization, and sorting
GitHub - alfiankan/teleterm: Telegram Bot Exec Terminal Command
GitHub - alfiankan/teleterm: Telegram Bot Exec Terminal Command
GitHub - JeremyLoy/config: 12 factor configuration as a typesafe struct in as little as two function calls
GitHub - JeremyLoy/config: 12 factor configuration as a typesafe struct in as little as two function calls
GitHub - goraz/onion: Layer based configuration for golang
GitHub - goraz/onion: Layer based configuration for golang
Golang
More on Golang

Programming Tips & Tricks

Code smarter, not harder—insider tips and tricks for developers.

Error Solutions

Turn frustration into progress—fix errors faster than ever.

Shortcuts

The art of speed—shortcuts to supercharge your workflow.
  1. Collections 😎
  2. Frequently Asked Question's 🤯

Tools

available to use.

Made with ❤️

to provide resources in various ares.