diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a6a6c5802b..a24d4dc1305c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/ - Add graceful keyboard interrupt shutdown for all agents - [#1731](https://github.com/PrefectHQ/prefect/pull/1731) - `agent start` CLI command now allows for Agent kwargs - [#1737](https://github.com/PrefectHQ/prefect/pull/1737) - Add users to specify a custom Dockerfile for Docker storage - [#1738](https://github.com/PrefectHQ/prefect/pull/1738) +- Expose `labels` kwarg in `flow.deploy` for convenient labeling of Flows - [#1742](https://github.com/PrefectHQ/prefect/pull/1742) ### Task Library @@ -43,7 +44,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/ ### Contributors -- None +- [Brett Naul](https://github.com/bnaul) ## 0.7.1 diff --git a/docs/cloud/agent/overview.md b/docs/cloud/agent/overview.md index 33f8eda3ffbd..982acf39dfa0 100644 --- a/docs/cloud/agent/overview.md +++ b/docs/cloud/agent/overview.md @@ -63,7 +63,7 @@ Prefect Agents rely on the use of a `RUNNER` token from Prefect Cloud. For infor ### Flow Affinity: Labels -Agents have an optional `labels` argument which allows for separation of execution when using multiple Agents. This is especially useful for teams who have various clusters running and they want different flows to run on specific clusters. For more information on labels and how to use them visit [Environments](../concepts/execution.html#labels). +Agents have an optional `labels` argument which allows for separation of execution when using multiple Agents. This is especially useful for teams who have various clusters running and they want different flows to run on specific clusters. For more information on labels and how to use them visit [Environments](../execution/overview.html#labels). By default Agents have no set labels and will therefore only pick up runs from flows which also have no specified Environment Labels. To set labels on your Agent they can be provided through a few methods: diff --git a/src/prefect/core/flow.py b/src/prefect/core/flow.py index 9bf91fb15eb6..e961fa7cbb4c 100644 --- a/src/prefect/core/flow.py +++ b/src/prefect/core/flow.py @@ -1231,6 +1231,7 @@ def deploy( self, project_name: str, build: bool = True, + labels: List[str] = None, set_schedule_active: bool = True, version_group_id: str = None, **kwargs: Any @@ -1243,6 +1244,8 @@ def deploy( - project_name (str): the project that should contain this flow. - build (bool, optional): if `True`, the flow's environment is built prior to serialization; defaults to `True` + - labels (List[str], optional): a list of labels to add to this Flow's environment; useful for + associating Flows with individual Agents; see http://docs.prefect.io/cloud/agent/overview.html#flow-affinity-labels - set_schedule_active (bool, optional): if `False`, will set the schedule to inactive in the database to prevent auto-scheduling runs (if the Flow has a schedule). Defaults to `True`. This can be changed later. @@ -1262,6 +1265,9 @@ def deploy( self.environment.labels.add("local") self.environment.labels.add(slugify(self.name)) + if labels: + self.environment.labels.update(labels) + client = prefect.Client() deployed_flow = client.deploy( flow=self,