Clean up repository - remove unnecessary files and simplify S2I

- Remove deploy-s2i-simple.sh (duplicate functionality)
- Remove openshift-s2i.yaml template (unnecessary complexity)
- Simplify deploy-s2i.sh to single script approach
- Reduce repository clutter and maintenance overhead
- Keep only essential scripts: deploy-s2i.sh, deploy-complete.sh, build-and-push.sh, undeploy-complete.sh
- Maintain clean, focused codebase
This commit is contained in:
2025-10-04 09:11:36 -03:00
parent 4eec703cba
commit 5ceb421a3c
3 changed files with 57 additions and 579 deletions

View File

@@ -1,320 +0,0 @@
# OpenShift S2I Template for ORU Analyzer
# Source-to-Image deployment configuration
apiVersion: template.openshift.io/v1
kind: Template
metadata:
name: oru-analyzer-s2i
annotations:
description: "ORU Analyzer - OpenShift Resource Usage Analyzer (S2I)"
tags: "python,fastapi,openshift,resource-governance,monitoring"
iconClass: "icon-python"
openshift.io/display-name: "ORU Analyzer (S2I)"
openshift.io/long-description: "OpenShift Resource Usage Analyzer using Source-to-Image"
openshift.io/provider-display-name: "Red Hat"
openshift.io/documentation-url: "https://github.com/andersonid/openshift-resource-governance"
openshift.io/support-url: "https://github.com/andersonid/openshift-resource-governance/issues"
parameters:
- name: NAME
displayName: "Application Name"
description: "The name assigned to all of the frontend objects defined in this template."
value: "oru-analyzer"
required: true
- name: NAMESPACE
displayName: "Namespace"
description: "The OpenShift Namespace where the ImageStream resides."
value: "resource-governance"
required: true
- name: GIT_REPOSITORY
displayName: "Git Repository URL"
description: "The URL of the repository with your application source code."
value: "https://github.com/andersonid/openshift-resource-governance.git"
required: true
- name: GIT_REF
displayName: "Git Reference"
description: "Set this to a branch name, tag or other ref of your repository if you are not using the default branch."
value: "main"
required: true
- name: PYTHON_VERSION
displayName: "Python Version"
description: "Version of Python to use."
value: "3.11"
required: true
- name: CPU_REQUEST
displayName: "CPU Request"
description: "The amount of CPU to request for the container."
value: "50m"
required: true
- name: CPU_LIMIT
displayName: "CPU Limit"
description: "The amount of CPU to limit the container to."
value: "200m"
required: true
- name: MEMORY_REQUEST
displayName: "Memory Request"
description: "The amount of memory to request for the container."
value: "64Mi"
required: true
- name: MEMORY_LIMIT
displayName: "Memory Limit"
description: "The amount of memory to limit the container to."
value: "256Mi"
required: true
- name: REPLICAS
displayName: "Number of Replicas"
description: "Number of replicas to run."
value: "1"
required: true
- name: ROUTE_HOSTNAME
displayName: "Route Hostname"
description: "The hostname for the route. Leave blank for auto-generated hostname."
value: ""
required: false
objects:
# ImageStream for the application
- apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: ${NAME}
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
spec:
lookupPolicy:
local: false
# BuildConfig for S2I
- apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: ${NAME}
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
spec:
source:
type: Git
git:
uri: ${GIT_REPOSITORY}
ref: ${GIT_REF}
contextDir: /
strategy:
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
namespace: openshift
name: python:${PYTHON_VERSION}
env:
- name: PYTHON_VERSION
value: ${PYTHON_VERSION}
- name: PIP_INDEX_URL
value: "https://pypi.org/simple"
output:
to:
kind: ImageStreamTag
name: ${NAME}:latest
triggers:
- type: ConfigChange
- type: ImageChange
imageChange: {}
# Service
- apiVersion: v1
kind: Service
metadata:
name: ${NAME}
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
spec:
ports:
- name: http
port: 8080
targetPort: 8080
protocol: TCP
selector:
app: ${NAME}
component: backend
# DeploymentConfig
- apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
name: ${NAME}
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
spec:
replicas: ${REPLICAS}
selector:
app: ${NAME}
component: backend
template:
metadata:
labels:
app: ${NAME}
component: backend
spec:
containers:
- name: ${NAME}
image: ${NAME}:latest
ports:
- containerPort: 8080
protocol: TCP
env:
- name: PYTHON_VERSION
value: ${PYTHON_VERSION}
- name: HOST
value: "0.0.0.0"
- name: PORT
value: "8080"
- name: WORKERS
value: "1"
resources:
requests:
cpu: ${CPU_REQUEST}
memory: ${MEMORY_REQUEST}
limits:
cpu: ${CPU_LIMIT}
memory: ${MEMORY_LIMIT}
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
timeoutSeconds: 10
periodSeconds: 30
failureThreshold: 3
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 10
failureThreshold: 3
triggers:
- type: ConfigChange
- type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- ${NAME}
from:
kind: ImageStreamTag
name: ${NAME}:latest
# Route
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${NAME}
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
spec:
host: ${ROUTE_HOSTNAME}
to:
kind: Service
name: ${NAME}
weight: 100
port:
targetPort: 8080
tls:
termination: edge
insecureEdgeTerminationPolicy: Redirect
# ServiceAccount
- apiVersion: v1
kind: ServiceAccount
metadata:
name: ${NAME}-sa
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
# Role
- apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: ${NAME}-role
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
rules:
- apiGroups: [""]
resources: ["pods", "namespaces", "nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
resources: ["deployments", "replicasets"]
verbs: ["get", "list", "watch", "patch", "update"]
- apiGroups: ["autoscaling.k8s.io"]
resources: ["verticalpodautoscalers"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: [""]
resources: ["services", "endpoints"]
verbs: ["get", "list", "watch"]
# RoleBinding
- apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ${NAME}-rolebinding
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
subjects:
- kind: ServiceAccount
name: ${NAME}-sa
namespace: ${NAMESPACE}
roleRef:
kind: Role
name: ${NAME}-role
apiGroup: rbac.authorization.k8s.io
# ConfigMap
- apiVersion: v1
kind: ConfigMap
metadata:
name: ${NAME}-config
namespace: ${NAMESPACE}
labels:
app: ${NAME}
component: backend
data:
CPU_LIMIT_RATIO: "3.0"
MEMORY_LIMIT_RATIO: "3.0"
MIN_CPU_REQUEST: "10m"
MIN_MEMORY_REQUEST: "32Mi"
CRITICAL_NAMESPACES: |
openshift-monitoring
openshift-ingress
openshift-apiserver
openshift-controller-manager
openshift-sdn
PROMETHEUS_URL: "https://prometheus-k8s.openshift-monitoring.svc.cluster.local:9091"
LOG_LEVEL: "INFO"
HOST: "0.0.0.0"
PORT: "8080"
WORKERS: "1"

View File

@@ -1,65 +0,0 @@
#!/bin/bash
# Ultra-simple S2I deployment - just run this one command!
set -e
echo "🚀 Ultra-Simple ORU Analyzer S2I Deployment"
echo "============================================="
# Check if logged in
if ! oc whoami >/dev/null 2>&1; then
echo "❌ Not logged in to OpenShift. Please run 'oc login' first"
exit 1
fi
# Create namespace
echo "📦 Creating namespace..."
oc new-project resource-governance 2>/dev/null || echo "Namespace already exists"
# Deploy with oc new-app (super simple!)
echo "🚀 Deploying with oc new-app..."
oc new-app python:3.11~https://github.com/andersonid/openshift-resource-governance.git \
--name=oru-analyzer \
--env=PYTHON_VERSION=3.11 \
--env=APP_ROOT=/app
# Configure resources
echo "⚙️ Configuring resources..."
oc patch deploymentconfig/oru-analyzer -p '{
"spec": {
"template": {
"spec": {
"containers": [{
"name": "oru-analyzer",
"resources": {
"requests": {"cpu": "50m", "memory": "64Mi"},
"limits": {"cpu": "200m", "memory": "256Mi"}
}
}]
}
}
}
}'
# Wait for build and deployment
echo "⏳ Waiting for build and deployment..."
oc logs -f buildconfig/oru-analyzer &
BUILD_PID=$!
# Wait for build to complete
oc wait --for=condition=Complete buildconfig/oru-analyzer --timeout=600s
kill $BUILD_PID 2>/dev/null || true
# Wait for deployment
oc rollout status deploymentconfig/oru-analyzer --timeout=300s
# Get URL
ROUTE_URL=$(oc get route oru-analyzer -o jsonpath='{.spec.host}' 2>/dev/null || echo "")
echo ""
echo "✅ Deployment Complete!"
echo "🌐 Application URL: https://$ROUTE_URL"
echo ""
echo "📊 Check status:"
echo " oc get pods -n resource-governance"
echo " oc logs -f deploymentconfig/oru-analyzer -n resource-governance"

View File

@@ -1,213 +1,76 @@
#!/bin/bash #!/bin/bash
# Deploy ORU Analyzer using Source-to-Image (S2I) # Deploy ORU Analyzer using Source-to-Image (S2I)
# Alternative deployment method for OpenShift
set -e set -e
echo "=== ORU Analyzer S2I Deployment Script ===" echo "🚀 ORU Analyzer S2I Deployment"
echo "Deploying ORU Analyzer using Source-to-Image..." echo "==============================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values # Default values
NAMESPACE="resource-governance" NAMESPACE="resource-governance"
APP_NAME="oru-analyzer" APP_NAME="oru-analyzer"
GIT_REPO="https://github.com/andersonid/openshift-resource-governance.git" GIT_REPO="https://github.com/andersonid/openshift-resource-governance.git"
GIT_REF="main"
PYTHON_VERSION="3.11"
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check prerequisites # Check prerequisites
check_prerequisites() { if ! command -v oc >/dev/null 2>&1; then
print_status "Checking prerequisites..." echo "❌ OpenShift CLI (oc) not found. Please install it first."
if ! command_exists oc; then
print_error "OpenShift CLI (oc) is not installed or not in PATH"
exit 1 exit 1
fi fi
# Check if logged in to OpenShift if ! oc whoami >/dev/null 2>&1; then
if ! oc whoami >/dev/null 2>&1; then echo "❌ Not logged in to OpenShift. Please run 'oc login' first"
print_error "Not logged in to OpenShift. Please run 'oc login' first"
exit 1 exit 1
fi fi
print_success "Prerequisites check passed" # Create namespace
} echo "📦 Creating namespace..."
oc new-project "$NAMESPACE" 2>/dev/null || echo "Namespace already exists"
# Create namespace if it doesn't exist # Deploy with oc new-app
create_namespace() { echo "🚀 Deploying with oc new-app..."
print_status "Creating namespace '$NAMESPACE' if it doesn't exist..." oc new-app python:3.11~"$GIT_REPO" \
if oc get namespace "$NAMESPACE" >/dev/null 2>&1; then
print_warning "Namespace '$NAMESPACE' already exists"
else
oc new-project "$NAMESPACE"
print_success "Namespace '$NAMESPACE' created"
fi
}
# Deploy using oc new-app (simpler S2I)
deploy_s2i() {
print_status "Deploying using oc new-app S2I..."
# Use oc new-app for simple S2I deployment
oc new-app python:3.11~"$GIT_REPO" \
--name="$APP_NAME" \ --name="$APP_NAME" \
--env=PYTHON_VERSION=3.11 \ --env=PYTHON_VERSION=3.11 \
--env=APP_ROOT=/app \ --env=APP_ROOT=/app \
--namespace="$NAMESPACE" --namespace="$NAMESPACE"
print_success "S2I application created successfully" # Configure resources
echo "⚙️ Configuring resources..."
# Configure resource requests and limits oc patch deploymentconfig/"$APP_NAME" -p '{
print_status "Configuring resource requests and limits..."
oc patch deploymentconfig/"$APP_NAME" -p '{
"spec": { "spec": {
"template": { "template": {
"spec": { "spec": {
"containers": [{ "containers": [{
"name": "'"$APP_NAME"'", "name": "'"$APP_NAME"'",
"resources": { "resources": {
"requests": { "requests": {"cpu": "50m", "memory": "64Mi"},
"cpu": "50m", "limits": {"cpu": "200m", "memory": "256Mi"}
"memory": "64Mi"
},
"limits": {
"cpu": "200m",
"memory": "256Mi"
}
} }
}] }]
} }
} }
} }
}' }'
print_success "Resource configuration applied" # Wait for build and deployment
} echo "⏳ Waiting for build and deployment..."
oc logs -f buildconfig/"$APP_NAME" &
BUILD_PID=$!
# Wait for build to complete # Wait for build to complete
wait_for_build() { oc wait --for=condition=Complete buildconfig/"$APP_NAME" --timeout=600s
print_status "Waiting for build to complete..." kill $BUILD_PID 2>/dev/null || true
# Wait for build to start # Wait for deployment
print_status "Waiting for build to start..." oc rollout status deploymentconfig/"$APP_NAME" --timeout=300s
oc wait --for=condition=Running buildconfig/"$APP_NAME" --timeout=60s || true
# Get the latest build # Get URL
BUILD_NAME=$(oc get builds -l buildconfig="$APP_NAME" --sort-by=.metadata.creationTimestamp -o jsonpath='{.items[-1].metadata.name}') ROUTE_URL=$(oc get route "$APP_NAME" -o jsonpath='{.spec.host}' 2>/dev/null || echo "")
if [ -n "$BUILD_NAME" ]; then echo ""
print_status "Waiting for build '$BUILD_NAME' to complete..." echo "✅ Deployment Complete!"
oc logs -f build/"$BUILD_NAME" || true echo "🌐 Application URL: https://$ROUTE_URL"
echo ""
# Wait for build to complete echo "📊 Check status:"
oc wait --for=condition=Complete build/"$BUILD_NAME" --timeout=600s || { echo " oc get pods -n $NAMESPACE"
print_error "Build failed or timed out" echo " oc logs -f deploymentconfig/$APP_NAME -n $NAMESPACE"
print_status "Build logs:"
oc logs build/"$BUILD_NAME"
exit 1
}
print_success "Build completed successfully"
else
print_warning "No build found, continuing..."
fi
}
# Wait for deployment to be ready
wait_for_deployment() {
print_status "Waiting for deployment to be ready..."
# Wait for deployment to complete
oc rollout status deploymentconfig/"$APP_NAME" --timeout=300s || {
print_error "Deployment failed or timed out"
print_status "Deployment logs:"
oc logs deploymentconfig/"$APP_NAME"
exit 1
}
print_success "Deployment completed successfully"
}
# Get application URL
get_application_url() {
print_status "Getting application URL..."
ROUTE_URL=$(oc get route "$APP_NAME" -o jsonpath='{.spec.host}' 2>/dev/null || echo "")
if [ -n "$ROUTE_URL" ]; then
print_success "Application deployed successfully!"
echo ""
echo "=========================================="
echo "🚀 ORU Analyzer is now available at:"
echo " https://$ROUTE_URL"
echo "=========================================="
echo ""
echo "📊 To check the application status:"
echo " oc get pods -n $NAMESPACE"
echo " oc logs -f deploymentconfig/$APP_NAME -n $NAMESPACE"
echo ""
echo "🔧 To check the build status:"
echo " oc get builds -n $NAMESPACE"
echo " oc logs build/<build-name> -n $NAMESPACE"
echo ""
else
print_warning "Could not determine application URL"
print_status "Check the route manually:"
echo " oc get route -n $NAMESPACE"
fi
}
# Main deployment function
main() {
echo "Starting ORU Analyzer S2I deployment..."
echo "=========================================="
echo "Namespace: $NAMESPACE"
echo "App Name: $APP_NAME"
echo "Git Repository: $GIT_REPO"
echo "Git Reference: $GIT_REF"
echo "Python Version: $PYTHON_VERSION"
echo "Method: oc new-app (simplified S2I)"
echo "=========================================="
echo ""
check_prerequisites
create_namespace
deploy_s2i
wait_for_build
wait_for_deployment
get_application_url
print_success "ORU Analyzer S2I deployment completed!"
}
# Run main function
main "$@"