Skip to content

Instantly share code, notes, and snippets.

@mesuutt
Last active November 4, 2022 11:18
Show Gist options
  • Save mesuutt/3a18f848479a613b01952dfe23f61837 to your computer and use it in GitHub Desktop.
Save mesuutt/3a18f848479a613b01952dfe23f61837 to your computer and use it in GitHub Desktop.

Revisions

  1. mesuutt revised this gist Nov 4, 2022. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion rename-kubeconfigs.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,22 @@
    #!/bin/bash

    # exit on error
    set -e

    CONF_DIR=~/.kube/config.d

    for f in $CONF_DIR/*.yml; do

    require() {
    if ! hash "$1" &>/dev/null; then
    echo "'$1' not found in PATH"
    exit 1
    fi
    }


    require yq

    for f in $CONF_DIR/*.{yml,conf}; do
    name=$(cat $f | yq -r '.clusters[0].name')
    if [[ ! "$name" == "null" ]]; then
    echo "$f === $name"
  2. mesuutt created this gist Sep 12, 2022.
    11 changes: 11 additions & 0 deletions rename-kubeconfigs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/bin/bash

    CONF_DIR=~/.kube/config.d

    for f in $CONF_DIR/*.yml; do
    name=$(cat $f | yq -r '.clusters[0].name')
    if [[ ! "$name" == "null" ]]; then
    echo "$f === $name"
    mv $f "$CONF_DIR/$name.yml"
    fi
    done