executable_netshoot 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env -S guile --no-auto-compile -e main -s
  2. !#
  3. (use-modules (json)
  4. (srfi srfi-1)
  5. (srfi srfi-37)
  6. (guix scripts))
  7. (define %labels
  8. '(("app.kubernetes.io/name" . "netshoot")))
  9. (define %options
  10. (list
  11. (option '(#\d "dry-run") #f #f
  12. (lambda (opt name arg result)
  13. (values (alist-cons 'dry-run? #t result)
  14. #f)))
  15. (option '(#\n "namespace") #t #f
  16. (lambda (opt name arg result)
  17. (alist-cons 'namespace arg result)))
  18. (option '(#\H "host") #t #f
  19. (lambda (opt name arg result)
  20. (alist-cons 'host arg result)))))
  21. (define %default-options
  22. '(()))
  23. (define (main args)
  24. (define opts
  25. (parse-command-line args %options
  26. (list %default-options)))
  27. (define dry-run? (assoc-ref opts 'dry-run?))
  28. (define namespace (assoc-ref opts 'namespace))
  29. (define host (assoc-ref opts 'host))
  30. (apply system*
  31. `(,@(if dry-run? '("echo") '())
  32. "kubectl"
  33. "run"
  34. "--rm=true"
  35. "--stdin=true"
  36. "--tty=true"
  37. ,@(if namespace
  38. (list (string-append "--namespace=" namespace))
  39. '())
  40. ,(string-append "--labels="
  41. (string-join
  42. (map (lambda (label)
  43. (string-append (first label)
  44. "="
  45. (cdr label)))
  46. %labels)
  47. ","))
  48. ,@(if host
  49. (list
  50. (string-concatenate
  51. (list
  52. "--overrides="
  53. (scm->json-string
  54. `(("spec"
  55. ("tolerations"
  56. .
  57. #((("effect" . "NoSchedule")
  58. ("value" . "true")
  59. ("operator" . "Equal")
  60. ("key" . "unschedulable"))))
  61. ("nodeSelector"
  62. ("kubernetes.io/hostname" . ,host)))
  63. ("apiVersion" . "v1"))))))
  64. '())
  65. "netshoot"
  66. "--image=nicolaka/netshoot"
  67. "/bin/bash")))