-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba03871
commit 456a665
Showing
12 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Testkube with ArgoRollouts | ||
|
||
## Overview | ||
|
||
This project integrates Testkube with ArgoRollouts to provide a robust testing and deployment pipeline. Testkube is a cloud-native testing framework, while ArgoRollouts is a Kubernetes controller for managing the deployment of applications using advanced deployment strategies. | ||
|
||
## Prerequisites | ||
|
||
- Kubernetes cluster | ||
- kubectl configured to interact with your cluster | ||
- Testkube installed | ||
- ArgoRollouts installed | ||
- API key from http://api.weatherapi.com | ||
|
||
## Project Structure | ||
|
||
- `rollout.yaml`: Configuration file for deploying the application using ArgoRollouts. | ||
- `template.yaml`: Template file containing the Testkube Test Workflow and other configurations. | ||
- `weatherSample-v1`: Files for the v1 of the weather application which shows the weather of Hyderabad. | ||
- `weatherSample-v2`: Files for the v1 of the weather application which shows the weather of New York. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Rollout | ||
metadata: | ||
name: rollout-experiment | ||
spec: | ||
replicas: 2 | ||
strategy: | ||
canary: | ||
steps: | ||
- setWeight: 50 | ||
- pause: {duration: 10} | ||
# The second step is the experiment which starts a single canary pod | ||
- experiment: | ||
duration: 5m | ||
templates: | ||
- name: canary | ||
specRef: canary | ||
# This experiment performs its own analysis by referencing an AnalysisTemplates | ||
# The success or failure of these runs will progress or abort the rollout respectively. | ||
analyses: | ||
- name: canary-experiment | ||
templateName: testkube-experiment-analysis | ||
- setWeight: 100 | ||
- pause: {duration: 10} | ||
revisionHistoryLimit: 2 | ||
selector: | ||
matchLabels: | ||
app: rollout-experiment | ||
template: | ||
metadata: | ||
labels: | ||
app: rollout-experiment | ||
spec: | ||
containers: | ||
- name: rollouts-demo | ||
image: docker.io/atulinfracloud/weathersample:v1 | ||
imagePullPolicy: Always | ||
ports: | ||
- containerPort: 5000 | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: rollout-weather-svc | ||
spec: | ||
selector: | ||
app: rollout-experiment | ||
ports: | ||
- protocol: "TCP" | ||
port: 80 | ||
targetPort: 5000 | ||
type: NodePort | ||
|
||
|
||
--- | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: rollout-ingress | ||
annotations: | ||
kubernetes.io/ingress.class: nginx | ||
spec: | ||
rules: | ||
- http: | ||
paths: | ||
- path: / | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: rollout-weather-svc | ||
port: | ||
number: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: AnalysisTemplate | ||
metadata: | ||
name: testkube-experiment-analysis | ||
spec: | ||
metrics: | ||
- name: run-testkube-workflows | ||
provider: | ||
job: | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: execute-testkube | ||
image: kubeshop/testkube-cli:2.1.19 | ||
env: | ||
- name: API_TOKEN | ||
value: "<your-API-token>" | ||
- name: ENVIRONMENT_ID | ||
value: "<your-environment-ID>" | ||
- name: ORGANIZATION_ID | ||
value: "<your-organization-ID>" | ||
- name: ROOT_DOMAIN | ||
value: "testkube.io" | ||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
testkube set context \ | ||
--api-key ${API_TOKEN} \ | ||
--root-domain ${ROOT_DOMAIN} \ | ||
--org-id ${ORGANIZATION_ID} \ | ||
--env-id ${ENVIRONMENT_ID} | ||
# Run the desired Testkube workflows during the experiment | ||
testkube run tw basic-k6-workflow -f || exit 1 | ||
restartPolicy: Never | ||
backoffLimit: 2 | ||
successCondition: "result.exitCode == 0" # Exit code 0 for success | ||
failureCondition: "result.exitCode == 1" # Exit code 1 for failure | ||
interval: 1m | ||
count: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM python:3.7 | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
ADD . /app/ | ||
RUN apt-get update | ||
RUN apt-get install iputils-ping -y | ||
RUN pip install -r requirements.txt | ||
|
||
CMD ["python", "main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from flask import Flask, render_template | ||
import requests, json | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route(f"/") | ||
def home(): | ||
# Hyderabad | ||
# Replace <your-api-key> with your actual api key | ||
api_url="http://api.weatherapi.com/v1/current.json?key=<your-api-key>&q=Hyderabad&aqi=no" | ||
response = requests.get(api_url) | ||
response.raise_for_status() | ||
if response.status_code != 204: | ||
res = json.loads(response.content.decode('utf-8')) | ||
temp = res['current']['temp_c'] | ||
wind_speed = res['current']['condition']['text'] | ||
weather_code = res['current']['cloud'] | ||
|
||
if weather_code < 10 and weather_code > 0: | ||
weather="Mainly Clear" | ||
elif weather_code > 40 and weather_code < 50: | ||
weather = "Fog" | ||
elif weather_code > 50 and weather_code < 56: | ||
weather = "Drizzle" | ||
elif weather_code > 60 and weather_code < 70: | ||
weather = "Light Rain" | ||
else: | ||
weather = "Rain" | ||
|
||
return render_template("index.html",temp=temp,wind_speed=wind_speed,weather=weather, location='Hyderabad') | ||
|
||
else: | ||
|
||
print("Error: "+response.status_code) | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Flask==2.1.1 | ||
Jinja2==3.0.2 | ||
requests==2.26.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title>Weather Forecast</title> | ||
<style> | ||
h1 { | ||
position: relative; | ||
font-size: 5rem; | ||
} | ||
|
||
html { | ||
block-size: 100%; | ||
inline-size: 100%; | ||
} | ||
|
||
body { | ||
min-block-size: 100%; | ||
min-inline-size: 100%; | ||
margin: 0; | ||
box-sizing: border-box; | ||
display: grid; | ||
place-content: center; | ||
font-family: system-ui, sans-serif; | ||
background-color: burlywood; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
|
||
<h1> | ||
Server Location: {{location}}<br> | ||
Temperature: {{temp}}<br> | ||
Cloud Cover: {{wind_speed}}<br> | ||
Forecast: {{weather}}<br> | ||
</h1> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM python:3.7 | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
ADD . /app/ | ||
RUN apt-get update | ||
RUN apt-get install iputils-ping -y | ||
RUN pip install -r requirements.txt | ||
|
||
CMD ["python", "main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from flask import Flask, render_template | ||
import requests, json | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route(f"/") | ||
def home(): | ||
# New York | ||
# Replace <your-api-key> with your actual api key | ||
api_url="http://api.weatherapi.com/v1/current.json?key=<your-api-key>&q=New%20York&aqi=no" | ||
response = requests.get(api_url) | ||
response.raise_for_status() | ||
if response.status_code != 204: | ||
res = json.loads(response.content.decode('utf-8')) | ||
temp = res['current']['temp_c'] | ||
wind_speed = res['current']['condition']['text'] | ||
weather_code = res['current']['cloud'] | ||
|
||
if weather_code < 10 and weather_code > 0: | ||
weather="Mainly Clear" | ||
elif weather_code > 40 and weather_code < 50: | ||
weather = "Fog" | ||
elif weather_code > 50 and weather_code < 56: | ||
weather = "Drizzle" | ||
elif weather_code > 60 and weather_code < 70: | ||
weather = "Light Rain" | ||
else: | ||
weather = "Rain" | ||
|
||
return render_template("index.html",temp=temp,wind_speed=wind_speed,weather=weather, location='New York') | ||
|
||
else: | ||
|
||
print("Error: "+response.status_code) | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Flask==2.1.1 | ||
Jinja2==3.0.2 | ||
requests==2.26.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title>Weather</title> | ||
<style> | ||
h1 { | ||
position: relative; | ||
font-size: 5rem; | ||
} | ||
|
||
html { | ||
block-size: 100%; | ||
inline-size: 100%; | ||
} | ||
|
||
body { | ||
min-block-size: 100%; | ||
min-inline-size: 100%; | ||
margin: 0; | ||
box-sizing: border-box; | ||
display: grid; | ||
place-content: center; | ||
font-family: system-ui, sans-serif; | ||
background-color: aquamarine; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
|
||
<h1> | ||
Server Location: {{location}}<br> | ||
Temperature: {{temp}}<br> | ||
Cloud Cover: {{wind_speed}}<br> | ||
Forecast: {{weather}}<br> | ||
</h1> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters