Add undeploy script and ensure namespace function for Kubernetes management
This commit is contained in:
@@ -94,17 +94,34 @@ validate_env() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to ensure namespace exists
|
||||
ensure_namespace() {
|
||||
if ! kubectl get namespace "$NAMESPACE" &> /dev/null; then
|
||||
print_info "Creating namespace: $NAMESPACE"
|
||||
kubectl create namespace "$NAMESPACE"
|
||||
print_success "Created namespace: $NAMESPACE"
|
||||
else
|
||||
print_info "Using existing namespace: $NAMESPACE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to apply Kubernetes manifests
|
||||
apply_manifests() {
|
||||
local manifest_dir="$1"
|
||||
|
||||
print_info "Applying Kubernetes manifests from $manifest_dir"
|
||||
|
||||
# Apply non-template files first
|
||||
# Apply static files that don't have template counterparts
|
||||
for manifest_file in "$K8S_DIR"/*.yaml; do
|
||||
if [[ -f "$manifest_file" && ! "$manifest_file" =~ \.template$ ]]; then
|
||||
print_info "Applying: $(basename "$manifest_file")"
|
||||
kubectl apply -f "$manifest_file"
|
||||
local basename_file=$(basename "$manifest_file")
|
||||
local template_file="$K8S_DIR/${basename_file}.template"
|
||||
|
||||
# Only apply if there's no corresponding template file
|
||||
if [[ ! -f "$template_file" ]]; then
|
||||
print_info "Applying static file: $basename_file"
|
||||
kubectl apply -f "$manifest_file" -n "$NAMESPACE"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -112,8 +129,8 @@ apply_manifests() {
|
||||
if [[ -d "$TEMP_DIR" ]]; then
|
||||
for manifest_file in "$TEMP_DIR"/*.yaml; do
|
||||
if [[ -f "$manifest_file" ]]; then
|
||||
print_info "Applying: $(basename "$manifest_file")"
|
||||
kubectl apply -f "$manifest_file"
|
||||
print_info "Applying template: $(basename "$manifest_file")"
|
||||
kubectl apply -f "$manifest_file" -n "$NAMESPACE"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -133,15 +150,15 @@ show_status() {
|
||||
echo ""
|
||||
|
||||
print_info "Pods:"
|
||||
kubectl get pods -l app=rxminder
|
||||
kubectl get pods -l app=rxminder -n "$NAMESPACE"
|
||||
echo ""
|
||||
|
||||
print_info "Services:"
|
||||
kubectl get services -l app=rxminder
|
||||
kubectl get services -l app=rxminder -n "$NAMESPACE"
|
||||
echo ""
|
||||
|
||||
print_info "Ingress:"
|
||||
kubectl get ingress -l app=rxminder
|
||||
kubectl get ingress -l app=rxminder -n "$NAMESPACE"
|
||||
echo ""
|
||||
|
||||
if [[ -n "${INGRESS_HOST:-}" ]]; then
|
||||
@@ -236,9 +253,15 @@ main() {
|
||||
# Load environment variables
|
||||
load_env "$env_file"
|
||||
|
||||
# Set default namespace if not provided in environment
|
||||
NAMESPACE="${NAMESPACE:-rxminder}"
|
||||
|
||||
# Validate required environment variables
|
||||
validate_env
|
||||
|
||||
# Ensure namespace exists
|
||||
ensure_namespace
|
||||
|
||||
# Process templates
|
||||
substitute_templates
|
||||
|
||||
|
||||
Reference in New Issue
Block a user