Hi, has anyone seen this error before on Kubernete...
# ask-community
i
Hi, has anyone seen this error before on Kubernetes
Failed to load and execute Flow's environment: AssertionError(None)
. Trying to access private github repo for first time. Have set the github token. Running on gke
Copy code
flow.storage = GitHub(
        repo="Infrastructure/prefect",                           # name of repo
        path="_cfg/server/hello.py",                   # location of flow file in repo
        base_url="<https://github.private-repo.com/>"
    )
we are setting the env variable which contains the token
a
@Isobel Jones Did it work locally with a local agent? Can you run the command and share the output of “prefect diagnostics”?
i
It works with public github. Havent tried running with local agent will do that and post results shortly. Ont the gke agent we get
Copy code
# prefect diagnostics
{
  "config_overrides": {},
  "env_vars": [
    "PREFECT__CONTEXT__SECRETS__GITHUB_ACCESS_TOKEN",
    "PREFECT__CLOUD__API",
    "PREFECT__BACKEND",
    "PREFECT__LOGGING__LEVEL",
    "PREFECT__CLOUD__AGENT__AGENT_ADDRESS",
    "PREFECT__CLOUD__AGENT__LABELS"
  ],
  "system_information": {
    "platform": "Linux-5.4.120+-x86_64-with-debian-11.1",
    "prefect_backend": "server",
    "prefect_version": "0.15.7",
    "python_version": "3.7.12"
  }
}
a
Are you using GitHub or a self hosted Git? When using GitHub storage, you don’t have to specify the base_url - it will then default to
Copy code
<https://api.github.com>
and will use your Personal Access Token you set via secret. When you use a self-hosted Git server, you would need to use Git
You could use it as shown here:
Copy code
from prefect import Flow
from prefect.storage import GitHub

flow = Flow(
    "github-flow",
    GitHub(
        repo="org/repo",                           # name of repo
        path="flows/my_flow.py",                   # location of flow file in repo
        access_token_secret="GITHUB_ACCESS_TOKEN"  # name of personal access token secret
    )
)
You can see more GitHub examples incl. KubernetesRun here: https://github.com/anna-geller/packaging-prefect-flows/tree/master/flows
l
we are using self-hosted github and prefect server therefore, from my undestanding,
access_token_secret=
cannot be used. I am going to try to switch to the git storage
🙌 1
Looking at the git storage doc I can’t see a way to pass a token for authentication to the git resource. Github had this env variable GITHUB_ACCESS_TOKEN but git doesn’t. Am I forced to use ssh keys considering that everything is self hosted?
a
@Luca Rovinetti there is this argument: git_token_secret_name - what happens if you set the secret name here?
l
SInce I do not have a prefect secret store what should I put there?
a
You can set it via env variable:
Copy code
export PREFECT__CLOUD__USE_LOCAL_SECRETS=true
export PREFECT__CONTEXT__SECRETS__GITHUB_ACCESS_TOKEN=xyz
👍 1
then:
Copy code
flow.storage = Git(git_token_secret_name="GITHUB_ACCESS_TOKEN", ...)
l
even if I set this in all deployments:
Copy code
- name: PREFECT__CLOUD__USE_LOCAL_SECRETS
          value: "true"
        - name: PREFECT__CONTEXT__SECRETS__GITHUB_ACCESS_TOKEN
          valueFrom:
            secretKeyRef:
              key: access_token
              name: github
it returns
Copy code
Failed to load and execute Flow's environment: ValueError('Local Secret "GITHUB_ACCESS_TOKEN" was not found.')
I also executed the diagnostics command on the agent container:
Copy code
prefect diagnostics
{
  "config_overrides": {},
  "env_vars": [
    "PREFECT__CLOUD__API",
    "PREFECT__CLOUD__AGENT__LABELS",
    "PREFECT__CLOUD__USE_LOCAL_SECRETS",
    "PREFECT__CONTEXT__SECRETS__GITHUB_ACCESS_TOKEN",
    "PREFECT__CLOUD__AGENT__AGENT_ADDRESS",
    "PREFECT__BACKEND"
  ],
  "system_information": {
    "platform": "Linux-5.4.120+-x86_64-with-debian-11.1",
    "prefect_backend": "server",
    "prefect_version": "0.15.7",
    "python_version": "3.7.12"
  }
}
not sure but it seems like the default answer if I set use_local_secrets to true: https://github.com/PrefectHQ/prefect/blob/8dfa18701c2ed8705d776f4da59637b7c49b427f/src/prefect/client/secrets.py#L143
a
I agree, it’s a bit more difficult with Server. Can you share your full Git storage definition? (just hide anything sensitive)
l
it is very simple:
Copy code
flow.storage = Git(
    repo="github_org/github_repo_name", 
    flow_path="_cfg/server/git_storage.py", 
    repo_host="<http://github.private_domain.com|github.private_domain.com>",
    git_token_secret_name="GITHUB_ACCESS_TOKEN"
    )
a
I’ll ask the team if that’s necessary, but it could be that you need to either: 1. Set this env variable in a terminal session before you start the agent - I think you would need to set it on the agent, because the agent pulls the flow file from Git storage. So setting it on the Server is likely not enough. 2. Set this Secret in config.toml on the agent or Server rather than setting it as local variable in a context. Option #1 is worth trying.
l
tnx, going to try
btw, for the #1 they are configured into the deployment so the pod starts with them set. I have added the config to all containers besides the postgres
👍 1
HI @Anna Geller, I was able to make it work ( then it fails on another error that seems more code related) but It needed nome tricks on the deployment in order to make it run. TLDR; the agent spins up k8s jobs that download the repos. Those Jobs needs the env variables you mentioned. Long: 1. create a secret containing the GIT token (
github
) 2. Configure a config map containing the env vars you mentioned (
prefecttoml
) defining the job template:
Copy code
job.yml: |
      apiVersion: batch/v1
      kind: Job
      spec:
        template:
          spec:
            containers:
              - name: flow
                env:
                - name: PREFECT__CLOUD__USE_LOCAL_SECRETS
                  value: "true"
                - name: PREFECT__CONTEXT__SECRETS__GITHUB_ACCESS_TOKEN
                  valueFrom:
                    secretKeyRef:
                      name: github
                      key: access_token
3. set the
Copy code
agent:
  jobTemplateFilePath: "/root/.prefect/job.yml"
4. edit the deloyment to mount the config map as volume in the agent container (NOT supported by the helm ):
Copy code
kubectl get deployments -n prefect prefect-agent  -o yaml
...
        volumeMounts:
        - mountPath: /root/.prefect/
          name: config
          readOnly: true
...
      volumes:
      - configMap:
          defaultMode: 420
          name: prefecttoml
        name: config
...
the error that I am getting now is in the retrieve task state:
Copy code
Failed to retrieve task state with error: ClientError([{'message': 'Expected type UUID!, found ""; Could not parse UUID: ', 'locations': [{'line': 2, 'column': 5}], 'path': ['get_or_create_task_run_info'], 'extensions': {'code': 'INTERNAL_SERVER_ERROR', 'exception': {'message': 'Expected type UUID!, found ""; Could not parse UUID: '}}}])
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/prefect/engine/cloud/task_runner.py", line 157, in initialize_run
    map_index=context.get("map_index"),
  File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 1798, in get_task_run_info
    result = self.graphql(mutation)  # type: Any
  File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 569, in graphql
    raise ClientError(result["errors"])
prefect.exceptions.ClientError: [{'message': 'Expected type UUID!, found ""; Could not parse UUID: ', 'locations': [{'line': 2, 'column': 5}], 'path': ['get_or_create_task_run_info'], 'extensions': {'code': 'INTERNAL_SERVER_ERROR', 'exception': {'message': 'Expected type UUID!, found ""; Could not parse UUID: '}}}]
a
@Luca Rovinetti nice work setting this up! This error usually indicates that something went wrong during registration. Other community user was able to fix it simply by reregistering the flow. Could you try to reregister and see if this fixes the error?
l
After registering it again it worked. thank you 🍻
🙌 1