Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. die() {
  3. echo "$*" 1>&2
  4. exit 1
  5. }
  6. need() {
  7. command -v "$1" &>/dev/null || die "Binary '$1' is missing but required"
  8. }
  9.  
  10. need "kubectl"
  11.  
  12. echo "------------------------------------------------"
  13. echo "get all resources in namespace..."
  14. echo "------------------------------------------------"
  15. FOUND=""
  16. NOT_FOUND=""
  17. ERROR=""
  18. RESOURCES=$(kubectl api-resources --namespaced=true -o name)
  19. for resource in $RESOURCES; do
  20. if [[ $resource =~ "metrics" ]]; then
  21. continue
  22. fi
  23.  
  24. found=$(kubectl get "$resource" 2>&1)
  25. if [[ "$found" == "No resources found." ]]; then
  26. echo "$resource: $found"
  27. NOT_FOUND="$NOT_FOUND\n$resource"
  28. elif [[ $found =~ "Error" ]]; then
  29. echo "$resource: $found"
  30. ERROR="$ERROR\n$resource"
  31. else
  32. printf ">> %s:\n%s" "$resource" "$found"
  33. FOUND="$FOUND\n$resource"
  34. fi
  35. done
  36.  
  37. echo "------------------------------------------------"
  38. echo "summary"
  39. echo "------------------------------------------------"
  40. printf ">> found: %b\n" "$FOUND"
  41. echo "------------------------------------------------"
  42. printf ">> not found: %b\n" "$NOT_FOUND"
  43. echo "------------------------------------------------"
  44. printf ">> error: %b\n" "$ERROR"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement