-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Create a generic callbacks class for KubernetesPodOperator #35714
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b841b49
Create a generic callbacks class for KubernetesPodOperator
hussein-awala dde518d
Merge branch 'main' into kpo_callbacks
hussein-awala 2797aef
Trigger tests with old-style union
hussein-awala 6b884f0
Fix GCP K8S test
hussein-awala 3ddfd82
Fix callback param type and cleanup calls
hussein-awala d245298
Some fixes and add unit tests
hussein-awala f722e40
Replace type by Type
hussein-awala c4ae081
Reset mock_callbacks in pod manager tests
hussein-awala c13b95e
Merge branch 'main' into kpo_callbacks
hussein-awala 6173c1b
Fix static checks
hussein-awala b1755af
Add a doc paragraph for the new callbacks
hussein-awala 1860881
Add a check for cncf-kuberntes version in google provider
hussein-awala 479b3c8
Merge branch 'main' into kpo_callbacks
hussein-awala d9fd475
Switch to None default value and bump min cncf-k8s provider in google…
hussein-awala 255b060
Merge branch 'main' into kpo_callbacks
hussein-awala 39ece30
Fix tests
hussein-awala 1d133d7
Reduce check intervals to avoid killing the asyncio task
hussein-awala be57a68
Merge branch 'main' into kpo_callbacks
hussein-awala 79354e8
Revert async callbacks
hussein-awala f56a925
fix breeze tests
hussein-awala 3470855
Merge branch 'main' into kpo_callbacks
hussein-awala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| from enum import Enum | ||
| from typing import Union | ||
|
|
||
| import kubernetes.client as k8s | ||
| import kubernetes_asyncio.client as async_k8s | ||
|
|
||
| client_type = Union[k8s.CoreV1Api, async_k8s.CoreV1Api] | ||
|
|
||
|
|
||
| class ExecutionMode(str, Enum): | ||
| """Enum class for execution mode.""" | ||
|
|
||
| SYNC = "sync" | ||
| ASYNC = "async" | ||
|
|
||
|
|
||
| class KubernetesPodOperatorCallback: | ||
| """`KubernetesPodOperator` callbacks methods. | ||
|
|
||
| Currently, the callbacks methods are not called in the async mode, this support will be added | ||
| in the future. | ||
| """ | ||
|
|
||
| @staticmethod | ||
| def on_sync_client_creation(*, client: k8s.CoreV1Api, **kwargs) -> None: | ||
| """Callback method called after creating the sync client. | ||
|
|
||
| :param client: the created `kubernetes.client.CoreV1Api` client. | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_pod_creation(*, pod: k8s.V1Pod, client: client_type, mode: str, **kwargs) -> None: | ||
| """Callback method called after creating the pod. | ||
|
|
||
| :param pod: the created pod. | ||
| :param client: the Kubernetes client that can be used in the callback. | ||
| :param mode: the current execution mode, it's one of (`sync`, `async`). | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_pod_starting(*, pod: k8s.V1Pod, client: client_type, mode: str, **kwargs) -> None: | ||
| """Callback method called when the pod starts. | ||
|
|
||
| :param pod: the started pod. | ||
| :param client: the Kubernetes client that can be used in the callback. | ||
| :param mode: the current execution mode, it's one of (`sync`, `async`). | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_pod_completion(*, pod: k8s.V1Pod, client: client_type, mode: str, **kwargs) -> None: | ||
| """Callback method called when the pod completes. | ||
|
|
||
| :param pod: the completed pod. | ||
| :param client: the Kubernetes client that can be used in the callback. | ||
| :param mode: the current execution mode, it's one of (`sync`, `async`). | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_pod_cleanup(*, pod: k8s.V1Pod, client: client_type, mode: str, **kwargs): | ||
| """Callback method called after cleaning/deleting the pod. | ||
|
|
||
| :param pod: the completed pod. | ||
| :param client: the Kubernetes client that can be used in the callback. | ||
| :param mode: the current execution mode, it's one of (`sync`, `async`). | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def on_operator_resuming( | ||
| *, pod: k8s.V1Pod, event: dict, client: client_type, mode: str, **kwargs | ||
| ) -> None: | ||
| """Callback method called when resuming the `KubernetesPodOperator` from deferred state. | ||
|
|
||
| :param pod: the current state of the pod. | ||
| :param event: the returned event from the Trigger. | ||
| :param client: the Kubernetes client that can be used in the callback. | ||
| :param mode: the current execution mode, it's one of (`sync`, `async`). | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def progress_callback(*, line: str, client: client_type, mode: str, **kwargs) -> None: | ||
| """Callback method to process pod container logs. | ||
|
|
||
| :param line: the read line of log. | ||
| :param client: the Kubernetes client that can be used in the callback. | ||
| :param mode: the current execution mode, it's one of (`sync`, `async`). | ||
| """ | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.