Verified Commit 70913c81 authored by Xueshan Feng's avatar Xueshan Feng
Browse files

added kube_*

parent 1792b364
Loading
Loading
Loading
Loading

functions.sh

0 → 120000
+1 −0
Original line number Diff line number Diff line
utils/functions.sh
 No newline at end of file

kube_apply.sh

0 → 100755
+36 −0
Original line number Diff line number Diff line
#!/bin/bash

###############################################################################
# apply resource definitions from list of input templates
###############################################################################

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PATH="${THIS_DIR}:${PATH}"

# include functions
source $THIS_DIR/functions.sh
source env.sh

# fail on error or undeclared vars
trap_errors

# optional vars
set +u
debug_gomplate=$debug_gomplate
set -u

template_files=$@

echo applying kubernetes resources with templates:
for template in $template_files; do
  echo "   $template"
  if [[ $template == *'.gomplate.'* ]]; then
    if [ "$debug_gomplate" = "true" ]; then
      gomplate.sh < $template
    else
      gomplate.sh < $template | kubectl apply -f -
    fi
  else
    cat $template | envsubst | kubectl apply -f -
  fi
done

kube_delete.sh

0 → 100755
+37 −0
Original line number Diff line number Diff line
#!/bin/bash

###############################################################################
# delete resources from list of input templates
###############################################################################

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PATH="${THIS_DIR}:${PATH}"

# include functions
source $THIS_DIR/functions.sh
source env.sh

# fail on error or undeclared vars
trap_errors

# optional vars
set +u
debug_gomplate=$debug_gomplate
set -u

template_files=$@

echo deleting kubernetes resources with templates:
for template in $template_files; do
  echo "   $template"
  # don't fail if resource exists
  if [[ $template == *'.gomplate.'* ]]; then
    if [ "$debug_gomplate" = "true" ]; then
      gomplate.sh < $template
    else
      gomplate.sh < $template | kubectl delete --ignore-not-found -f - || true
    fi
  else
    cat $template | envsubst | kubectl delete --ignore-not-found -f - || true
  fi
done

show-kube-cert.sh

0 → 100755
+34 −0
Original line number Diff line number Diff line
#!/bin/bash
# Usage:
#   show-kube-cert.sh [namespace] [secname]
# Show the x509 certificates stored in kubernetes secrets 

if [ -z "$1" ]
then
    sec_ns=default
else
    sec_ns=$1
    shift
fi

if [ -z "$1" ]
then
    sec_names=$(kubectl get secrets -o json  -n ${sec_ns} | jq -r '.items[].metadata.name')
else 
    sec_names=$*
fi

for sec in $sec_names
do
    crt=$(kubectl get secret -n ${sec_ns} ${sec} -o json | jq -r '.data."tls.crt"')
    if [ "null" != "${crt}" ] ; then
        echo  ========================= ${sec} ==============================
        echo $crt | base64 --decode \
            | openssl x509 -text \
            | sed '/BEGIN CERTIFICATE/,/END CERTIFICATE/d' \
            | sed '/Public Key Info/,/Exponent:/d' \
            | sed '/X509v3 Certificate Policies/,$d'
        echo  ========================= ${sec} ==============================
        echo
    fi
done
 No newline at end of file