Skip to content
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

test-k8s-version #1

Merged
merged 20 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: registry.uffizzi.com/quickstart
ports:
- containerPort: 8080
20 changes: 20 additions & 0 deletions .github/k8s/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
spec:
ingressClassName: uffizzi
rules:
- host: web.example.com
http:
paths:
- backend:
service:
name: web
port:
number: 8080
path: /
pathType: Prefix
tls:
- hosts:
- web.example.com
6 changes: 6 additions & 0 deletions .github/k8s/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- ingress.yaml
- service.yaml
10 changes: 10 additions & 0 deletions .github/k8s/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: web
spec:
ports:
- port: 8080
type: ClusterIP
selector:
app: web
30 changes: 30 additions & 0 deletions .github/workflows/changelog_builder/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"categories": [
{
"title": "## � Features",
"labels": ["feature"]
},
{
"title": "## � Fixes",
"labels": ["fix"]
},
{
"title": "## � Tests",
"labels": ["test"]
},
{
"title": "## � Other",
"labels": ["other"]
},
{
"title": "## � Dependencies",
"labels": ["dependencies"]
}
],
"sort": "ASC",
"template": "${{CHANGELOG}}",
"pr_template": "- ${{TITLE}}\n - PR: #${{NUMBER}}",
"empty_template": "- no changes",
"max_pull_requests": 1000,
"max_back_track_time_days": 1000
}
204 changes: 204 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
name: Multicluster e2e

on:
pull_request:
branches: [ main ]
types: [opened,reopened,synchronize,closed]

permissions:
contents: read
pull-requests: write
id-token: write

jobs:
build-image:
name: Build and Push `nodejs` Image
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
outputs:
tags: ${{ steps.meta.outputs.tags }}
uuid: ${{ env.UUID_IMAGE }}
steps:
- name: Checkout git repo
uses: actions/checkout@v3
- name: Generate UUID image name
id: uuid
run: echo "UUID_IMAGE=$(uuidgen)" >> $GITHUB_ENV
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
# An anonymous, emphemeral registry built on ttl.sh
images: registry.uffizzi.com/${{ env.UUID_IMAGE }}
tags: type=raw,value=48h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Image to Uffizzi Ephemeral Registry
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: ./src
cache-from: type=gha
cache-to: type=gha,mode=max

uffizzi-cluster:
name: Deploy Helm chart to Uffizzi Virtual Cluster
needs:
- build-image
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

# Identify comment to be updated
- name: Find comment for Ephemeral Environment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: pr-${{ github.event.pull_request.number }}-e2e-helm
direction: last

# Create/Update comment with action deployment status
- name: Create or Update Comment with Deployment Notification
id: notification
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Uffizzi Ephemeral Environment - Virtual Cluster - E2E Helm Chart

:cloud: deploying ...

:gear: Updating now by workflow run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).

Cluster name will be `pr-${{ github.event.pull_request.number }}-e2e-helm`

Download the Uffizzi CLI to interact with the upcoming virtual cluster
https://docs.uffizzi.com/install
edit-mode: replace

- name: Create and connect to vcluster
uses: UffizziCloud/cluster-action@k8s_version
with:
cluster-name: pr-${{ github.event.pull_request.number }}-1276
server: https://app.uffizzi.com
k8s-version: 1.27
kubeconfig: kubeconfig-1276

- name: Create and connect to vcluster
uses: UffizziCloud/cluster-action@k8s_version
with:
cluster-name: pr-${{ github.event.pull_request.number }}-1282
server: https://app.uffizzi.com
k8s-version: 1.28
kubeconfig: kubeconfig-1282

- name: Apply Kustomize to test the new image
id: prev
run: |
if [[ ${RUNNER_DEBUG} == 1 ]]; then
pwd
ls -la
fi
(
cp ./kubeconfig-1276 ./kubeconfig-1282 ./.github/k8s
cd .github/k8s
# Change the image name to those just built and pushed.
kustomize edit set image uffizzi/hello-world-k8s=${{ needs.build-image.outputs.tags }}


# Apply kustomized manifests to virtual cluster.
kubectl apply --kustomize . --kubeconfig ./kubeconfig-1276
kubectl apply --kustomize . --kubeconfig ./kubeconfig-1282
)
# Allow uffizzi to sync the resources
sleep 5

# Get the hostnames assigned by uffizzi
export WEB_HOST_1=$(kubectl get ingress web --kubeconfig ./kubeconfig-1276 -o json | jq '.spec.rules[0].host' | tr -d '"')
export WEB_HOST_2=$(kubectl get ingress web --kubeconfig ./kubeconfig-1282 -o json | jq '.spec.rules[0].host' | tr -d '"')

if [[ ${RUNNER_DEBUG} == 1 ]]; then
kubectl get all --kubeconfig ./kubeconfig-1276
kubectl get all --kubeconfig ./kubeconfig-1282
fi

echo "web_url_1=${WEB_HOST_1}" >> $GITHUB_OUTPUT
echo "web_url_2=${WEB_HOST_2}" >> $GITHUB_OUTPUT

echo "Access the \`web\` endpoint deployed on k8s version 1.27.6 at [\`${WEB_HOST_1}\`](http://${WEB_HOST_1})" >> $GITHUB_STEP_SUMMARY
echo "Access the \`web\` endpoint deployed on k8s version 1.28.2 at [\`${WEB_HOST_2}\`](http://${WEB_HOST_2})" >> $GITHUB_STEP_SUMMARY

- name: Create or Update Comment with Deployment URL
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.notification.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
## Uffizzi Ephemeral Environment - Virtual Cluster - E2E Helm Chart

E2E tests in progress on the `pr-${{ github.event.pull_request.number }}-1276` and
`pr-${{ github.event.pull_request.number }}-1282` virtual clusters.
edit-mode: replace

uffizzi-cluster-delete:
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }}
runs-on: ubuntu-latest
steps:
- name: Delete Virtual Cluster
uses: UffizziCloud/cluster-action@main
with:
action: delete
cluster-name: pr-${{ github.event.pull_request.number }}-1276
server: https://app.uffizzi.com

- name: Delete Virtual Cluster
uses: UffizziCloud/cluster-action@main
with:
action: delete
cluster-name: pr-${{ github.event.pull_request.number }}-1282
server: https://app.uffizzi.com

# Identify comment to be updated
- name: Find comment for Ephemeral Environment 1
uses: peter-evans/find-comment@v2
id: find-comment-1
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: pr-${{ github.event.pull_request.number }}-1276
direction: last

# Identify comment to be updated
- name: Find comment for Ephemeral Environment 2
uses: peter-evans/find-comment@v2
id: find-comment-2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: pr-${{ github.event.pull_request.number }}-1282
direction: last

- name: Update Comment with Deletion
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.find-comment-1.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Uffizzi Cluster `pr-${{ github.event.pull_request.number }}-1276` was deleted.
edit-mode: replace

- name: Update Comment with Deletion
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ steps.find-comment-2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Uffizzi Cluster `pr-${{ github.event.pull_request.number }}-1282` was deleted.
edit-mode: replace