<p>How do you trigger rerunning a job once one of its dependent secrets get updated?</p>
<p>For example, say I have this simple job:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: batch/v1
kind: Job
metadata:
  name: job-test
spec:
  template:
    metadata:
      labels:
        app: databricks
    spec:
      containers:
      - name: job-test
        image: alpine
        command:
          - echo
          - hello $(DAN_TEST)
        env:
          - name: DAN_TEST
            valueFrom:
              secretKeyRef:
                name: dan-test
                key: dan-test-1
      restartPolicy: Never
  backoffLimit: 4
</code></pre>
<p>Adding this job makes it run and print out the secret, but when the secret is changed, the job is not automatically rerun.</p>
<p>Is there built-in or 3rd party extension resource that can target the secret and the job and trigger a rerun?</p>

Daniel
<p>I think it's maybe better to use a <code>ConfigMap</code> instead of a <code>Secret</code>, because <code>ConfigMaps</code> are designed to be more easily updated and can be monitored for changes using Kubernetes' built-in watch functionality!</p>
<p>let me update your code again :</p>
<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: job-test
  annotations:
    configmap.reloader.stakater.com/reload: &quot;dan-test&quot;
spec:
  template:
    metadata:
      labels:
        app: databricks
    spec:
      containers:
      - name: job-test
        image: alpine
        command:
          - echo
          - hello $(DAN_TEST)
        env:
          - name: DAN_TEST
            valueFrom:
              configMapKeyRef:
                name: dan-test
                key: dan-test-1
      restartPolicy: Never
  backoffLimit: 4
</code></pre>
<p>as you can see,I'm using the &quot;configmap.reloader.stakater.com/reload&quot; annotation to tell Kubernetes to monitor the &quot;dan-test&quot; ConfigMap for changes.
and about third-party tools, the &quot;Kubernetes Event-Driven Autoscaling&quot; (KEDA) project includes a &quot;Secret&quot; scaler that can trigger a Job based on changes to a Secret or other tools like <code>Argo Workflows</code> also provide similar functionality.</p>
<p><strong>update :</strong><br>
Ok I think to automatically trigger a rerun of a Job when a ConfigMap or Secret it depends on is updated, you can use the <code>cronjob</code> resource instead of the <code>job</code> resource</p>
<p>Let me explain cronjob to you with this example :</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: job-test
spec:
  schedule: &quot;*/1 * * * *&quot; # run every minute
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: job-test
            image: alpine
            command:
              - echo
              - hello $(DAN_TEST)
            env:
            - name: DAN_TEST
              valueFrom:
                configMapKeyRef:
                  name: dan-test
                  key: dan-test-1
          restartPolicy: OnFailure
</code></pre>
<p>As you see,<code>restartPolicy</code> is set to <code>OnFailure</code>, which means that the <code>cronjob</code> will automatically rerun the <code>job</code> if it fails, and also to trigger a rerun of the <code>cronjob</code> when the <code>dan-test</code> ConfigMap is updated, you can use the <code>configmap.reloader.stakater.com/reload</code> annotation on the <code>cronjob</code></p>
<p>Something like this (but be careful if the <code>cronjob</code> is already running when the ConfigMap is updated, the <code>job</code> may be in progress and cannot be interrupted. In this scenario, you will need to delete the <code>job</code> manually to trigger a rerun) :</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: job-test
  annotations:
    configmap.reloader.stakater.com/reload: &quot;dan-test&quot;
spec:
  schedule: &quot;*/1 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: job-test
            image: alpine
            command:
              - echo
              - hello $(DAN_TEST)
            env:
            - name: DAN_TEST
              valueFrom:
                configMapKeyRef:
                  name: dan-test
                  key: dan-test-1
          restartPolicy: OnFailure
</code></pre>
<p>good luck !</p>
