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

QA Kubernetes Tasks #1559

Merged
merged 8 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/
### Task Library

- Add `BlobStorageDownload` and `BlobStorageUpload` for interacting with data stored on Azure Blob Storage - [#692](https://github.com/PrefectHQ/prefect/pull/1538)
- Loosen Kubernetes Tasks' requirement of an API secret key - [#1559](https://github.com/PrefectHQ/prefect/pull/1559)

### Fixes

Expand Down
67 changes: 49 additions & 18 deletions src/prefect/tasks/kubernetes/deployment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any

from kubernetes import client, config
from kubernetes.config.config_exception import ConfigException

from prefect import Task
from prefect.client import Secret
Expand All @@ -16,7 +17,10 @@ class CreateNamespacedDeployment(Task):
the first successful connection attempt becoming the mode of communication with a
cluster.

1. Attempt to use a Prefect Secret that contains a Kubernetes API Key
1. Attempt to use a Prefect Secret that contains a Kubernetes API Key. If
`kubernetes_api_key_secret` = `None` then it will attempt the next two connection
mathods. By default the value is `KUBERNETES_API_KEY` so providing `None` acts as
an override for the remote connection.
2. Attempt in-cluster connection (will only work when running on a Pod in a cluster)
3. Attempt out-of-cluster connection using the default location for a kube config file

Expand Down Expand Up @@ -87,7 +91,9 @@ def run(
"A dictionary representing a ExtensionsV1beta1Deployment must be provided."
)

kubernetes_api_key = Secret(kubernetes_api_key_secret).get()
kubernetes_api_key = None
if kubernetes_api_key_secret:
kubernetes_api_key = Secret(kubernetes_api_key_secret).get()
cicdw marked this conversation as resolved.
Show resolved Hide resolved

if kubernetes_api_key:
configuration = client.Configuration()
Expand All @@ -96,7 +102,7 @@ def run(
else:
try:
config.load_incluster_config()
except config.config_exception.ConfigException:
except ConfigException:
config.load_kube_config()

api_client = client.ExtensionsV1beta1Api()
Expand All @@ -118,7 +124,10 @@ class DeleteNamespacedDeployment(Task):
the first successful connection attempt becoming the mode of communication with a
cluster.

1. Attempt to use a Prefect Secret that contains a Kubernetes API Key
1. Attempt to use a Prefect Secret that contains a Kubernetes API Key. If
`kubernetes_api_key_secret` = `None` then it will attempt the next two connection
mathods. By default the value is `KUBERNETES_API_KEY` so providing `None` acts as
an override for the remote connection.
2. Attempt in-cluster connection (will only work when running on a Pod in a cluster)
3. Attempt out-of-cluster connection using the default location for a kube config file

Expand Down Expand Up @@ -185,7 +194,9 @@ def run(
if not deployment_name:
raise ValueError("The name of a Kubernetes deployment must be provided.")

kubernetes_api_key = Secret(kubernetes_api_key_secret).get()
kubernetes_api_key = None
if kubernetes_api_key_secret:
kubernetes_api_key = Secret(kubernetes_api_key_secret).get()

if kubernetes_api_key:
configuration = client.Configuration()
Expand All @@ -194,7 +205,7 @@ def run(
else:
try:
config.load_incluster_config()
except config.config_exception.ConfigException:
except ConfigException:
config.load_kube_config()

api_client = client.ExtensionsV1beta1Api()
Expand All @@ -218,7 +229,10 @@ class ListNamespacedDeployment(Task):
the first successful connection attempt becoming the mode of communication with a
cluster.

1. Attempt to use a Prefect Secret that contains a Kubernetes API Key
1. Attempt to use a Prefect Secret that contains a Kubernetes API Key. If
`kubernetes_api_key_secret` = `None` then it will attempt the next two connection
mathods. By default the value is `KUBERNETES_API_KEY` so providing `None` acts as
an override for the remote connection.
2. Attempt in-cluster connection (will only work when running on a Pod in a cluster)
3. Attempt out-of-cluster connection using the default location for a kube config file

Expand Down Expand Up @@ -276,7 +290,9 @@ def run(
- ExtensionsV1beta1DeploymentList: a Kubernetes ExtensionsV1beta1DeploymentList
of the deployments which are found
"""
kubernetes_api_key = Secret(kubernetes_api_key_secret).get()
kubernetes_api_key = None
if kubernetes_api_key_secret:
kubernetes_api_key = Secret(kubernetes_api_key_secret).get()

if kubernetes_api_key:
configuration = client.Configuration()
Expand All @@ -285,7 +301,7 @@ def run(
else:
try:
config.load_incluster_config()
except config.config_exception.ConfigException:
except ConfigException:
config.load_kube_config()

api_client = client.ExtensionsV1beta1Api()
Expand All @@ -304,7 +320,10 @@ class PatchNamespacedDeployment(Task):
the first successful connection attempt becoming the mode of communication with a
cluster.

1. Attempt to use a Prefect Secret that contains a Kubernetes API Key
1. Attempt to use a Prefect Secret that contains a Kubernetes API Key. If
`kubernetes_api_key_secret` = `None` then it will attempt the next two connection
mathods. By default the value is `KUBERNETES_API_KEY` so providing `None` acts as
an override for the remote connection.
2. Attempt in-cluster connection (will only work when running on a Pod in a cluster)
3. Attempt out-of-cluster connection using the default location for a kube config file

Expand Down Expand Up @@ -388,7 +407,9 @@ def run(
if not deployment_name:
raise ValueError("The name of a Kubernetes deployment must be provided.")

kubernetes_api_key = Secret(kubernetes_api_key_secret).get()
kubernetes_api_key = None
if kubernetes_api_key_secret:
kubernetes_api_key = Secret(kubernetes_api_key_secret).get()

if kubernetes_api_key:
configuration = client.Configuration()
Expand All @@ -397,7 +418,7 @@ def run(
else:
try:
config.load_incluster_config()
except config.config_exception.ConfigException:
except ConfigException:
config.load_kube_config()

api_client = client.ExtensionsV1beta1Api()
Expand All @@ -419,7 +440,10 @@ class ReadNamespacedDeployment(Task):
the first successful connection attempt becoming the mode of communication with a
cluster.

1. Attempt to use a Prefect Secret that contains a Kubernetes API Key
1. Attempt to use a Prefect Secret that contains a Kubernetes API Key. If
`kubernetes_api_key_secret` = `None` then it will attempt the next two connection
mathods. By default the value is `KUBERNETES_API_KEY` so providing `None` acts as
an override for the remote connection.
2. Attempt in-cluster connection (will only work when running on a Pod in a cluster)
3. Attempt out-of-cluster connection using the default location for a kube config file

Expand Down Expand Up @@ -490,7 +514,9 @@ def run(
if not deployment_name:
raise ValueError("The name of a Kubernetes deployment must be provided.")

kubernetes_api_key = Secret(kubernetes_api_key_secret).get()
kubernetes_api_key = None
if kubernetes_api_key_secret:
kubernetes_api_key = Secret(kubernetes_api_key_secret).get()

if kubernetes_api_key:
configuration = client.Configuration()
Expand All @@ -499,7 +525,7 @@ def run(
else:
try:
config.load_incluster_config()
except config.config_exception.ConfigException:
except ConfigException:
config.load_kube_config()

api_client = client.ExtensionsV1beta1Api()
Expand All @@ -520,7 +546,10 @@ class ReplaceNamespacedDeployment(Task):
the first successful connection attempt becoming the mode of communication with a
cluster.

1. Attempt to use a Prefect Secret that contains a Kubernetes API Key
1. Attempt to use a Prefect Secret that contains a Kubernetes API Key. If
`kubernetes_api_key_secret` = `None` then it will attempt the next two connection
mathods. By default the value is `KUBERNETES_API_KEY` so providing `None` acts as
an override for the remote connection.
2. Attempt in-cluster connection (will only work when running on a Pod in a cluster)
3. Attempt out-of-cluster connection using the default location for a kube config file

Expand Down Expand Up @@ -604,7 +633,9 @@ def run(
if not deployment_name:
raise ValueError("The name of a Kubernetes deployment must be provided.")

kubernetes_api_key = Secret(kubernetes_api_key_secret).get()
kubernetes_api_key = None
if kubernetes_api_key_secret:
kubernetes_api_key = Secret(kubernetes_api_key_secret).get()

if kubernetes_api_key:
configuration = client.Configuration()
Expand All @@ -613,7 +644,7 @@ def run(
else:
try:
config.load_incluster_config()
except config.config_exception.ConfigException:
except ConfigException:
config.load_kube_config()

api_client = client.ExtensionsV1beta1Api()
Expand Down
Loading