Closed aodj closed 10 months ago
I should point out that the only way to resolve this is to change the db-migration
to not be a job, let it run the migrations, then you can revert it to being a job. This will work until you need to upgrade your Airflow version and it includes new db migrations, and then you need to do the whole thing again.
I did more searching and found #266 and #317 and it looks like there might be something I can set to fix this but I'm not sure I understand what needs to change. Can you advise @thesuperzapper ?
@aodj the default behavior of the chart is to use a Deployment to handle db-migrations
because of this exact issue with ArgoCD (and similar systems).
Are you sure you are not setting the airflow.dbMigrations.runAsJob
to true
:
My apologies for not making it clearer, but yes I am running it as a job; I do this because I don't want a long lived Python process consuming 5~600 MB (I also run the other sync steps as Kubernetes jobs for this same reason).
This came up in another thread I wrote last year about the possibility of running these jobs as CronJobs rather than Jobs (#540) because they consume upwards of 2 GB per installation (of which I have several). The Airflow version and the variables/connections/etc get updated rarely so I saw very little benefit to having them constantly up and syncing the same data/db migrations.
As for the problem at hand, the annotations are only set on the Jobs (not the Deployments) so I'm basically looking for a way to customise the ordering of the Helm hooks because otherwise it's either 1) run the db migrations as a deployment forever, or 2) run it as a Job but end up in a chicken-and-egg loop where you can't instantiate the webserver/scheduler until the db migrations are run, which only runs after said webserver/scheduler are up and running.
I've got some code running locally that will merge user provided annotations
with the default ones set by the chart, if you're interested in a PR:
{{- define "airflow.db_migrations.annotations" -}}
{{- $defaultAnnotations := (dict "helm.sh/hook" "post-install,post-upgrade" "helm.sh/hook-weight" "-100" "helm.sh/hook-delete-policy" "before-hook-creation") -}}
{{- $annotations := mergeOverwrite $defaultAnnotations .Values.airflow.dbMigrations.annotations -}}
{{- toYaml $annotations -}}
{{- end -}}
If it's something that might be useful I could also generalise it for use across all the different jobs.
@aodj The issue remains that post-install
helm hooks won't run until ALL the main Deployments (like the airflow Scheduler) are Ready when using the --wait
flag, which will never happen.
So, as far as I know, there is currently no solution that works in all cases except doing the db-migrations
with a Deployment. I have proposed a possible solution in upstream helm, see https://github.com/helm/helm/issues/10555#issuecomment-1515156101.
Interestingly, I think that ArgoCD might already support something similar to my proposed behavior with its own argocd.argoproj.io/hook: Snyc
hook. But there is currently no way to invoke via helm-hooks, so would require the inclusion of ArgoCD-specific annotation in the chart.
Also, if you are concerned about the resource usage of the Sync Deployments, I think there is a case to be made for consolidating them all into a single Deployment.
@aodj The issue remains that
post-install
helm hooks won't run until ALL the main Deployments (like the airflow Scheduler) are Ready when using the--wait
flag, which will never happen.
In my installations I've found that the db-migration is the only one that needs to be run to allow the webserver and scheduler to be considered healthy; Airflow will start up without connections, pools, users, and so on apparently without problem.
So, as far as I know, there is currently no solution that works in all cases except doing the
db-migrations
with a Deployment. I have proposed a possible solution in upstream helm, see helm/helm#10555 (comment).Interestingly, I think that ArgoCD might already support something similar to my proposed behavior with its own
argocd.argoproj.io/hook: Snyc
hook. But there is currently no way to invoke via helm-hooks, so would require the inclusion of ArgoCD-specific annotation in the chart.Also, if you are concerned about the resource usage of the Sync Deployments, I think there is a case to be made for consolidating them all into a single Deployment.
Would you be interested in my suggestion above to allow users of this chart control over the helm hooks? I don't mind the default settings but I would like the ability to override them if I so choose.
This issue has been automatically marked as stale because it has not had activity in 60 days. It will be closed in 7 days if no further activity occurs.
Thank you for your contributions.
Issues never become stale if any of the following is true:
lifecycle/frozen
label
Checks
User-Community Airflow Helm Chart
.Chart Version
8.6.1
Kubernetes Version
Helm Version
Description
It's not possible to change the
helm.sh
annotations on for the db-migrations job as they are hardcoded in the template:In the environment I'm deploying Airflow to, deployments are handled by Argo which waits for the webserver and scheduler to become "healthy" when deploying, before continuing with the db-migrations job, as defined by the
helm.sh/hook
value.As the job is set to run
post-install
, Argo doesn't run it until the other resources are ready (as explained in the Helm documentation under Hooks and the Release Lifecycle). This means in a new install, thecheck-for-db-migrations
initContainer will never complete, because thedb-migrations
job can't run, as the webserver and scheduler never become ready.I thought it would be a simple case of setting the
annotations
in thevalues.yaml
but I see now that the chart has them hard coded, and any attempt to set thesehelm.sh
annotations results in invalid yaml:This also applies to the other jobs, but they aren't critical for starting the deployments, so will eventually resolve themselves.
Relevant Logs
No response
Custom Helm Values
No response