Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Variáveis de ambiente
- # O nome do cluster Kubernetes
- export KUBECONFIG=/path/to/kubeconfig
- # O namespace do Kubernetes
- export NAMESPACE=default
- # Função para exibir mensagens de erro e encerrar o script
- error_exit() {
- echo "$1" >&2
- exit 1
- }
- # Função para validar o nome do deployment
- validate_deployment_name() {
- local deployment_name="$1"
- if [[ ! "$deployment_name" =~ ^[a-z0-9-]+$ ]]; then
- error_exit "O nome do deployment deve conter apenas letras minúsculas, números e hífens."
- fi
- }
- # Função para criar um Deployment
- create_deployment() {
- local deployment_name="$1"
- local image_name="$2"
- validate_deployment_name "$deployment_name"
- kubectl create deployment "$deployment_name" --image="$image_name" --namespace="$NAMESPACE"
- }
- # Função para deletar um Deployment
- delete_deployment() {
- local deployment_name="$1"
- kubectl delete deployment "$deployment_name" --namespace="$NAMESPACE"
- }
- # Função principal
- main() {
- local operation="$1"
- local deployment_name="$2"
- local image_name="$3"
- # Verifica se o número correto de argumentos foi fornecido
- if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
- error_exit "Uso: $0 <create/delete> <deployment_name> [image_name]"
- fi
- # Chama a função apropriada
- case "$operation" in
- "create")
- create_deployment "$deployment_name" "$image_name"
- ;;
- "delete")
- delete_deployment "$deployment_name"
- ;;
- *)
- error_exit "Uso: $0 <create/delete> <deployment_name> [image_name]"
- ;;
- esac
- }
- # Chama a função principal com os argumentos passados para o script
- main "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement