Add new infra architecture 11
This commit is contained in:
@@ -96,7 +96,10 @@ is_registry_running() {
|
||||
# Function to handle cleanup with better error handling
|
||||
cleanup() {
|
||||
print_status "Starting cleanup process..."
|
||||
|
||||
|
||||
# Ensure correct Docker context is used
|
||||
ensure_docker_context
|
||||
|
||||
# Delete Kubernetes namespace with timeout
|
||||
print_status "Deleting namespace $NAMESPACE..."
|
||||
if kubectl get namespace "$NAMESPACE" &>/dev/null; then
|
||||
@@ -390,10 +393,81 @@ EOF
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to configure Docker daemon inside Colima with insecure registries
|
||||
configure_docker_daemon() {
|
||||
print_status "Configuring Docker daemon with cgroup driver..."
|
||||
|
||||
# Create a temporary file with the Docker daemon configuration
|
||||
local temp_config=$(mktemp)
|
||||
cat > "$temp_config" << 'DOCKERCONFIG'
|
||||
{
|
||||
"exec-opts": ["native.cgroupdriver=cgroupfs"],
|
||||
"features": {
|
||||
"buildkit": true,
|
||||
"containerd-snapshotter": true
|
||||
}
|
||||
}
|
||||
DOCKERCONFIG
|
||||
|
||||
# Copy the configuration to Colima VM using stdin
|
||||
if cat "$temp_config" | colima --profile "$COLIMA_PROFILE" ssh -- sudo tee /etc/docker/daemon.json > /dev/null; then
|
||||
print_success "Docker daemon configuration written"
|
||||
rm -f "$temp_config"
|
||||
|
||||
# Restart Docker service to apply the configuration
|
||||
print_status "Restarting Docker service to apply configuration..."
|
||||
if colima --profile "$COLIMA_PROFILE" ssh -- sudo systemctl restart docker; then
|
||||
print_success "Docker service restarted successfully"
|
||||
|
||||
# Wait for Docker to be ready
|
||||
sleep 3
|
||||
|
||||
return 0
|
||||
else
|
||||
print_error "Failed to restart Docker service"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "Failed to write Docker daemon configuration"
|
||||
rm -f "$temp_config"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to ensure correct Docker context is used
|
||||
ensure_docker_context() {
|
||||
if ! docker version >/dev/null 2>&1; then
|
||||
print_warning "Docker daemon is not accessible, attempting to set correct context..."
|
||||
|
||||
if is_colima_running; then
|
||||
# Look for the correct Colima Docker context
|
||||
COLIMA_CONTEXT=$(docker context ls --format='{{.Name}}' | grep -E "^colima($|-[[:alnum:]_-]+)" | head -1)
|
||||
|
||||
if [ -n "$COLIMA_CONTEXT" ]; then
|
||||
print_status "Switching Docker context to $COLIMA_CONTEXT"
|
||||
docker context use "$COLIMA_CONTEXT" >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Docker context switched to $COLIMA_CONTEXT"
|
||||
sleep 2 # Give Docker a moment to establish connection
|
||||
else
|
||||
print_error "Failed to switch Docker context to $COLIMA_CONTEXT"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
print_error "No Colima Docker context found. Please ensure Colima is properly configured."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to handle setup with better error handling
|
||||
setup() {
|
||||
print_status "Starting setup process..."
|
||||
|
||||
|
||||
# Ensure correct Docker context is used
|
||||
ensure_docker_context
|
||||
|
||||
# Check for required config files
|
||||
check_config_files
|
||||
|
||||
@@ -406,38 +480,8 @@ setup() {
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Colima started successfully"
|
||||
|
||||
# Configure Docker daemon with cgroup driver and insecure registries
|
||||
print_status "Configuring Docker daemon with cgroup driver and insecure registries..."
|
||||
cat << 'EOFCMD' | colima --profile k8s-local ssh
|
||||
sudo tee /etc/docker/daemon.json << 'EOF'
|
||||
{
|
||||
"exec-opts": [
|
||||
"native.cgroupdriver=cgroupfs"
|
||||
],
|
||||
"features": {
|
||||
"buildkit": true,
|
||||
"containerd-snapshotter": true
|
||||
},
|
||||
"insecure-registries": ["registry.bakery-ia.local"]
|
||||
}
|
||||
EOF
|
||||
EOFCMD
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Docker daemon configured successfully"
|
||||
|
||||
# Restart Docker service to apply the configuration
|
||||
print_status "Restarting Docker service to apply configuration..."
|
||||
colima --profile k8s-local ssh sudo systemctl restart docker
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Docker service restarted successfully"
|
||||
else
|
||||
print_error "Failed to restart Docker service"
|
||||
fi
|
||||
else
|
||||
print_error "Failed to configure Docker daemon"
|
||||
fi
|
||||
# Configure Docker daemon with insecure registries
|
||||
configure_docker_daemon
|
||||
else
|
||||
print_error "Failed to start Colima"
|
||||
print_status "Checking Colima status..."
|
||||
@@ -447,40 +491,10 @@ EOFCMD
|
||||
else
|
||||
print_success "Colima is already running"
|
||||
|
||||
# Configure Docker daemon with cgroup driver and insecure registries even if Colima was already running
|
||||
print_status "Configuring Docker daemon with cgroup driver and insecure registries..."
|
||||
cat << 'EOFCMD' | colima --profile k8s-local ssh
|
||||
sudo tee /etc/docker/daemon.json << 'EOF'
|
||||
{
|
||||
"exec-opts": [
|
||||
"native.cgroupdriver=cgroupfs"
|
||||
],
|
||||
"features": {
|
||||
"buildkit": true,
|
||||
"containerd-snapshotter": true
|
||||
},
|
||||
"insecure-registries": ["registry.bakery-ia.local"]
|
||||
}
|
||||
EOF
|
||||
EOFCMD
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Docker daemon configured successfully"
|
||||
|
||||
# Restart Docker service to apply the configuration
|
||||
print_status "Restarting Docker service to apply configuration..."
|
||||
colima --profile k8s-local ssh sudo systemctl restart docker
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Docker service restarted successfully"
|
||||
else
|
||||
print_error "Failed to restart Docker service"
|
||||
fi
|
||||
else
|
||||
print_error "Failed to configure Docker daemon"
|
||||
fi
|
||||
# Configure Docker daemon with insecure registries even if Colima was already running
|
||||
configure_docker_daemon
|
||||
fi
|
||||
|
||||
|
||||
# 2. Create local registry before Kind cluster
|
||||
create_local_registry
|
||||
|
||||
@@ -687,6 +701,45 @@ check_prerequisites() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if Docker daemon is accessible
|
||||
if ! docker version >/dev/null 2>&1; then
|
||||
print_warning "Docker daemon is not accessible with current context"
|
||||
|
||||
# Check if Colima is running and try to set Docker context accordingly
|
||||
if is_colima_running; then
|
||||
print_status "Colima is running, checking for correct Docker context..."
|
||||
|
||||
# Look for the correct Colima Docker context
|
||||
COLIMA_CONTEXT=$(docker context ls --format='{{.Name}}' | grep -E "^colima($|-[[:alnum:]_-]+)" | head -1)
|
||||
|
||||
if [ -n "$COLIMA_CONTEXT" ]; then
|
||||
print_status "Switching Docker context to $COLIMA_CONTEXT"
|
||||
docker context use "$COLIMA_CONTEXT" >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Docker context switched to $COLIMA_CONTEXT"
|
||||
else
|
||||
print_error "Failed to switch Docker context to $COLIMA_CONTEXT"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
print_error "No Colima Docker context found. Please ensure Colima is properly configured."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
print_warning "Docker daemon is not running and Colima is not running. Will start Colima during setup."
|
||||
# For setup operations, we can continue without Docker being accessible yet
|
||||
# since Colima will be started as part of the setup process
|
||||
if [[ "${1:-full}" == "setup" ]]; then
|
||||
print_status "Continuing with setup since this is a setup operation..."
|
||||
elif [[ "${1:-full}" == "full" ]]; then
|
||||
print_status "Continuing with full operation (cleanup + setup)..."
|
||||
else
|
||||
print_error "Docker daemon is not running and Colima is not running. Please start Docker or Colima first."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
print_success "All prerequisites are met"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user