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

dbt with kubernetes #493

Closed
rtooker opened this issue Aug 25, 2023 · 7 comments · Fixed by #554
Closed

dbt with kubernetes #493

rtooker opened this issue Aug 25, 2023 · 7 comments · Fixed by #554
Milestone

Comments

@rtooker
Copy link

rtooker commented Aug 25, 2023

Similar to #491 but I think subtly different.

I'm using

  • apache-airflow==2.6.3
  • astronomer-cosmos==1.0.5

DbtTaskGroup has a mandatory profile_config arg, but when set this seems to be passed through to the DbtRunKubernetesPodOperator causing in exception

with DAG(
    Path(__file__).stem,
    description="*****",
    schedule=None,
    start_date=datetime(2023,1,1),
    catchup=False,
) as dag:
    dbt_task_group = DbtTaskGroup(
        project_config=ProjectConfig(
            dbt_project_path = Path(__file__).parent / 'dbt',
            manifest_path=Path(__file__).parent / 'manifests' / 'manifest.json',
        ),
        render_config=RenderConfig(
            load_method=LoadMode.DBT_MANIFEST,
        ),
        execution_config=ExecutionConfig(
            execution_mode=ExecutionMode.KUBERNETES,
        ),
        profile_config=ProfileConfig(
            profile_name='*****',
            target_name='*****'
        ),
        operator_args={
           ...
        }
    )



if __name__ == "__main__":
    dag.test()

yields

airflow.exceptions.AirflowException: Invalid arguments were passed to DbtRunKubernetesOperator (task_id: ******). Invalid arguments were:
**kwargs: {'profile_config': ProfileConfig(profile_name='****', target_name='****', profiles_yml_filepath=None, profile_mapping=None)}
@adityasharma1685
Copy link

After moving my DBT project under Airflow Dags folder, I am getting same error.

@david-mag
Copy link
Contributor

I've got the same issue. The step-by-step guide in the documentation doesn't look like its up to date either. It uses imports (from cosmos.providers.dbt.task_group import DbtTaskGroup) that don't work with the latest version of cosmos anymore.

@david-mag
Copy link
Contributor

david-mag commented Sep 2, 2023

I've added a pull request for an attempt to fix this issue here.

jlaneve pushed a commit that referenced this issue Sep 5, 2023
## Description

When creating `DbtTaskGroup`s and `DbtDag`s, a `ProfileConfig` needs to
be provided, since it's a required positional argument of the
`DbtAirflowConverter` class. However, when providing a `profile_config`
in `execution_mode="kubernetes"`, the following Exception is thrown:
```
AirflowException: Invalid arguments were passed to DbtRunKubernetesOperator (task_id: my_first_dbt_model_run). Invalid arguments were:
**kwargs: {'profile_config': ProfileConfig(profile_name='jaffle_shop', target_name='dev', profiles_yml_filepath='jaffle_shop/profiles.yml', profile_mapping=None)}
```

In my humble attempt of a solution, I make the `profile_config` an
optional argument of the `DbtKubernetesBaseOperator` class (mainly to
satisfy the tests ... since its a required argument in the previous part
of the "pipeline", having it being a required argument would make sense
imho) and parse it inside the `build_kube_args` method (similar, but not
identically) to how it is done in the `run_command` method of the
`DbtLocalBaseOperator` class.

This solution fixes the thrown exception and has the added benefit of
giving the user that want to run dbt inside kubernetes the option to
specify `--profile` and `--target`, which is a useful feature when
wanting to schedule the same model in airflow, pointing to dev and prod
targets.

I've tested this solution in my GCC environment.

## Related Issue(s)

This PR resolves the issue in issue #493

## Breaking Change?

This should fix something that is broken atm, as far as I can see.

## Checklist

- [ ] I have made corresponding changes to the documentation (if
required)
- [ ] I have added tests that prove my fix is effective or that my
feature works
@rtooker
Copy link
Author

rtooker commented Sep 13, 2023

Thanks @david-mag .
I'm now getting the same issue as reported in #505 (comment)

airflow.exceptions.AirflowException: Invalid arguments were passed to DbtRunKubernetesOperator (task_id: XXXX). Invalid arguments were:
**kwargs: {'emit_datasets': True}

@david-mag
Copy link
Contributor

As far as I can see, with the release of this fix, more "unknown" arguments have been added, which broke the kubernetes DAGs and TaskGroups again right away.

@adityasharma1685
Copy link

adityasharma1685 commented Sep 18, 2023

While trying latest release(1.1.1) I ran into another issue and getting below exception:

from airflow.providers.cncf.kubernetes.operators.pod import KubernetesPodOperator
except ImportError:
    raise ImportError(
        "Could not import KubernetesPodOperator. Ensure you've installed the Kubernetes provider "
        "separately or with with `pip install astronomer-cosmos[...,kubernetes]`."
    )

https://github.com/astronomer/astronomer-cosmos/blob/main/cosmos/operators/kubernetes.py#L21-L26
I am using Airflow=2.5.3 and apache-airflow-providers-cncf-kubernetes==5.2.2 .

It seems like the latest version of the cosmos is using the Kubernetes >= 7.4 though the toml file says kubernetes version >=5.1 < 7.3

tatiana added a commit that referenced this issue Sep 27, 2023
Fix behaviour when using `ExecutionMode.KUBERNETES`, broken between the
Cosmos releases 1.0.0 and 1.1.1.

Update the documentation to be representative of the 1.x Cosmos
interface:

https://astronomer.github.io/astronomer-cosmos/getting_started/kubernetes.html

Add unit tests to avoid regressions on these fixes.

Part of the documentation fixes are made in:
astronomer/cosmos-example#4

As a next step, we must ensure integration tests for running Cosmos on
K8s to avoid this breaking change moving forward (issue #535).

Closes: #493
Closes: #548
Closes: #534

Co-authored-by: Pádraic Slattery <pgoslatara@gmail.com> (who created PR #551)
tatiana added a commit that referenced this issue Sep 27, 2023
Fix behaviour when using `ExecutionMode.KUBERNETES`, broken between the
Cosmos releases 1.0.0 and 1.1.1.

Update the documentation to be representative of the 1.x Cosmos
interface:

https://astronomer.github.io/astronomer-cosmos/getting_started/kubernetes.html

Add unit tests to avoid regressions on these fixes.

Part of the documentation fixes are made in:
astronomer/cosmos-example#4

As a next step, we must ensure integration tests for running Cosmos on
K8s to avoid this breaking change moving forward (issue #535).

Closes: #493
Closes: #548
Closes: #534

Co-authored-by: Pádraic Slattery <pgoslatara@gmail.com>
tatiana added a commit that referenced this issue Sep 27, 2023
Fix behaviour when using `ExecutionMode.KUBERNETES`, broken between the
Cosmos releases 1.0.0 and 1.1.1.

Update the documentation to be representative of the 1.x Cosmos
interface:

https://astronomer.github.io/astronomer-cosmos/getting_started/kubernetes.html

Add unit tests to avoid regressions on these fixes.

Part of the documentation fixes are made in:
astronomer/cosmos-example#4

As a next step, we must ensure integration tests for running Cosmos on
K8s to avoid this breaking change moving forward (issue #535).

Closes: #493
Closes: #548
Closes: #534

Co-authored-by: Pádraic Slattery <pgoslatara@gmail.com>
@tatiana
Copy link
Collaborator

tatiana commented Sep 27, 2023

Thanks for the details, @rtooker @adityasharma1685 @david-mag, for all the support and information.

I believe the release astronomer-cosmos 1.1.2 will solve the pending issues described in this thread:
https://github.com/astronomer/astronomer-cosmos/releases/tag/astronomer-cosmos-v1.1.2
https://pypi.org/project/astronomer-cosmos/1.1.2/

Please, do reach out if any of them persist.

@tatiana tatiana added this to the 1.1.2 milestone Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants