-
Notifications
You must be signed in to change notification settings - Fork 8
Restart k8s deployments running new images #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,3 +203,51 @@ jobs: | |
| echo "⏭️ (SKIP) Frontend: No version change detected" | ||
| fi | ||
| echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" | ||
|
|
||
| deploy-backend: | ||
| name: Restart Backend Deployment | ||
| if: github.event.pull_request.merged && needs.build-backend.result == 'success' | ||
| needs: [check_version_update, build-backend] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Set up kubectl | ||
| uses: azure/setup-kubectl@v3 | ||
| with: | ||
| version: 'latest' | ||
|
|
||
| - name: Configure kubectl for SAP BTP Kyma | ||
| run: | | ||
| mkdir -p ~/.kube | ||
| echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config | ||
| chmod 600 ~/.kube/config | ||
|
|
||
| - name: Restart Backend Deployment | ||
| run: | | ||
| echo "🔄 Restarting backend deployment to pull latest image..." | ||
| kubectl rollout restart deployment/stars-backend -n stars | ||
| kubectl rollout status deployment/stars-backend -n stars --timeout=10m | ||
| echo "✅ Backend deployment restarted successfully" | ||
|
Comment on lines
+224
to
+229
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error Handling: The deployment restart commands lack proper error handling. Consider adding error handling and validation to ensure the operations complete successfully. - name: Restart Backend Deployment
run: |
echo "🔄 Restarting backend deployment to pull latest image..."
if kubectl rollout restart deployment/stars-backend -n stars; then
echo "✅ Restart command issued successfully"
else
echo "❌ Failed to restart deployment"
exit 1
fi
if kubectl rollout status deployment/stars-backend -n stars --timeout=10m; then
echo "✅ Backend deployment restarted successfully"
else
echo "❌ Deployment rollout failed or timed out"
exit 1
fi
Comment on lines
+224
to
+229
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation Step: Consider adding a validation step to verify that the deployment is actually running and healthy after the restart. - name: Verify Deployment Health
run: |
echo "🔍 Verifying deployment health..."
kubectl get pods -n stars -l app=stars-backend
# Wait for pods to be ready
kubectl wait --for=condition=ready pod -l app=stars-backend -n stars --timeout=5m
# Optional: Health check if your app has a health endpoint
# kubectl port-forward service/stars-backend 8080:8080 -n stars &
# sleep 5
# curl -f http://localhost:8080/health || exit 1
echo "✅ Deployment is healthy and ready" |
||
|
|
||
| deploy-frontend: | ||
| name: Restart Frontend Deployment | ||
| if: github.event.pull_request.merged && needs.build-frontend.result == 'success' | ||
| needs: [check_version_update, build-frontend] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Set up kubectl | ||
| uses: azure/setup-kubectl@v3 | ||
| with: | ||
| version: 'latest' | ||
|
|
||
| - name: Configure kubectl for SAP BTP Kyma | ||
| run: | | ||
| mkdir -p ~/.kube | ||
| echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config | ||
| chmod 600 ~/.kube/config | ||
|
Comment on lines
+213
to
+246
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code Duplication: The kubectl setup and configuration steps are duplicated between the two jobs. Consider extracting this into a reusable action or composite action to follow DRY principles. # Create a composite action in .github/actions/setup-kubectl/action.yml
name: 'Setup kubectl for SAP BTP Kyma'
description: 'Sets up kubectl and configures it for SAP BTP Kyma'
runs:
using: 'composite'
steps:
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Configure kubectl for SAP BTP Kyma
shell: bash
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
# Then use it in both jobs:
- name: Setup kubectl
uses: ./.github/actions/setup-kubectl |
||
|
|
||
| - name: Restart Frontend Deployment | ||
| run: | | ||
| echo "🔄 Restarting frontend deployment to pull latest image..." | ||
| kubectl rollout restart deployment/stars-frontend -n stars | ||
| kubectl rollout status deployment/stars-frontend -n stars --timeout=10m | ||
| echo "✅ Frontend deployment restarted successfully" | ||
|
Comment on lines
+207
to
+253
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configuration as Variables: Hard-coded values like namespace, deployment names, and timeout should be extracted as variables or inputs for better maintainability. deploy-backend:
name: Restart Backend Deployment
if: github.event.pull_request.merged && needs.build-backend.result == 'success'
needs: [check_version_update, build-backend]
runs-on: ubuntu-latest
env:
NAMESPACE: stars
DEPLOYMENT_NAME: stars-backend
ROLLOUT_TIMEOUT: 10m
steps:
# ... kubectl setup steps ...
- name: Restart Backend Deployment
run: |
echo "🔄 Restarting $DEPLOYMENT_NAME deployment to pull latest image..."
kubectl rollout restart deployment/$DEPLOYMENT_NAME -n $NAMESPACE
kubectl rollout status deployment/$DEPLOYMENT_NAME -n $NAMESPACE --timeout=$ROLLOUT_TIMEOUT
echo "✅ $DEPLOYMENT_NAME deployment restarted successfully" |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security Enhancement: The KUBECONFIG secret handling could be more secure by using environment variables instead of directly echoing secrets in the command line.