#!/bin/bash

batch_delete_pod() {
  local namespace=$1
  local app_name_prefix=$2
  if [ $namespace == "" ]; then
    echo "namespace is null"
    return
  fi
  if [ $app_name_prefix == "" ]; then
    echo "app_name_prefix is null"
    return
  fi

  local app_pod_list=$(kubectl -n "$namespace" get pods -A | grep "$app_name_prefix" | awk '{print$2}'| tr "\n" "  " )

  for app in "${app_pod_list[@]}"; do
      echo "app is ${app}"
      kubectl -n "$namespace" delete pod $app
  done

}

batch_delete_pod kube-system flannel
