Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
update with new gateway api
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Sep 25, 2024
1 parent de36972 commit 96a56e3
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 137 deletions.
77 changes: 59 additions & 18 deletions neon-postgres-demo/obd-demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,6 @@ spec:
appProtocol: HTTP
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: frontend-external
annotations:
kardinal.dev.service/ingress: "true"
kardinal.dev.service/host: "prod.app.localhost"
spec:
type: LoadBalancer
selector:
app: frontend
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
appProtocol: HTTP
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -251,3 +233,62 @@ spec:
targetPort: 8070
protocol: TCP
appProtocol: HTTP

---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway
annotations:
kardinal.dev.service/gateway: "true"
spec:
gatewayClassName: istio
listeners:
- name: default
hostname: "*.app.localhost"
port: 8888
protocol: HTTP
allowedRoutes:
namespaces:
from: All

---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http
annotations:
kardinal.dev.service/route: "true"
spec:
parentRefs:
- name: gateway
hostnames: ["prod.app.localhost"]
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: frontend
port: 80

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
kardinal.dev.service/ingress: "true"
name: ingress
spec:
rules:
- host: web.other.localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 80
238 changes: 119 additions & 119 deletions scripts/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,179 +8,179 @@ KARDINAL_CLI_PATH=""
KARDINAL_DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/kardinal"
UUID_FILE="$KARDINAL_DATA_DIR/fk-tenant-uuid"


# Spinning cursor animation
spinner() {
local pid=$1
local delay=0.1
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
local pid=$1
local delay=0.1
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}

log() {
echo "$1"
echo "$1"
}

log_verbose() {
if $VERBOSE; then
echo "$1"
fi
if $VERBOSE; then
echo "$1"
fi
}

log_error() {
echo "❌ Error: $1" >&2
echo "Please email us at [email protected] for assistance." >&2
exit 1
echo "❌ Error: $1" >&2
echo "Please email us at [email protected] for assistance." >&2
exit 1
}

run_command_with_spinner() {
if $VERBOSE; then
"$@"
else
"$@" >/dev/null 2>&1 &
local pid=$!
spinner $pid
wait $pid
return $?
fi
if $VERBOSE; then
"$@"
else
"$@" >/dev/null 2>&1 &
local pid=$!
spinner $pid
wait $pid
return $?
fi
}

setup_docker() {
log "🐳 Setting up Docker..."
while ! run_command_with_spinner docker info; do
sleep 1
done
log_verbose "Docker is running."
sleep 3
log "🐳 Setting up Docker..."
while ! run_command_with_spinner docker info; do
sleep 1
done
log_verbose "Docker is running."
sleep 3
}

start_minikube() {
log "🚀 Starting Minikube..."
total_memory=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
total_memory_mb=$((total_memory / 1024))
run_command_with_spinner minikube start --driver=docker --cpus=$(nproc) --memory $total_memory_mb --disk-size 32g || log_error "Failed to start Minikube"
run_command_with_spinner minikube addons enable ingress
run_command_with_spinner minikube addons enable metrics-server
run_command_with_spinner kubectl config set-context minikube
log_verbose "Minikube started successfully."
log "🚀 Starting Minikube..."
total_memory=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
total_memory_mb=$((total_memory / 1024))
run_command_with_spinner minikube start --driver=docker --cpus=$(nproc) --memory $total_memory_mb --disk-size 32g || log_error "Failed to start Minikube"
run_command_with_spinner minikube addons enable ingress
run_command_with_spinner minikube addons enable metrics-server
run_command_with_spinner kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.1.0/standard-install.yaml
run_command_with_spinner kubectl config set-context minikube
log_verbose "Minikube started successfully."
}

install_istio() {
log "🌐 Installing Istio..."
run_command_with_spinner sh -c 'curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.22.1 TARGET_ARCH=x86_64 sh -' || log_error "Failed to download Istio"
cd istio-1.22.1
export PATH=$PWD/bin:$PATH
echo 'export PATH=$PATH:'"$PWD/bin" >> ~/.bashrc
run_command_with_spinner istioctl install --set profile=demo -y || log_error "Failed to install Istio"
cd ..
log_verbose "Istio installed successfully."
log "🌐 Installing Istio..."
run_command_with_spinner sh -c 'curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.22.1 TARGET_ARCH=x86_64 sh -' || log_error "Failed to download Istio"
cd istio-1.22.1
export PATH=$PWD/bin:$PATH
echo 'export PATH=$PATH:'"$PWD/bin" >>~/.bashrc
run_command_with_spinner istioctl install --set profile=minimal -y || log_error "Failed to install Istio"
cd ..
log_verbose "Istio installed successfully."
}

setup_kardinal_cli() {
log "🛠️ Setting up Kardinal CLI..."
log "🛠️ Setting up Kardinal CLI..."

# Install Kardinal CLI using curl, skip interactive post-install steps
curl get.kardinal.dev -sL | env SKIP_KARDINAL_POST_INSTALL=1 sh || true
# Install Kardinal CLI using curl, skip interactive post-install steps
curl get.kardinal.dev -sL | env SKIP_KARDINAL_POST_INSTALL=1 sh || true

# Ensure the Kardinal data directory exists
mkdir -p "$KARDINAL_DATA_DIR"
# Ensure the Kardinal data directory exists
mkdir -p "$KARDINAL_DATA_DIR"

# Find the kardinal CLI path
KARDINAL_CLI_PATH=$(which kardinal)
# Find the kardinal CLI path
KARDINAL_CLI_PATH=$(which kardinal)

if [ -z "$KARDINAL_CLI_PATH" ]; then
log_error "Failed to find kardinal CLI after installation"
return 1
fi
if [ -z "$KARDINAL_CLI_PATH" ]; then
log_error "Failed to find kardinal CLI after installation"
return 1
fi

log "✅ Kardinal CLI installed successfully. You can now use the 'kardinal' command directly."
log_verbose "Kardinal CLI setup completed. The 'kardinal' command is now available at $KARDINAL_CLI_PATH."
log "✅ Kardinal CLI installed successfully. You can now use the 'kardinal' command directly."
log_verbose "Kardinal CLI setup completed. The 'kardinal' command is now available at $KARDINAL_CLI_PATH."
}

deploy_kardinal_manager() {
log "🚀 Deploying Kardinal Manager..."
log "🚀 Deploying Kardinal Manager..."

local kube_config="${HOME}/.kube/config"
local minikube_dir="${HOME}/.minikube"
local kube_config="${HOME}/.kube/config"
local minikube_dir="${HOME}/.minikube"

# Check if the Kubernetes config file exists
if [ ! -f "$kube_config" ]; then
log_error "Kubernetes config file not found at $kube_config"
return 1
fi
# Check if the Kubernetes config file exists
if [ ! -f "$kube_config" ]; then
log_error "Kubernetes config file not found at $kube_config"
return 1
fi

# Check if the Minikube directory exists
if [ ! -d "$minikube_dir" ]; then
log_error "Minikube directory not found at $minikube_dir"
return 1
fi
# Check if the Minikube directory exists
if [ ! -d "$minikube_dir" ]; then
log_error "Minikube directory not found at $minikube_dir"
return 1
fi

log_verbose "About to run kardinal command to deploy manager..."
log_verbose "About to run kardinal command to deploy manager..."

# Run the kardinal command with spinner
run_command_with_spinner kardinal manager deploy kloud-kontrol
# Run the kardinal command with spinner
run_command_with_spinner kardinal manager deploy kloud-kontrol

log_verbose "Kardinal command to deploy manager completed successfully"
log "👩‍💼 Kardinal Manager Deployed"
log_verbose "Kardinal command to deploy manager completed successfully"
log "👩‍💼 Kardinal Manager Deployed"

# Run the kardinal command for voting app deployment with spinner
run_command_with_spinner kardinal deploy -k obd-demo.yaml
# Run the kardinal command for voting app deployment with spinner
run_command_with_spinner kardinal deploy -k obd-demo.yaml

log "🗳️ Initial version of voting app deployed"
log "🗳️ Initial version of voting app deployed"

# Extract the Tenant UUID from the UUID file
if [ ! -f "$UUID_FILE" ]; then
log_error "UUID file not found at $UUID_FILE after deployment"
return 1
fi
# Extract the Tenant UUID from the UUID file
if [ ! -f "$UUID_FILE" ]; then
log_error "UUID file not found at $UUID_FILE after deployment"
return 1
fi

TENANT_UUID=$(cat "$UUID_FILE")
log_verbose "Kardinal Manager deployed successfully with Tenant UUID: $TENANT_UUID"
TENANT_UUID=$(cat "$UUID_FILE")
log_verbose "Kardinal Manager deployed successfully with Tenant UUID: $TENANT_UUID"
}

silent_segment_track() {
local username="${GITHUB_USER}"
if [ -z "$username" ]; then
echo "Error: GITHUB_USER environment variable is not set" >&2
return 1
fi

curl -s -o /dev/null --location 'https://api.segment.io/v1/track' \
--header 'Content-Type: application/json' \
--data-raw '{
local username="${GITHUB_USER}"
if [ -z "$username" ]; then
echo "Error: GITHUB_USER environment variable is not set" >&2
return 1
fi

curl -s -o /dev/null --location 'https://api.segment.io/v1/track' \
--header 'Content-Type: application/json' \
--data-raw '{
"event": "start_codespace_demo",
"userId": "'"$username"'",
"writeKey": "UgpQTmrrzwTVdW4oDSPUlZRvjZ3CQJuj"
}'
}

main() {
# Check if an argument is provided
if [ $# -gt 0 ] && [ "$1" = "--verbose" ]; then
VERBOSE=true
log "Verbose mode enabled."
fi

log "🕰️ This can take around 3 minutes! Familiarize yourself with the repository while this happens."

silent_segment_track
setup_docker
start_minikube
install_istio
setup_kardinal_cli
deploy_kardinal_manager

log "✅ Startup completed! Minikube, Istio, Kontrol, and Kardinal Manager are ready."
log "🏠 Tenant UUID: $TENANT_UUID"
log "📊 Kardinal Dashboard: https://app.kardinal.dev/$(cat ~/.local/share/kardinal/fk-tenant-uuid)/traffic-configuration"
exec bash
# Check if an argument is provided
if [ $# -gt 0 ] && [ "$1" = "--verbose" ]; then
VERBOSE=true
log "Verbose mode enabled."
fi

log "🕰️ This can take around 3 minutes! Familiarize yourself with the repository while this happens."

silent_segment_track
setup_docker
start_minikube
install_istio
setup_kardinal_cli
deploy_kardinal_manager

log "✅ Startup completed! Minikube, Istio, Kontrol, and Kardinal Manager are ready."
log "🏠 Tenant UUID: $TENANT_UUID"
log "📊 Kardinal Dashboard: https://app.kardinal.dev/$(cat ~/.local/share/kardinal/fk-tenant-uuid)/traffic-configuration"
exec bash
}

main "$@"

0 comments on commit 96a56e3

Please sign in to comment.