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

Automatic loading of namespaced custom components #500

Merged
merged 50 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
08bfa8d
Create concept for namespaced custom components
disrupted Jun 26, 2024
a6a5b84
Remove components module from config
disrupted Jun 26, 2024
0e629af
Temporarily disable gen-schema hook
disrupted Jun 26, 2024
b83c5a2
Temporarily disable schema command
disrupted Jun 26, 2024
a4ff8e9
Temporarily disable schema test
disrupted Jun 26, 2024
406bfa3
Refactor Registry
disrupted Jun 26, 2024
61a2428
Temporarily disable test
disrupted Jun 26, 2024
ef07335
Refactor Schema Handler
disrupted Jun 26, 2024
1874705
Update test
disrupted Jun 26, 2024
28adbbf
Update test
disrupted Jun 26, 2024
62a490e
Update snapshot
disrupted Jun 26, 2024
e7418e5
Try testing
disrupted Jun 26, 2024
224a871
Refactor registry
disrupted Jun 26, 2024
43d06ff
Update Schema Handler
disrupted Jun 26, 2024
628ca21
Mark todo
disrupted Jun 26, 2024
c40ae5c
Update tests
disrupted Jun 26, 2024
246541f
Improve
disrupted Jun 26, 2024
f76c90d
Fix include package itself for module discovery
disrupted Jun 26, 2024
9ecbaa6
Fix Schema Handler
disrupted Jun 26, 2024
d0a37c9
Update Schema Handler tests
disrupted Jun 26, 2024
534b95f
Move common fixture to conftest
disrupted Jun 26, 2024
fb6f578
Fix test generate
disrupted Jun 26, 2024
0ff0173
Rename method
disrupted Jun 26, 2024
7cfd06a
Update gen docs hook
disrupted Jun 26, 2024
0b94046
Fix gen schema hook
disrupted Jun 26, 2024
eab2d4f
Revert "Temporarily disable gen-schema hook"
disrupted Jun 26, 2024
5af8684
Revert "Temporarily disable schema command"
disrupted Jun 26, 2024
af6997b
Update schema generation
disrupted Jun 26, 2024
d6d6749
Try namespace package
disrupted Jun 26, 2024
24d0e51
Fix Ruff lint
disrupted Jun 26, 2024
c7ec556
Add missing files
disrupted Jun 26, 2024
0279d76
Update test
disrupted Jun 26, 2024
d22e789
Revert mistake
disrupted Jun 26, 2024
0fe22e9
Improve CLI help
disrupted Jun 26, 2024
e454b1a
Add draft for migration
disrupted Jun 27, 2024
6809be3
Add components property to registry
disrupted Jun 27, 2024
aa30817
Cleanup & fix test
disrupted Jun 27, 2024
4bc8ae5
Cosmetic
disrupted Jun 27, 2024
951cfde
Fix `kpops --version`
disrupted Jun 27, 2024
f87d71a
Add test ensuring namespace compatibility
disrupted Jun 27, 2024
5ca9584
Update migration guide
disrupted Jul 3, 2024
1093c8d
Update migration guide
disrupted Jul 3, 2024
b329f60
Update config
disrupted Jul 3, 2024
84dd087
Update config
disrupted Jul 3, 2024
31636ca
Remove unnecessary test resources
disrupted Jul 3, 2024
475f2ce
Refactor module name
disrupted Jul 3, 2024
6b11a11
Merge remote-tracking branch 'origin/main' into feat/namespaced-custo…
disrupted Jul 8, 2024
56a5ce9
Refactor debug log
disrupted Jul 8, 2024
e1f3edc
Rename TypeVar for plugins
disrupted Jul 8, 2024
3af0c5e
Merge remote-tracking branch 'origin/main' into feat/namespaced-custo…
disrupted Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
kafka_brokers: "http://k8kafka-cp-kafka-headless.kpops.svc.cluster.local:9092"
components_module: tests.pipeline.test_components
pipeline_base_dir: tests/pipeline
9 changes: 2 additions & 7 deletions docs/docs/resources/pipeline-config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# CONFIGURATION
#
# Custom Python module defining project-specific KPOps components
components_module: null
# Base directory to the pipelines (default is current working directory)
pipeline_base_dir: .
# The Kafka brokers address.
# REQUIRED
kafka_brokers: "http://broker1:9092,http://broker2:9092"
# Configure the topic name variables you can use in the pipeline definition.
topic_name_config:
topic_name_config:
# Configures the value for the variable ${output_topic_name}
default_output_topic_name: ${pipeline.name}-${component.name}
# Configures the value for the variable ${error_topic_name}
Expand All @@ -27,9 +25,6 @@ kafka_rest:
kafka_connect:
# Address of Kafka Connect.
url: "http://localhost:8083"
# The timeout in seconds that specifies when actions like deletion or deploy
# timeout.
timeout: 300
# Flag for `helm upgrade --install`.
# Create the release namespace if not present.
create_namespace: false
Expand All @@ -42,7 +37,7 @@ helm_config:
# Kubernetes API version used for Capabilities.APIVersions
api_version: null
# Configure Helm Diff.
helm_diff_config:
helm_diff_config:
# Set of keys that should not be checked.
ignore:
- name
Expand Down
3 changes: 0 additions & 3 deletions docs/docs/resources/variables/config_env_vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# settings in `config.yaml`. Variables marked as required can instead
# be set in the global config.
#
# components_module
# Custom Python module defining project-specific KPOps components
KPOPS_COMPONENTS_MODULE # No default value, not required
# pipeline_base_dir
# Base directory to the pipelines (default is current working
# directory)
Expand Down
1 change: 0 additions & 1 deletion docs/docs/resources/variables/config_env_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ These variables take precedence over the settings in `config.yaml`. Variables ma

| Name | Default Value |Required| Description | Setting name |
|--------------------------------------------------|----------------------------------------|--------|----------------------------------------------------------------------------------|-------------------------------------------|
|KPOPS_COMPONENTS_MODULE | |False |Custom Python module defining project-specific KPOps components |components_module |
|KPOPS_PIPELINE_BASE_DIR |. |False |Base directory to the pipelines (default is current working directory) |pipeline_base_dir |
|KPOPS_KAFKA_BROKERS | |True |The comma separated Kafka brokers address. |kafka_brokers |
|KPOPS_TOPIC_NAME_CONFIG__DEFAULT_OUTPUT_TOPIC_NAME|${pipeline.name}-${component.name} |False |Configures the value for the variable ${output_topic_name} |topic_name_config.default_output_topic_name|
Expand Down
13 changes: 0 additions & 13 deletions docs/docs/schema/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,6 @@
"additionalProperties": false,
"description": "Global configuration for KPOps project.",
"properties": {
"components_module": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Custom Python module defining project-specific KPOps components",
"title": "Components Module"
},
"create_namespace": {
"default": false,
"description": "Flag for `helm upgrade --install`. Create the release namespace if not present.",
Expand Down
62 changes: 62 additions & 0 deletions docs/docs/user/migration-guide/v6-v7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Migrate from V6 to V7

## [Automatic loading of namespaced custom components](https://github.com/bakdata/kpops/pull/500)

KPOps is now distributed as a Python namespace package (as defined by [PEP 420](https://peps.python.org/pep-0420/)). This allows us to standardize the namespace `kpops.components` for both builtin and custom pipeline components.

As a result of the restructure, some imports need to be adjusted:

**KPOps Python API**

```diff
-import kpops
+import kpops.api as kpops
```

**builtin KPOps components**

```diff
-from kpops.components import (
- HelmApp,
- KafkaApp,
- KafkaConnector,
- KafkaSinkConnector,
- KafkaSourceConnector,
- KubernetesApp,
- StreamsBootstrap,
- ProducerApp,
- StreamsApp,
- PipelineComponent,
- StreamsApp,
- ProducerApp,
-)
+from kpops.components.base_components import (
+ HelmApp,
+ KafkaApp,
+ KafkaConnector,
+ KafkaSinkConnector,
+ KafkaSourceConnector,
+ KubernetesApp,
+ PipelineComponent,
+)
+from kpops.components.streams_bootstrap import (
+ StreamsBootstrap,
+ StreamsApp,
+ ProducerApp,
+)
```

### your custom KPOps components

#### config.yaml

```diff
-components_module: components
```

#### Python module

```diff
-components/__init__.py
+kpops/components/custom/__init__.py
```
9 changes: 5 additions & 4 deletions docs/docs/user/references/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,16 @@ $ kpops schema [OPTIONS] SCOPE:{pipeline|defaults|config}



pipeline: Schema of PipelineComponents. Includes the built-in KPOps components by default. To include custom components, provide components module in config.
- pipeline: Schema of PipelineComponents for KPOps pipeline.yaml


- defaults: Schema of PipelineComponents for KPOps defaults.yaml


config: Schema of KpopsConfig. [required]
- config: Schema for KPOps config.yaml [required]

**Options**:

* `--config DIRECTORY`: Path to the dir containing config.yaml files [env var: KPOPS_CONFIG_PATH; default: .]
* `--include-stock-components / --no-include-stock-components`: Include the built-in KPOps components. [default: include-stock-components]
* `--help`: Show this message and exit.
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ nav:
- Migrate from v3 to v4: user/migration-guide/v3-v4.md
- Migrate from v4 to v5: user/migration-guide/v4-v5.md
- Migrate from v5 to v6: user/migration-guide/v5-v6.md
- Migrate from v6 to v7: user/migration-guide/v6-v7.md
- CLI usage: user/references/cli-commands.md
- Editor integration: user/references/editor-integration.md
- CI integration:
Expand Down
12 changes: 9 additions & 3 deletions hooks/gen_docs/gen_docs_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
import yaml

from hooks import ROOT
from kpops.api.registry import _find_classes
from kpops.components import KafkaConnector, PipelineComponent
from kpops.api.registry import Registry
from kpops.components.base_components.kafka_connector import KafkaConnector
from kpops.components.base_components.pipeline_component import (
PipelineComponent,
)
from kpops.utils.colorify import redify, yellowify
from kpops.utils.pydantic import issubclass_patched
from kpops.utils.yaml import load_yaml_file

registry = Registry()
registry.discover_components()

PATH_KPOPS_MAIN = ROOT / "kpops/cli/main.py"
PATH_CLI_COMMANDS_DOC = ROOT / "docs/docs/user/references/cli-commands.md"
PATH_DOCS_RESOURCES = ROOT / "docs/docs/resources"
Expand All @@ -33,7 +39,7 @@
(PATH_DOCS_RESOURCES / "pipeline-defaults/headers").iterdir(),
)

KPOPS_COMPONENTS = tuple(_find_classes("kpops.components", PipelineComponent))
KPOPS_COMPONENTS = tuple(registry.components)
KPOPS_COMPONENTS_SECTIONS = {
component.type: [
field_name
Expand Down
14 changes: 0 additions & 14 deletions kpops/__init__.py

This file was deleted.

17 changes: 7 additions & 10 deletions kpops/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pathlib import Path
from typing import TYPE_CHECKING

import kpops
from kpops.api.logs import log, log_action
from kpops.api.options import FilterType
from kpops.api.registry import Registry
Expand All @@ -23,8 +22,8 @@
from kpops.utils.cli_commands import init_project

if TYPE_CHECKING:
from kpops.components import PipelineComponent
from kpops.components.base_components.models.resource import Resource
from kpops.components.base_components.pipeline_component import PipelineComponent
from kpops.config import KpopsConfig


Expand Down Expand Up @@ -90,7 +89,7 @@ def manifest(
:param verbose: Enable verbose printing.
:return: Resources.
"""
pipeline = kpops.generate(
pipeline = generate(
pipeline_path=pipeline_path,
dotenv=dotenv,
config=config,
Expand Down Expand Up @@ -129,7 +128,7 @@ def deploy(
:param verbose: Enable verbose printing.
:param parallel: Enable or disable parallel execution of pipeline steps.
"""
pipeline = kpops.generate(
pipeline = generate(
pipeline_path=pipeline_path,
dotenv=dotenv,
config=config,
Expand Down Expand Up @@ -177,7 +176,7 @@ def destroy(
:param verbose: Enable verbose printing.
:param parallel: Enable or disable parallel execution of pipeline steps.
"""
pipeline = kpops.generate(
pipeline = generate(
pipeline_path=pipeline_path,
dotenv=dotenv,
config=config,
Expand Down Expand Up @@ -227,7 +226,7 @@ def reset(
:param verbose: Enable verbose printing.
:param parallel: Enable or disable parallel execution of pipeline steps.
"""
pipeline = kpops.generate(
pipeline = generate(
pipeline_path=pipeline_path,
dotenv=dotenv,
config=config,
Expand Down Expand Up @@ -276,7 +275,7 @@ def clean(
:param verbose: Enable verbose printing.
:param parallel: Enable or disable parallel execution of pipeline steps.
"""
pipeline = kpops.generate(
pipeline = generate(
pipeline_path=pipeline_path,
dotenv=dotenv,
config=config,
Expand Down Expand Up @@ -333,9 +332,7 @@ def _create_pipeline(
:return: Created `Pipeline` object.
"""
registry = Registry()
if kpops_config.components_module:
registry.find_components(kpops_config.components_module)
registry.find_components("kpops.components")
registry.discover_components()

handlers = _setup_handlers(kpops_config)
parser = PipelineGenerator(kpops_config, registry, handlers)
Expand Down
5 changes: 5 additions & 0 deletions kpops/api/file_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ def as_yaml_file(self, prefix: str = "", suffix: str = "") -> str:
'pre_pipeline_suf.yaml'
"""
return prefix + self.value + suffix + FILE_EXTENSION


PIPELINE_YAML = KpopsFileType.PIPELINE.as_yaml_file()
DEFAULTS_YAML = KpopsFileType.DEFAULTS.as_yaml_file()
CONFIG_YAML = KpopsFileType.CONFIG.as_yaml_file()
2 changes: 1 addition & 1 deletion kpops/api/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import typer

if TYPE_CHECKING:
from kpops.components import PipelineComponent
from kpops.components.base_components.pipeline_component import PipelineComponent


class CustomFormatter(logging.Formatter):
Expand Down
2 changes: 1 addition & 1 deletion kpops/api/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from kpops.components import PipelineComponent
from kpops.components.base_components.pipeline_component import PipelineComponent
from kpops.pipeline import ComponentFilterPredicate


Expand Down
Loading
Loading