/wrapf

Small script shell wraps kubectl, kustomize and terraform commands with fzf. It allows you to select a resource corresponding to the specified type and perform the given command on it.

Primary LanguageShell

WRAPF

wrapf is a small script wrapping kubectl, kustomize, terraform with Fzf to allow you to select one or multiple resources and perform an action on them.

wrapf Demo

For kubectl, you use wrapf in the same way as you use kubectl because wrapf uses almost the same syntax, same commands, same resource types and same options as kubectl does, except for several small differences as described in the usage section.

Usage

Usage: wrapf <CMD> <TYPE> <OPTION1>...<OPTIONX> -- <ARG1> ... <ARGX>

CMD:       exec, logs, describe, delete, rollout, scale, autoscale, label, annotate, view, kb, ka, kd, tfwsa, tfwsp, tfwsd, tfwsr.
TYPE:      all kubectl resource types supported by the above commands.
OPTIONS:   all kubectl options normally used with the above commands & types.
ARGS:      command shell with its arguments to be executed in the container

Kubernetes

Describe a pod in a given namespace:

$ wrapf describe pod -n istio-system

Execute a command shell in a container within a pod:

$ wrapf exec pod -n default -- ls -la

Execute a interactive shell in a container within a pod:

$ wrapf exec pod -n istio-system -it -- bash

Watch logs of a container within a pod in a given namespace:

$ wrapf logs pod -n istio-system -f

Execute a commanwrapfd shell in a container within a pod with --all-namespaces:

$ wrapf exec pod --all-namespaces -- ls -la

Delete a ressource:

$ wrapf delete secrets

View secret data entry:

$ wrapf view secrets -n mongodb

Kustomize

Execute kustomize build:

$ wrapf kb ./envs

Execute kustomize build and kubectl apply:

$ wrapf ka ./envs

Terraform

Execute terraform plan in a workspace that we are going to select in fuzzy:

$ wrapf tfwsa

Execute terraform apply in a workspace that we are going to select in fuzzy:

$ wrapf tfwsa

Execute terraform destroy in a workspace that we are going to select in fuzzy:

$ wrapf tfwsa

Remove a workspace that we are going to select in fuzzy:

$ wrapf tfwsr

Installation

  • Manual: MacOS, Linux and any POSIX environment with Bash/Zsh installed.
  • Homebrew: soon and recommanded for MacOs.

Manual

$ sudo git clone https://github.com/uthng/wrapf.git /opt/wrapf
$ chmod +x /opt/wrapf/wrapf
$ sudo ln -s /opt/wrapf/wrapf /usr/local/bin/wrapf

Homebrew

Comming soon.

How does it work ?

  • For each command, wrapf first gets a list of resources corresponding to the given type (pods, deployment, pvc, etc) in the current namespace, in all namespaces or maybe with filters used commonly in kubectl get
  • Then, wrapf passes it to Fzf to allow you to select one or multiple values depending on command type.
  • Once a value selected, wrapf performs the given command with common kubectl options, if specified.
  • If a container needs to be specified, wrapf does another get on the related pod to retrieve the container list and passes it to Fzf.
  • If the command is not supported (neither be in kubectl command list nor in custom one), kubectl will be used as fallback.
  • It works in the same way for kustomize or terraform.

Notes: Not all but wrapfcan be used with almost common commands, resource types, filters and options as you usually do with kubectl. The only thing you must respect is the syntax:

wrapf <CMD> <TYPE> <OPTION1>...<OPTIONX> -- <ARG1> ... <ARGX>