openweathermap key
This commit is contained in:
parent
a7014d91d2
commit
079c3cc88a
5 changed files with 142 additions and 1 deletions
0
get_helm.sh
Executable file → Normal file
0
get_helm.sh
Executable file → Normal file
3
justfile
3
justfile
|
|
@ -21,7 +21,8 @@ sealed-secretes-backup:
|
|||
|
||||
seal-openweathermap-api-key:
|
||||
kubectl create secret generic openweathermap-api-key --from-literal=openweathermap-api-key=${OPENWEATHERMAP_API_KEY} --dry-run=client -o yaml > private/openweathermap-api-key.yaml
|
||||
kubeseal --format=yaml < private/openweathermap-api-key.yaml > temperature-cronjob/templates/openweathermap-api-key.yaml
|
||||
kubeseal --namespace temperature-cronjob-helm --format=yaml < private/openweathermap-api-key.yaml > temperature-cronjob/templates/sealed-openweathermap-api-key.yaml
|
||||
kubeseal --namespace temperature-cronjob-manifest --format=yaml < private/openweathermap-api-key.yaml > temperature-cronjob-manifest/sealed-openweathermap-api-key.yaml
|
||||
|
||||
argo-install:
|
||||
kubectl create namespace argocd
|
||||
|
|
|
|||
110
temperature-cronjob-manifest/cronjob.yaml
Normal file
110
temperature-cronjob-manifest/cronjob.yaml
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: temperature-cronjob-manifest
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: temperature-fetcher
|
||||
namespace: temperature-cronjob-manifest
|
||||
data:
|
||||
temperature_fetcher.py: |
|
||||
# temperature_fetcher.py
|
||||
import datetime
|
||||
import os
|
||||
import requests
|
||||
import sqlite3
|
||||
|
||||
print("hey im running")
|
||||
|
||||
city = os.getenv("CITY")
|
||||
api_key = os.getenv("API_KEY")
|
||||
mount_path = os.getenv("MOUNT_PATH", "/data/manifest")
|
||||
|
||||
try:
|
||||
response = requests.get(
|
||||
f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=imperial"
|
||||
)
|
||||
response.raise_for_status()
|
||||
temp = response.json()["main"]["temp"]
|
||||
|
||||
db_path = f"{mount_path}/temperature.db"
|
||||
conn = sqlite3.connect(db_path)
|
||||
c = conn.cursor()
|
||||
c.execute(
|
||||
"CREATE TABLE IF NOT EXISTS temperatures (timestamp TEXT, temperature REAL)"
|
||||
)
|
||||
c.execute(
|
||||
"INSERT INTO temperatures VALUES (?, ?)",
|
||||
(datetime.datetime.now().isoformat(), temp),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(
|
||||
f"Successfully stored temperature {temp}°C for {city} at {datetime.datetime.now()}"
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: temperature-cronjob
|
||||
namespace: temperature-cronjob-manifest
|
||||
spec:
|
||||
schedule: "*/1 * * * *"
|
||||
startingDeadlineSeconds: 200 # Deadline for starting the job
|
||||
concurrencyPolicy: Forbid # Prevents concurrent runs
|
||||
successfulJobsHistoryLimit: 3 # Keeps last successful job
|
||||
failedJobsHistoryLimit: 3 # Keeps last failed job
|
||||
jobTemplate:
|
||||
spec:
|
||||
activeDeadlineSeconds: 180 # Limits how long a job can be active
|
||||
ttlSecondsAfterFinished: 100 # Cleans up finished jobs after 100 seconds
|
||||
backoffLimit: 0 # Number of retries before considering the job failed
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: temperature-fetcher
|
||||
terminationMessagePath: "/sqlite-data/termination.log"
|
||||
image: "python:3.9-slim"
|
||||
imagePullPolicy: IfNotPresent
|
||||
command: ["/bin/bash", "-c"]
|
||||
args:
|
||||
- |
|
||||
echo "Installing dependencies" && \
|
||||
pip install requests && \
|
||||
echo "Fetching temperature" && \
|
||||
python /scripts/temperature_fetcher.py
|
||||
resources:
|
||||
requests:
|
||||
cpu: "25m"
|
||||
memory: "8Mi"
|
||||
limits:
|
||||
cpu: "50m"
|
||||
memory: "16Mi"
|
||||
env:
|
||||
- name: CITY
|
||||
value: "Dunlap, US"
|
||||
- name: MOUNT_PATH
|
||||
value: "/data"
|
||||
- name: API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: openweathermap-api-key
|
||||
key: openweathermap-api-key
|
||||
volumeMounts:
|
||||
- name: sqlite-data
|
||||
mountPath: "/data"
|
||||
- name: script-volume
|
||||
mountPath: /scripts
|
||||
restartPolicy: Never
|
||||
volumes:
|
||||
- name: sqlite-data
|
||||
hostPath:
|
||||
path: "/sqlite-data"
|
||||
type: Directory
|
||||
- name: script-volume
|
||||
configMap:
|
||||
name: release-name-script
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
apiVersion: bitnami.com/v1alpha1
|
||||
kind: SealedSecret
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: openweathermap-api-key
|
||||
namespace: temperature-cronjob-manifest
|
||||
spec:
|
||||
encryptedData:
|
||||
openweathermap-api-key: AgAniTh8zqhUvb/IQ2nYH/0OCu+ke9GfcYuOE9lSTmKYWQvwecw9F5phjs0wkLDSGyLQfUWLAOT4rKg6e7nqAOHQEnFdp5tI5vbWtcgV2sZbaB+h40WGdLSa4tC0EfXtEpvM1/ugECd8YFOrOmgL7zUNNFsT7MUWyHAxv8p2Na0bKZ68fsEr8urhnEg6F980U7jeb2cQ4sgWsODs2EYTwzTdsNanZCTFADbDPpmcY6rc5kkGSK65lhCV7wZozS2i6DG2TRMAttxynZidAy1sdRRqmI/T85hVWB+/U9SpL/T07uR49zJIPSer/1yWmznVvJRgQYcu64PlpxwXIW5UkLkDc4ksCJTolwLBFCR0BdEMK/+MUfbnJs6W/CqwNGm7Z7URNIxRU169OJJeDLa4lrBd1wopaXWTosbTyX0kdit9dxb3uRZ/0EYYNB85i8rJdpU+gCXxERvZ74Z0l/qZSYgiPmTnrCbzKlmOOqXwmQ2VtdDny1YJ2B51Nq790MA+vrWaT+3hS2JirCGtnZYvEnAsZxrqhhPPG8pfe3CMbUfhroFhoNQabVj+0Zjkfhb8qJwGRady7B4k2i08YFgdFiTjuFl3ZBvchv/L4qWQY4uPCywCn4SB+bVueObw2ajxO4xD1wtdNUg76rLV3juBncXJLsDyfM8C+gVTXhshNLbEq+EC4KaSmXYv6LZp2RqSVUe+tYJqUAiyUhYdRNiYU1RcCvrvQ0l+8S2Kl66fPztI7A==
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: openweathermap-api-key
|
||||
namespace: temperature-cronjob-manifest
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
apiVersion: bitnami.com/v1alpha1
|
||||
kind: SealedSecret
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: openweathermap-api-key
|
||||
namespace: temperature-cronjob-helm
|
||||
spec:
|
||||
encryptedData:
|
||||
openweathermap-api-key: AgABEOpp8H1O51kQsDZnCW1rjTYeDNCwJMn/TMC/UMQi8WfngR2lHRevbTQ3sRgcGvBghsH2kfcrU6unO9XjprIOJ6DG7HQ3uKuKGrkG18eQHQtb0GY4nw9LO8scp8dBYYxyjLhHWVXnTof7HYKSDq2LLKZ5XstNh+th2D5UyI1flCJxKBJqqHVX7L0FNdKamGqhMr4FJ9dJ0ATFuOhwkjGHq6POe5WO6/pJR9zYlkvy4ViEJ3M+YbUlnEcPD62FloV5uQ9+BhhLYIxV9dPSH3XF4eW5vZF+enFRWSJuU55JIac858DRqNgVnuJCrilcoIeOch3kzFdJCo7Pqr+VMtcsjmdDtXIDR5EYOB1aZIFZn+HTxjoiMDJpr/Yrm2HXNSukIBES1im7Rb6icJoFicG7uirVvcv8NtlF9y3Mnv+3n4yYQ8xXTXX8yfTyOVws3/JVOuDJNbuvwBHvZLnCndIooCRYYDLaVybGeDcLUj3pScTSvAtJqmfEmXS7PzlhumajhZaHUnJ9gAUObEolI9RI62CgctE4HbIFcragbeLbgAhjkKLB4fY+oNDeYW2uqI1pla5GE0yMgfPg63ykKI70pxnneQFUCbpLpw4ZVqzaMt1Rz1FnUN6nG0+IxZtmcUT1/PC1f/MexQzRIT7Y03zU+qBIdEGogktm0u3heGKFfBPaWFV/6nshN8jGzliOgXd4erwb264QH7WPg+UeH4+YQhT+JKrNVg6Dfy3SSpM87Q==
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: openweathermap-api-key
|
||||
namespace: temperature-cronjob-helm
|
||||
Loading…
Add table
Add a link
Reference in a new issue