Repository: PrefectHQ/prefect

Issue:
Kubernetes Agent Failing to Parse Labels (version 0.11.0)
## Description
*A clear description of the bug*

It appears the kubernetes agent in version 0.11.0 is failing to read labels (possibly tied to https://github.com/PrefectHQ/prefect/pull/2558) with the following error:

```
(dw_kube) dylanhughes@Dylans-MacBook-Pro-Prefect ~> kubectl get po                                                                                                                                                                                                            1
NAME                             READY   STATUS             RESTARTS   AGE
prefect-agent-74d7947c44-dsxxw   1/2     CrashLoopBackOff   5          5m14s
(dw_kube) dylanhughes@Dylans-MacBook-Pro-Prefect ~> kubectl logs prefect-agent-74d7947c44-dsxxw agent                                                                                                                                                                         1
Traceback (most recent call last):
  File "/usr/local/bin/prefect", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/prefect/cli/agent.py", line 278, in start
    agent_address=agent_address,
  File "/usr/local/lib/python3.6/site-packages/prefect/agent/kubernetes/agent.py", line 67, in __init__
    no_cloud_logs=no_cloud_logs,
  File "/usr/local/lib/python3.6/site-packages/prefect/agent/agent.py", line 102, in __init__
    labels or ast.literal_eval(config.cloud.agent.get("labels", "[]"))
  File "/usr/local/lib/python3.6/ast.py", line 85, in literal_eval
    return _convert(node_or_string)
  File "/usr/local/lib/python3.6/ast.py", line 84, in _convert
    raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <BoxList: ['prefect-data-warehouse']>
(dw_kube) dylanhughes@Dylans-MacBook-Pro-Prefect ~> prefect version
0.11.0
```



## Reproduction
*A minimal example that exhibits the behavior.*

While running version 0.11.0 run:
```
prefect agent install kubernetes -t TOKEN  --label prefect-data-warehouse --rbac --resource-manager | kubectl apply -f -
```
The deployment will come up but the pod will die with the above error.

## Environment
*Any additional information about your environment*
Not sure it's relevant given above error

*Optionally run `prefect diagnostics` from the command line and paste the information here*



Discussion:
Looks like there's a double `literal_eval` happening. Looking into it

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
@@ -98,9 +98,11 @@ def __init__(
         no_cloud_logs: bool = False,
     ) -> None:
         self.name = name or config.cloud.agent.get("name", "agent")
-        self.labels = list(
-            labels or ast.literal_eval(config.cloud.agent.get("labels", "[]"))
-        )
+
+        self.labels = labels or config.cloud.agent.get("labels", [])
+        # quick hack in case config has not been evaluated to a list yet
+        if isinstance(self.labels, str):
+            self.labels = ast.literal_eval(self.labels)
         self.env_vars = env_vars or config.cloud.agent.get("env_vars", dict())
         self.max_polls = max_polls
         self.log_to_cloud = False if no_cloud_logs else True
@@ -166,7 +168,7 @@ def _register_agent(self) -> str:
             - The agent ID as a string
         """
         agent_id = self.client.register_agent(
-            agent_type=type(self).__name__, name=self.name, labels=self.labels
+            agent_type=type(self).__name__, name=self.name, labels=self.labels  # type: ignore
         )
 
         self.logger.debug(f"Agent ID: {agent_id}")


Test patch: