Matias Godoy

    Matias Godoy

    1 year ago
    Hi guys! I wanted to ask a question about flow labels; Right now I have two environments (DEV and PROD) and I have 2 different Kubernetes Agents (one with label
    dev
    and the other with label
    prod
    ), which also means that I'm using Docker Storage for the flows. Inside my flow I set the labels like this:
    flow.environment = LocalEnvironment(labels=['dev'])
    The thing is that I'd like the flow label to be "dynamic" in the sense that if I register that flow from a development environment, the label is automatically set to
    dev
    , but if I want to register it for production, I'd like the flow label to be
    prod
    . For now I register the flows from my own laptop, which automatically generates the Docker image and uploads it to my ECR for the Agents to use. Maybe I'm wrong with this, but I guess that if I set an environment variable in my local computer, and make the flow code something like
    flow.environment = LocalEnvironment(labels=[my_env_var])
    it will not work, because that variable will not exist in the container that runs the flow. Is this correct? Another alternative would be to be able to set flow labels when registering the flow using the CLI. Something like
    prefect register flow --file my_flow.py --name My-Flow --label dev
    , but according to the CLI help,
    --label
    is not a valid parameter when registering flows. Do you have any recommendations for setting flow labels dynamically depending on the environment they where registered? Thanks!
    j

    josh

    1 year ago
    Hey @Matias Godoy these are all great questions! ā€¢ If you set your
    LocalEnvironment(labels=[os.getenv("VAR")])
    then it will work because that variable is retrieved and set at registration time (aka on the machine you are registering from) ā€¢ I agree that we should definitely expose a way to set the labels through the CLI command! Would you mind opening an enhancement request on the repo for this? There is actually a new feature coming out very soon (most likely next week) where you can actually edit/adjust labels for your flows after they are registered! Meaning if you wanted to you could register a flow to dev, ensure it works, then update its label for prod. Stay tuned for that šŸ™‚
    Matias Godoy

    Matias Godoy

    1 year ago
    That is a really good feature! I'll definitely open an enhancement request. Thanks a lot for your answer!