From 3822da04578668bfe144f7828a598300e1481769 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 08:53:42 -0500 Subject: [PATCH 01/10] use a real tag --- temperature-cronjob/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/temperature-cronjob/values.yaml b/temperature-cronjob/values.yaml index e9cc70f..be3a5f3 100644 --- a/temperature-cronjob/values.yaml +++ b/temperature-cronjob/values.yaml @@ -1,7 +1,7 @@ # values.yaml image: repository: python - tag: "fails-to-pull" + tag: "3.9-slim" pullPolicy: IfNotPresent schedule: "*/1 * * * *" # Every minute city: "Dunlap, US" From db997a6cb0479a538a91e8fe993a6be8386979eb Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 08:59:08 -0500 Subject: [PATCH 02/10] fix secret name --- .gitignore | 1 + justfile | 2 +- temperature-cronjob/templates/openweathermap-api-key.yaml | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 621f648..7c05ee7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ sqlite-data private/* +.env diff --git a/justfile b/justfile index 7134493..ba23d71 100644 --- a/justfile +++ b/justfile @@ -20,7 +20,7 @@ sealed-secretes-backup: kubectl get secret -n kube-system -l sealedsecrets.bitnami.com/sealed-secrets-key -o yaml > private/sealed-secrets-key.yaml seal-openweathermap-api-key: - kubectl create secret generic mysecret --from-literal=openweathermap-api-key=${OPENWEATHERMAP_API_KEY} --dry-run=client -o yaml > private/openweathermap-api-key.yaml + 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 argo-install: diff --git a/temperature-cronjob/templates/openweathermap-api-key.yaml b/temperature-cronjob/templates/openweathermap-api-key.yaml index 2793cb9..ff23ac3 100644 --- a/temperature-cronjob/templates/openweathermap-api-key.yaml +++ b/temperature-cronjob/templates/openweathermap-api-key.yaml @@ -3,13 +3,13 @@ apiVersion: bitnami.com/v1alpha1 kind: SealedSecret metadata: creationTimestamp: null - name: mysecret + name: openweathermap-api-key namespace: default spec: encryptedData: - openweathermap-api-key: AgCFICyiqMaxx5vf4D06GuuB/xoC8SJJ43KD5+ipsF7stwzDN7BWQexnPAgPvCMiRq+w+oRRbR/IBIYPk4Ng3kdTwYjkCf1rUFogaHdACs9dS1mhaW9ipwd2rO7ImJVVJUZgkAmEv/F6JBz+cR4w6RUsU8OcDBLqPMehe8JG/YrXPu2hJt38lzl8Hry/j7ydgm5nq7fxuHGbY66FKyVrtW/zzKQhZHYojDvS0Qez/OsWFz7I8o/287qoQjcxPr8giniIo3EPxfT5XjAB5HymJUD9DgUSgjvqAKDLRGrSuomoXi42OWywzi3heq2LgsJFm6BeMU9tilTXDN6AjiN+47OTY4FX8twUiRci+wPRTWp5eSy1utoQf/VW6PRisFVt0z2D7ZBEFLMYrJuAqQhSrEDxvLQqVF5h4h6tXHAlSsinLp0jXYdcM0v6MGzMUSaQOxWjNrBeTdM6TIh7YWdpoC1msHxh+N939ru0Q0Nt/d2sy8oRqVsXh6JxIP/QTpyR5d5qNk10nOj2LojA4sfnJZTALEFFYp1gfYNmbU3O4QW0Qye0PnZ6nnhJ+ox6dCN8yuL+Ci8hMxPMzvVYeZ5Am8wZ7feeFeWpClMdW2sm3koGj4+M60BMs9SOfDuBAK22t2sD6ShP3xRI7MEbsOzMkJNizVqira55YQWUn6aLBMOW90ghD5J7QW77ih3r4oq60OGUX3yc9hlJnvgBblYL1KRVtPgawUelK3Q3EoKAok6YjA== + openweathermap-api-key: AgBm3myqlnLC3peWUOG9/vl5zzqwzTvyOXXAp54XQ9S3iQjC7GO+Bo5an9KVRqWQVQ9JY8DjGAp/7CYrKdgplOLG63bBGVTS1QdmH72xYSbEF0Je9pJwZ8+dD9q/rhoZzTgUqSvF/CFCtBI9dr2aE25jmxGc9TV/VnzhscX12o/6+kxz9p5hEhZ7QTHbdWEaVjjbo4YQ1aXyb0XD9Z/xxG3Hwf3N97sE9z39IvoF/aAGEKrCGMZYtI0T0fuUwCqji8JgjJ9SguPq4GzRRpUeJGnB+LSZFB95k1lAj6yhUP95DIwUGRon7ksQ/AXcJMFrsaQQ7kcxwUuTlbvoc7Vc84SQi6ZPv0yDypyr6pUE+8MrzvTzchXgsofCUC7FWDIqzH5bGc3CJ1OEP21FxW87NtvTr9xgap5/bOqLYs9U8wv02bL1yqVGLfWBoy+QLIY5viVUgj+kVzLftQlkimSMbfNNUtCJjpYYrLNoknU+fyGqsQnksXQSFlfwJZTOKFIcXwQ+exAkja8KpBYzehJulvU8A1UZZ0ylqniLTgxEMpOJ7Vu1MsBuBddZn4qHModbM1dCRC6GJEVQAaFYrZWonb9nhqLX9xei2LE2j/amaw6D7oZQ0b0+4cMsGC/mtRMgWMC5VorQH8qRPXtSitztOQv1mejvnpJWv0mUvmWiNsynaALMbA89OorMNPc5xn5HogTpygp69lb03n7UGwBBIvkQHGD336Uwh07L4iZ5lOe4sA== template: metadata: creationTimestamp: null - name: mysecret + name: openweathermap-api-key namespace: default From 4795ae01850e963984934ae87283d1fa90152f01 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 09:00:53 -0500 Subject: [PATCH 03/10] no sleep --- temperature-cronjob/templates/cronjob.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/temperature-cronjob/templates/cronjob.yaml b/temperature-cronjob/templates/cronjob.yaml index a6f9bb7..0956235 100644 --- a/temperature-cronjob/templates/cronjob.yaml +++ b/temperature-cronjob/templates/cronjob.yaml @@ -23,11 +23,10 @@ spec: command: ["/bin/bash", "-c"] args: - | - echo "Running temperature_fetcher.py" && \ + echo "Installing dependencies" && \ pip install requests && \ echo "Fetching temperature" && \ python /scripts/temperature_fetcher.py && \ - sleep 300 resources: requests: cpu: "100m" From 83b71864309def247e2c5c672e644e383dfb3d31 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 09:16:51 -0500 Subject: [PATCH 04/10] fix cronjob command --- temperature-cronjob/templates/cronjob.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/temperature-cronjob/templates/cronjob.yaml b/temperature-cronjob/templates/cronjob.yaml index 0956235..22a1d9e 100644 --- a/temperature-cronjob/templates/cronjob.yaml +++ b/temperature-cronjob/templates/cronjob.yaml @@ -26,7 +26,7 @@ spec: echo "Installing dependencies" && \ pip install requests && \ echo "Fetching temperature" && \ - python /scripts/temperature_fetcher.py && \ + python /scripts/temperature_fetcher.py resources: requests: cpu: "100m" From 7f57570f8e014603bed0d139368fd86be732d269 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 09:18:04 -0500 Subject: [PATCH 05/10] reduce backoff --- temperature-cronjob/templates/cronjob.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/temperature-cronjob/templates/cronjob.yaml b/temperature-cronjob/templates/cronjob.yaml index 22a1d9e..fbf5096 100644 --- a/temperature-cronjob/templates/cronjob.yaml +++ b/temperature-cronjob/templates/cronjob.yaml @@ -13,7 +13,7 @@ spec: spec: activeDeadlineSeconds: 180 # Limits how long a job can be active ttlSecondsAfterFinished: 100 # Cleans up finished jobs after 100 seconds - backoffLimit: 3 # Number of retries before considering the job failed + backoffLimit: 0 # Number of retries before considering the job failed template: spec: containers: From 7c8a08327931bd86463c0d5856f9e24320f1bd56 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 09:25:30 -0500 Subject: [PATCH 06/10] less resources --- temperature-cronjob/templates/cronjob.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/temperature-cronjob/templates/cronjob.yaml b/temperature-cronjob/templates/cronjob.yaml index fbf5096..1093e8d 100644 --- a/temperature-cronjob/templates/cronjob.yaml +++ b/temperature-cronjob/templates/cronjob.yaml @@ -29,11 +29,11 @@ spec: python /scripts/temperature_fetcher.py resources: requests: + cpu: "50m" + memory: "64Mi" + limits: cpu: "100m" memory: "128Mi" - limits: - cpu: "200m" - memory: "256Mi" env: - name: CITY value: "{{ .Values.city }}" From 28497b877d411d24e3fd71468b1c137018587ed7 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 09:38:17 -0500 Subject: [PATCH 07/10] low resources --- temperature-cronjob/templates/cronjob.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/temperature-cronjob/templates/cronjob.yaml b/temperature-cronjob/templates/cronjob.yaml index 1093e8d..7717823 100644 --- a/temperature-cronjob/templates/cronjob.yaml +++ b/temperature-cronjob/templates/cronjob.yaml @@ -29,11 +29,11 @@ spec: python /scripts/temperature_fetcher.py resources: requests: - cpu: "50m" - memory: "64Mi" + cpu: "25m" + memory: "8Mi" limits: - cpu: "100m" - memory: "128Mi" + cpu: "50m" + memory: "16Mi" env: - name: CITY value: "{{ .Values.city }}" From a7014d91d21cbd1a9e2a96800281ab6e2a3b6ddd Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Wed, 25 Sep 2024 09:42:30 -0500 Subject: [PATCH 08/10] add terminationMessagePath --- temperature-cronjob/templates/cronjob.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/temperature-cronjob/templates/cronjob.yaml b/temperature-cronjob/templates/cronjob.yaml index 7717823..87cf474 100644 --- a/temperature-cronjob/templates/cronjob.yaml +++ b/temperature-cronjob/templates/cronjob.yaml @@ -18,6 +18,7 @@ spec: spec: containers: - name: temperature-fetcher + terminationMessagePath: "/sqlite-data/termination.log" image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} command: ["/bin/bash", "-c"] From 079c3cc88a7e45d8633bdda0da4ed720a5f44664 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sat, 22 Nov 2025 19:56:40 -0600 Subject: [PATCH 09/10] openweathermap key --- get_helm.sh | 0 justfile | 3 +- temperature-cronjob-manifest/cronjob.yaml | 110 ++++++++++++++++++ .../sealed-openweathermap-api-key.yaml | 15 +++ .../sealed-openweathermap-api-key.yaml | 15 +++ 5 files changed, 142 insertions(+), 1 deletion(-) mode change 100755 => 100644 get_helm.sh create mode 100644 temperature-cronjob-manifest/cronjob.yaml create mode 100644 temperature-cronjob-manifest/sealed-openweathermap-api-key.yaml create mode 100644 temperature-cronjob/templates/sealed-openweathermap-api-key.yaml diff --git a/get_helm.sh b/get_helm.sh old mode 100755 new mode 100644 diff --git a/justfile b/justfile index ba23d71..f9732a6 100644 --- a/justfile +++ b/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 diff --git a/temperature-cronjob-manifest/cronjob.yaml b/temperature-cronjob-manifest/cronjob.yaml new file mode 100644 index 0000000..97301b4 --- /dev/null +++ b/temperature-cronjob-manifest/cronjob.yaml @@ -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 diff --git a/temperature-cronjob-manifest/sealed-openweathermap-api-key.yaml b/temperature-cronjob-manifest/sealed-openweathermap-api-key.yaml new file mode 100644 index 0000000..1d90e33 --- /dev/null +++ b/temperature-cronjob-manifest/sealed-openweathermap-api-key.yaml @@ -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 diff --git a/temperature-cronjob/templates/sealed-openweathermap-api-key.yaml b/temperature-cronjob/templates/sealed-openweathermap-api-key.yaml new file mode 100644 index 0000000..57f6398 --- /dev/null +++ b/temperature-cronjob/templates/sealed-openweathermap-api-key.yaml @@ -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 From 9a5a237cb3d23fcc4ad99bf5fb2cfdb0780c5bd2 Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sat, 22 Nov 2025 19:56:46 -0600 Subject: [PATCH 10/10] chore: note repository moved to Forgejo --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f7fc21d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +> [!IMPORTANT] +> This project has been moved to https://git.wayl.one/waylon/learn-helm +