diff --git a/src/main/cljc/dda/k8s_mastodon_bot/core.cljc b/src/main/cljc/dda/k8s_mastodon_bot/core.cljc index 0e21ce4..c43efb6 100644 --- a/src/main/cljc/dda/k8s_mastodon_bot/core.cljc +++ b/src/main/cljc/dda/k8s_mastodon_bot/core.cljc @@ -19,8 +19,10 @@ )) (defn generate-deployment [] - (-> - (yaml/from-string (yaml/load-resource "deployment.yaml")))) + (yaml/from-string (yaml/load-resource "deployment.yaml"))) + +(defn generate-cron [] + (yaml/from-string (yaml/load-resource "cron.yaml"))) (defn-spec generate any? [my-config string? @@ -28,4 +30,4 @@ (cs/join "\n" [(yaml/to-string (generate-config my-config my-auth)) "---" - (yaml/to-string (generate-deployment))])) + (yaml/to-string (generate-cron))])) diff --git a/src/main/cljs/dda/k8s_mastodon_bot/yaml.cljs b/src/main/cljs/dda/k8s_mastodon_bot/yaml.cljs index 4c8dca4..e286bb8 100644 --- a/src/main/cljs/dda/k8s_mastodon_bot/yaml.cljs +++ b/src/main/cljs/dda/k8s_mastodon_bot/yaml.cljs @@ -6,11 +6,14 @@ (def config (rc/inline "config.yaml")) +(def cron (rc/inline "cron.yaml")) + (def deployment (rc/inline "deployment.yaml")) (defn load-resource [resource-name] (case resource-name "config.yaml" config + "cron.yaml" cron "deployment.yaml" deployment)) (defn from-string [input] diff --git a/src/main/resources/cron.yaml b/src/main/resources/cron.yaml new file mode 100644 index 0000000..a45cad0 --- /dev/null +++ b/src/main/resources/cron.yaml @@ -0,0 +1,34 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: mastodon-bot-cron + labels: + app.kubernetes.io/name: k8s-mastodon-bot +spec: + schedule: "* */10 * * *" + successfulJobsHistoryLimit: 0 + failedJobsHistoryLimit: 0 + jobTemplate: + spec: + template: + spec: + volumes: + - name: config-volume + configMap: + name: mastodon-bot + containers: + - image: domaindrivenarchitecture/mastodon-bot + name: mastodon-bot + env: + - name: MASTODON_BOT_CREDENTIALS + value: /credentials.edn + volumeMounts: + - name: config-volume + mountPath: /config.edn + subPath: config.edn + readOnly: true + - name: config-volume + mountPath: /credentials.edn + subPath: credentials.edn + readOnly: true + restartPolicy: Never diff --git a/src/main/resources/deployment.yaml b/src/main/resources/deployment.yaml index f7ed6d0..7056179 100644 --- a/src/main/resources/deployment.yaml +++ b/src/main/resources/deployment.yaml @@ -23,7 +23,6 @@ spec: env: - name: MASTODON_BOT_CREDENTIALS value: /credentials.edn - cmd: volumeMounts: - name: config-volume mountPath: /config.edn