Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git sync option and unit tests for the Helm chart #9371

Merged
merged 19 commits into from
Jul 5, 2020

Conversation

aneesh-joseph
Copy link
Contributor

@aneesh-joseph aneesh-joseph commented Jun 18, 2020


Make sure to mark the boxes below before creating PR: [x]

  • Description above provides context of the change
  • Unit tests coverage for changes (not needed for documentation changes)
  • Target Github ISSUE in description if exists
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions.
  • I will engage committers as explained in Contribution Workflow Example.

In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

Improve the helm chart with:

  • Add capability to sync dags using a git-sync sidecar
    • git sync over ssh with ssh key sourced from kubernetes secrets
    • provide a way to specify known_hosts when using git sync over ssh with an ssh key
    • git sync without ssh
    • credentials support for git sync without ssh(credentials sourced from a kubernetes secret)
    • Persistence support using PVC. if enabled the scheduler will sync dags to the PVC and others will mount the synced dags
  • Add helm-unit tests. The CI tests use an image published using the Dockerfile from a forked repo https://github.com/aneesh-joseph/helm-unittest.
    • Add CI flow for helm unit tests
    • Add tests for git sync

@boring-cyborg boring-cyborg bot added the area:helm-chart Airflow Helm Chart label Jun 18, 2020
@aneesh-joseph aneesh-joseph force-pushed the git-sync branch 4 times, most recently from d2162f6 to 51fb039 Compare June 18, 2020 15:33
@@ -82,6 +82,9 @@ spec:
{{- include "custom_airflow_environment" . | indent 10 }}
{{- include "standard_airflow_environment" . | indent 10 }}
containers:
{{- if .Values.gitSync.enabled }}
Copy link
Contributor Author

@aneesh-joseph aneesh-joseph Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dag sync won't be needed on the webserver if dag serialization is enabled

@@ -434,3 +434,23 @@ postgresql:
enabled: true
postgresqlPassword: postgres
postgresqlUsername: postgres
# Git sync
gitSync:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put this under a kubernetesExecutor section in case we need to expand to further k8sexecutor-specific features

Copy link
Contributor Author

@aneesh-joseph aneesh-joseph Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought the same, but the git sync sidecars might also be used without the KubernetesExecutor ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok yeah I can see that. would just need to set a relatively fast cycle for pinging/re-pulling the repo s.t. the worker stays in sync with the scheduler/webserver.

Copy link
Contributor Author

@aneesh-joseph aneesh-joseph Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the sync interval to a default of 1 minute, have added in a PVC as well

# ssh example: [email protected]:aneesh-joseph/dags-repo.git
# https example: https://github.com/aneesh-joseph/dags-repo.git
#TODO Change the URLs used for testing
repo: https://github.com/aneesh-joseph/dags-repo.git
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to the apache project.

Copy link
Contributor Author

@aneesh-joseph aneesh-joseph Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aneesh-joseph aneesh-joseph requested a review from dimberman June 18, 2020 19:40
@aneesh-joseph aneesh-joseph force-pushed the git-sync branch 2 times, most recently from 8b13e51 to 5d60c26 Compare June 19, 2020 02:58
@aneesh-joseph aneesh-joseph changed the title Add git sync option to the Helm chart Add git sync option & helm unit tests Jun 19, 2020
@aneesh-joseph aneesh-joseph force-pushed the git-sync branch 10 times, most recently from c317639 to d2abd4f Compare June 19, 2020 06:34

docker run -w /airflow-chart -v "$CHART_DIR":/airflow-chart \
--entrypoint /bin/sh \
divya12/helm-unittest \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to change this image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue: #9401 - we have a few more "private" images that we depend on, we should replace them with our own copy of those images. For now it can stay like it is .

# [email protected]:apache/airflow.git
# https example: https://github.com/apache/airflow.git
repo: https://github.com/apache/airflow.git
branch: v1-10-stable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it later to a variable. But for now iI think it's good. I plan to use the Helm chart not only for unit tests (which are great BTW) but also to run our Kubernetes tests (we are currently using some custom, simple templates for the kubernetes resources - replacing it with the helm chart from master and using images built locally will be a great way to do doggfooding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, that would be awesome 👍

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aneesh-joseph aneesh-joseph force-pushed the git-sync branch 2 times, most recently from 1f54704 to 5b36045 Compare July 4, 2020 02:09
@aneesh-joseph
Copy link
Contributor Author

@dimberman @ashb @potiuk - the tests are now passing, can you help in getting this merged please

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Change! I was thinking - shoudl not we also update the tests in test_kubernetes? we already have git_sync mode for those tests but it is disable - I am happy to help in switching the git_sync tests on. We can do it in a separate change but it actually belongs here.
@dimberman WDYT?

@@ -66,7 +66,7 @@ The command removes all the Kubernetes components associated with the chart and

## Updating DAGs

The recommended way to update your DAGs with this chart is to build a new docker image with the latest code (`docker build -t my-company/airflow:8a0da78 .`), push it to an accessible registry (`docker push my-company/airflow:8a0da78`), then update the Airflow pods with that image:
The recommended way to update your DAGs with this chart is to build a new docker image with the latest DAG code (`docker build -t my-company/airflow:8a0da78 .`), push it to an accessible registry (`docker push my-company/airflow:8a0da78`), then update the Airflow pods with that image:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will want to change that description as it is not valid any more and we have "EMBED_DAGS" directive while building the dockerfiles + we will add on-build most likely to add the DAGs on building deppendent image but I will do it separately.

# Refer values.yaml for details
```

## Mounting DAGS using Git-Sync side car without Persistence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have this option.!

chart/README.md Outdated Show resolved Hide resolved
chart/README.md Outdated Show resolved Hide resolved
chart/README.md Outdated Show resolved Hide resolved
@@ -1,6 +0,0 @@
dependencies:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do wer delete this ?

@@ -0,0 +1,64 @@
# Licensed to the Apache Software Foundation (ASF) under one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the unit tests of helm chart! ❤️

@dimberman dimberman merged commit d93555b into apache:master Jul 5, 2020
@friedhardware
Copy link

Where is this chart hosted? Is it related to https://hub.helm.sh/charts/stable/airflow?

@marclamberti
Copy link

@friedhardware, this chart is only available from this repo for now and it is the official one, not related to the current one on Helm.sh

{{- if .Values.dags.persistence.enabled }}
- name: dags
persistentVolumeClaim:
claimName: {{ .Release.Name }}-dags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If uses dags.persistence.existingClaim, it should be modified to
claimName: {{ .Values.dags.persistence.existingClaim }}.
Currently, the webserver pod cannot find pvc, so it is put in a pending state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have raised a PR to fix this - #9688

@aneesh-joseph aneesh-joseph deleted the git-sync branch July 6, 2020 10:58
@marclamberti
Copy link

I got an issue yesterday with git-sync and the K8s worker pods.
If we specify:
AIRFLOW__KUBERNETES__RUN_AS_USER="50000" in values, git-sync ends up with the following error in K8s worker pods:
E0715 21:13:28.459419 9 main.go:347] "msg"="failed to sync repo, aborting" "error"="error running command: exit status 128: { stdout: \"\", stderr: \"Cloning into '/git'...\\nNo user exists for uid 50000\\r\\nfatal: Could not read from remote repository.\\n\\nPlease make sure you have the correct access rights\\nand the repository exists.\\n\" }"

Nonetheless, git-sync along with the webserver and scheduler of Airflow works since the env var AIRFLOW__KUBERNETES__RUN_AS_USER="50000" isn't set which is not the case in the K8S worker pods.

To fix this, we have to define
AIRFLOW__KUBERNETES__GIT_SYNC_RUN_AS_USER="65553" corresponding to the default uid of git-sync.

Also, we have to set the UID to 50000 otherwise Airflow fails with the following error:

Traceback (most recent call last):
  File "/home/airflow/.local/bin/airflow", line 23, in <module>
    import argcomplete
ModuleNotFoundError: No module named 'argcomplete'

@aneesh-joseph
Copy link
Contributor Author

I got an issue yesterday with git-sync and the K8s worker pods.
If we specify:
AIRFLOW__KUBERNETES__RUN_AS_USER="50000" in values, git-sync ends up with the following error in K8s worker pods:
E0715 21:13:28.459419 9 main.go:347] "msg"="failed to sync repo, aborting" "error"="error running command: exit status 128: { stdout: \"\", stderr: \"Cloning into '/git'...\\nNo user exists for uid 50000\\r\\nfatal: Could not read from remote repository.\\n\\nPlease make sure you have the correct access rights\\nand the repository exists.\\n\" }"

Nonetheless, git-sync along with the webserver and scheduler of Airflow works since the env var AIRFLOW__KUBERNETES__RUN_AS_USER="50000" isn't set which is not the case in the K8S worker pods.

To fix this, we have to define
AIRFLOW__KUBERNETES__GIT_SYNC_RUN_AS_USER="65553" corresponding to the default uid of git-sync.

Also, we have to set the UID to 50000 otherwise Airflow fails with the following error:

Traceback (most recent call last):
  File "/home/airflow/.local/bin/airflow", line 23, in <module>
    import argcomplete
ModuleNotFoundError: No module named 'argcomplete'

yes it might be failing as the user 50000 doesn't exist in /etc/passwd and ssh needs that. setting AIRFLOW__KUBERNETES__GIT_SYNC_RUN_AS_USER to 65553(may need to set fs_group as well - not very sure) will fix it or setting GIT_SYNC_ADD_USER env var on the init container should fix it as well(we do this on scheduler & webserver). I had added that change to the worker pods but that's not part of 1.10.11 https://github.com/apache/airflow/pull/9371/files#r442960495. think run_as_user is already defaulted to 50000 ({{ .Values.uid }}) in the config map rendered by the chart

dimberman pushed a commit that referenced this pull request Jul 20, 2020
* add git sync sidecars

* add a helm test

* add more tests

* allow users to provide git username and pass via  a k8s secrets

* set default values for airflow worker repository & tag

* change ci timeout

* fix link

* add credentials_secret to airflow.cfg configmap

* set GIT_SYNC_ADD_USER on kubernetes worker pods, set uid

* add fsGroup to webserver and kubernete workers

* move gitSync to dags.gitSync

* rename valueFields

* turn off git sync and dag persistence by default

* provide option to specify known_hosts

* add git-sync details into the chart documentation

* Update .gitignore

Co-authored-by: Ash Berlin-Taylor <[email protected]>

* make git sync max failures configurable

* Apply suggestions from code review

Co-authored-by: Jarek Potiuk <[email protected]>

* add back requirements.lock

Co-authored-by: Ash Berlin-Taylor <[email protected]>
Co-authored-by: Jarek Potiuk <[email protected]>
(cherry picked from commit d93555b)
potiuk pushed a commit that referenced this pull request Jul 22, 2020
* add git sync sidecars

* add a helm test

* add more tests

* allow users to provide git username and pass via  a k8s secrets

* set default values for airflow worker repository & tag

* change ci timeout

* fix link

* add credentials_secret to airflow.cfg configmap

* set GIT_SYNC_ADD_USER on kubernetes worker pods, set uid

* add fsGroup to webserver and kubernete workers

* move gitSync to dags.gitSync

* rename valueFields

* turn off git sync and dag persistence by default

* provide option to specify known_hosts

* add git-sync details into the chart documentation

* Update .gitignore

Co-authored-by: Ash Berlin-Taylor <[email protected]>

* make git sync max failures configurable

* Apply suggestions from code review

Co-authored-by: Jarek Potiuk <[email protected]>

* add back requirements.lock

Co-authored-by: Ash Berlin-Taylor <[email protected]>
Co-authored-by: Jarek Potiuk <[email protected]>
(cherry picked from commit d93555b)
cfei18 pushed a commit to cfei18/incubator-airflow that referenced this pull request Mar 5, 2021
* add git sync sidecars

* add a helm test

* add more tests

* allow users to provide git username and pass via  a k8s secrets

* set default values for airflow worker repository & tag

* change ci timeout

* fix link

* add credentials_secret to airflow.cfg configmap

* set GIT_SYNC_ADD_USER on kubernetes worker pods, set uid

* add fsGroup to webserver and kubernete workers

* move gitSync to dags.gitSync

* rename valueFields

* turn off git sync and dag persistence by default

* provide option to specify known_hosts

* add git-sync details into the chart documentation

* Update .gitignore

Co-authored-by: Ash Berlin-Taylor <[email protected]>

* make git sync max failures configurable

* Apply suggestions from code review

Co-authored-by: Jarek Potiuk <[email protected]>

* add back requirements.lock

Co-authored-by: Ash Berlin-Taylor <[email protected]>
Co-authored-by: Jarek Potiuk <[email protected]>
(cherry picked from commit d93555b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:helm-chart Airflow Helm Chart
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants