Hi, Community How can I specify my namespace when ...
# ask-the-community
l
Hi, Community How can I specify my namespace when use the command line
Copy code
kubectl create secret -n flytesnacks-development generic user-info --from-literal=user_secret=mysecret
and read it in pyflyte ?
Copy code
import os
from typing import Tuple

import flytekit
from flytekit import Secret, task, workflow
from flytekit.testing import SecretsManager

secret = Secret(
    group="<SECRET_GROUP>",
    key="<SECRET_KEY>",
    mount_requirement=Secret.MountType.ENV_VAR,
)
s
@L godlike, sorry I haven't understood your question. Do you want to specify namespace in the pyflyte command?
l
yes
this is my problem, thank you very much
s
pyflyte run -p <project> -d <domain> ...
should work where the project-domain combination forms a namespace.
l
BTW, can I use my local environment for pyflyte ? Or I have to build a image and specify it ?
s
You can use your local environment.
l
Thank you very much, how can I use it ?
I use
Copy code
pyflyte run --remote
as my start
s
If you want to run your code locally, you can use your local environment, meaning you need to have all the libraries installed in your local environment. If you want to run the code remotely on the Flyte cluster, you need to specify an image or use
ImageSpec
to let Flyte build an image for you.
l
Got it ! You just solved my problem !
Thank you very much
s
No problem! 🙂
l
Copy code
{
  "apiVersion": "v1",
  "data": {
    "user_secret": "bXlzZWNyZXQ="
  },
  "kind": "Secret",
  "metadata": {
    "creationTimestamp": "2023-07-10T04:12:43Z",
    "name": "user-info",
    "namespace": "default",
    "resourceVersion": "24069",
    "uid": "8bafcba4-4afb-431f-ab5a-3868b319abb0"
  },
  "type": "Opaque"
}
Copy code
kubectl get secret user-info -o json
This is my output
Copy code
{
  "apiVersion": "v1",
  "data": {
    "user_secret": "bXlzZWNyZXQ="
  },
  "kind": "Secret",
  "metadata": {
    "creationTimestamp": "2023-07-10T04:12:43Z",
    "name": "user-info",
    "namespace": "default",
    "resourceVersion": "24069",
    "uid": "8bafcba4-4afb-431f-ab5a-3868b319abb0"
  },
  "type": "Opaque"
}
I am wondering that how can I enable my local environment to detect the secret ?
Copy code
ValueError: Error encountered while executing 'secret_task':                                                                  
                                      Unable to find secret for key user_secret in group user-info in Env Var:_FSEC_USER-INFO_USER_SECRET and                     
                                    FilePath: /etc/secrets/user-info/user_secret                                                                                  
Failed with Unknown Exception <class 'ValueError'> Reason: Error encountered while executing 'secret_task':
  Unable to find secret for key user_secret in group user-info in Env Var:_FSEC_USER-INFO_USER_SECRET and FilePath: /etc/secrets/user-info/user_secret
Error encountered while executing 'secret_task':
  Unable to find secret for key user_secret in group user-info in Env Var:_FSEC_USER-INFO_USER_SECRET and FilePath: /etc/secrets/user-info/user_secret
s
You need to set an environment variable to enable Flyte to detect your secrets locally: https://docs.flyte.org/projects/cookbook/en/latest/auto_examples/containerization/use_secrets.html#secret-discovery
l
Thank you very much ! I will try it now !