Repository: PrefectHQ/prefect

Issue:
Add agent(s) documentation and setup instructions
Docs should include: an overview of what agents are and their implementation pattern, individual agent setup instructions, add relevant info to the [first steps](https://docs.prefect.io/cloud/first-steps.html) cloud doc


Discussion:

Resolving patch:
diff --git a/src/prefect/agent/agent.py b/src/prefect/agent/agent.py
--- a/src/prefect/agent/agent.py
+++ b/src/prefect/agent/agent.py
@@ -79,7 +79,7 @@ def agent_connect(self) -> str:
         print(ascii_name)
         self.logger.info("Starting {}".format(type(self).__name__))
         self.logger.info(
-            "Agent documentation can be found at https://docs.prefect.io/cloud/agent"
+            "Agent documentation can be found at https://docs.prefect.io/cloud/"
         )
         tenant_id = self.query_tenant_id()
 
diff --git a/src/prefect/agent/kubernetes/agent.py b/src/prefect/agent/kubernetes/agent.py
--- a/src/prefect/agent/kubernetes/agent.py
+++ b/src/prefect/agent/kubernetes/agent.py
@@ -105,7 +105,10 @@ def replace_job_spec_yaml(self, flow_run: GraphQLResult) -> dict:
 
     @staticmethod
     def generate_deployment_yaml(
-        token: str = None, api: str = None, namespace: str = None
+        token: str = None,
+        api: str = None,
+        namespace: str = None,
+        resource_manager_enabled: bool = False,
     ) -> str:
 
         # Use defaults if not provided
@@ -119,17 +122,21 @@ def generate_deployment_yaml(
             deployment = yaml.safe_load(deployment_file)
 
         agent_env = deployment["spec"]["template"]["spec"]["containers"][0]["env"]
-        resource_manager_env = deployment["spec"]["template"]["spec"]["containers"][1][
-            "env"
-        ]
 
         agent_env[0]["value"] = token
         agent_env[1]["value"] = api
         agent_env[2]["value"] = namespace
 
-        resource_manager_env[0]["value"] = token
-        resource_manager_env[1]["value"] = api
-        resource_manager_env[3]["value"] = namespace
+        if resource_manager_enabled:
+            resource_manager_env = deployment["spec"]["template"]["spec"]["containers"][
+                1
+            ]["env"]
+
+            resource_manager_env[0]["value"] = token
+            resource_manager_env[1]["value"] = api
+            resource_manager_env[3]["value"] = namespace
+        else:
+            del deployment["spec"]["template"]["spec"]["containers"][1]
 
         return yaml.safe_dump(deployment)
 
diff --git a/src/prefect/cli/agent.py b/src/prefect/cli/agent.py
--- a/src/prefect/cli/agent.py
+++ b/src/prefect/cli/agent.py
@@ -90,7 +90,10 @@ def start(name, token, no_pull):
     help="Agent namespace to launch workloads.",
     hidden=True,
 )
-def install(name, token, api, namespace):
+@click.option(
+    "--resource-manager", is_flag=True, help="Enable resource manager.", hidden=True
+)
+def install(name, token, api, namespace, resource_manager):
     """
     Install an agent. Outputs configuration text which can be used to install on various
     platforms.
@@ -105,6 +108,7 @@ def install(name, token, api, namespace):
         --token, -t         TEXT    A Prefect Cloud API token
         --api, -a           TEXT    A Prefect Cloud API URL
         --namespace, -n     TEXT    Agent namespace to launch workloads
+        --resource-manager          Enable resource manager on install
     """
 
     supported_agents = {"kubernetes": "prefect.agent.kubernetes.KubernetesAgent"}
@@ -116,6 +120,9 @@ def install(name, token, api, namespace):
         return
 
     deployment = from_qualified_name(retrieved_agent).generate_deployment_yaml(
-        token=token, api=api, namespace=namespace
+        token=token,
+        api=api,
+        namespace=namespace,
+        resource_manager_enabled=resource_manager,
     )
     click.echo(deployment)


Test patch:
diff --git a/tests/agent/test_k8s_agent.py b/tests/agent/test_k8s_agent.py
--- a/tests/agent/test_k8s_agent.py
+++ b/tests/agent/test_k8s_agent.py
@@ -179,7 +179,10 @@ def test_k8s_agent_generate_deployment_yaml(monkeypatch):
     with set_temporary_config({"cloud.agent.auth_token": "token"}):
         agent = KubernetesAgent()
         deployment = agent.generate_deployment_yaml(
-            token="test_token", api="test_api", namespace="test_namespace"
+            token="test_token",
+            api="test_api",
+            namespace="test_namespace",
+            resource_manager_enabled=True,
         )
 
         deployment = yaml.safe_load(deployment)
@@ -196,3 +199,24 @@ def test_k8s_agent_generate_deployment_yaml(monkeypatch):
         assert resource_manager_env[0]["value"] == "test_token"
         assert resource_manager_env[1]["value"] == "test_api"
         assert resource_manager_env[3]["value"] == "test_namespace"
+
+
+def test_k8s_agent_generate_deployment_yaml_no_resource_manager(monkeypatch):
+    k8s_config = MagicMock()
+    monkeypatch.setattr("kubernetes.config", k8s_config)
+
+    with set_temporary_config({"cloud.agent.auth_token": "token"}):
+        agent = KubernetesAgent()
+        deployment = agent.generate_deployment_yaml(
+            token="test_token", api="test_api", namespace="test_namespace"
+        )
+
+        deployment = yaml.safe_load(deployment)
+
+        agent_env = deployment["spec"]["template"]["spec"]["containers"][0]["env"]
+
+        assert agent_env[0]["value"] == "test_token"
+        assert agent_env[1]["value"] == "test_api"
+        assert agent_env[2]["value"] == "test_namespace"
+
+        assert len(deployment["spec"]["template"]["spec"]["containers"]) == 1
diff --git a/tests/cli/test_agent.py b/tests/cli/test_agent.py
--- a/tests/cli/test_agent.py
+++ b/tests/cli/test_agent.py
@@ -89,9 +89,32 @@ def test_agent_install_passes_args():
             "TEST_API",
             "--namespace",
             "TEST_NAMESPACE",
+            "--resource-manager",
         ],
     )
     assert result.exit_code == 0
     assert "TEST_TOKEN" in result.output
     assert "TEST_API" in result.output
     assert "TEST_NAMESPACE" in result.output
+    assert "resource-manager" in result.output
+
+
+def test_agent_install_no_resource_manager():
+    runner = CliRunner()
+    result = runner.invoke(
+        agent,
+        [
+            "install",
+            "--token",
+            "TEST_TOKEN",
+            "--api",
+            "TEST_API",
+            "--namespace",
+            "TEST_NAMESPACE",
+        ],
+    )
+    assert result.exit_code == 0
+    assert "TEST_TOKEN" in result.output
+    assert "TEST_API" in result.output
+    assert "TEST_NAMESPACE" in result.output
+    assert not "resource-manager" in result.output