3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

argocdで完了済みのJobを自動削除する

Posted at

Jobの自動削除

終了したJobの自動クリーンアップで記載のある通り、kubernetes v1.23でGAされている
.spec.ttlSecondsAfterFinishedフィールドを使用してJobの完了または失敗から任意の時間後にJobをカスケード的に削除できる。

以下説明に使用するマニフェストです。待機時間は不要だと思ってttlSecondsAfterFinished: 0としました。

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-ttl
spec:
  ttlSecondsAfterFinished: 0
  template:
    spec:
      containers:
      - name: pi
        image: perl:5.34.0
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

Out of Syncの発生

ttlSecondsAfterFinishedで完了済みのJobが自動で削除されるようになったはいいものの、Deleted jobs by TTL controller show application as "Out of Sync"で話されていることと同じ現象がおきました。

公式ドキュメントを漁っていると、Sync Status with Jobs/Workflows with Time to Live (ttl)のようなものを見つけ、.metadata.annotationsに以下の二つを指定することで解決できそうです。

    argocd.argoproj.io/hook: PostSync
    argocd.argoproj.io/hook-delete-policy: HookSucceeded

argoのUIでJobに⚓マークが出て、無事にSyncedとなった。

Jobの完了を待ち続ける (Last Sync: Syncing)

上記のannotationsでOutofSyncが正常にSyncedになったのですが、LastSyncがずっとSyncingのままなので何かまちがっている。

argoのメッセージにはwaiting completion job(のような雰囲気)が出ていたので、もしかするとJobの完了後に即削除していたので、argo側が認識する前にリソースが削除されていると予想。

そこで以下のように、Jobの削除に待機時間を設けてみる。

# .spec
ttlSecondsAfterFinished: 10

ここまで長く待つ必要はないが、Last SyncSyncedとなった。

参考

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?