Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Spark plugin] Environment variables in the pod_template that use ValueFrom don't work #4530

Closed
2 tasks done
Tom-Newton opened this issue Dec 5, 2023 · 2 comments · Fixed by #4532
Closed
2 tasks done
Labels
bug Something isn't working flytepropeller

Comments

@Tom-Newton
Copy link
Contributor

Tom-Newton commented Dec 5, 2023

Describe the bug

If we have a task like this

@task(
    task_config=Spark(spark_conf={"spark.driver.memory": "1000M"}),
    pod_template=PodTemplate(
        pod_spec=client.V1PodSpec(
            containers=[
                client.V1Container(
                    name="primary",
                    env=[
                        client.V1EnvVar(
                            name="SECRET_ENV_VAR",
                            value_from=client.V1EnvVarSource(
                                secret_key_ref=client.V1SecretKeySelector(
                                    name="name-in-k8s-key-vault", key="name-of-key-within-secret"
                                )
                            ),
                        )
                    ],
                ),
            ],
        ),
    ),
)
def spark_task() -> str:
    ...

This results in the resulting SparkApplication spec

    - name: `SECRET_ENV_VAR`

SECRET_ENV_VAR is set to empty string.

Expected behavior

The SparkApplication spec should look like this

    - name: `SECRET_ENV_VAR`
      valueFrom:
        secretKeyRef:
          key: name-of-key-within-secret
          name: name-in-k8s-key-vault

Additional context to reproduce

I have a change to the unittests which can catch this.

The bug seems to be in how the pod_template is converted into a spark application. Specifically I think the problem comes from createSparkPodSpec where we just take the Value of the corev1.EnvVar which is expected to be empty when using ValueFrom.

This is done because currently we try to funnel the []EnvVar from Container.Env into map[string]string at SparkPodSpec.EnvVars. I propose we instead put these values in SparkPodSpec.Env which has type []EnvVar meaning no type conversion is required and it will support all features of corev1.EnvVar.

I can make a PR with this change if my proposal seems sensible.

Screenshots

No response

Are you sure this issue hasn't been raised already?

  • Yes

Have you read the Code of Conduct?

  • Yes
@Tom-Newton Tom-Newton added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Dec 5, 2023
Copy link

dosubot bot commented Dec 5, 2023

🤖

It's great to see that you've identified the issue and even proposed a solution along with a potential code change. Your contribution would definitely be valuable to the flyte community. I encourage you to go ahead and create a PR with your proposed changes. Thank you for your willingness to contribute!


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@Tom-Newton Tom-Newton changed the title [BUG] [Spark plugin] Environment variables in the pod_template that reference secrets don't work [BUG] [Spark plugin] Environment variables in the pod_template that use ValueFrom don't work Dec 5, 2023
@hamersaw
Copy link
Contributor

hamersaw commented Dec 5, 2023

@tom as you suggested using the SparkPodSpec.Env rather than SparkPodSpec.EnvVars sounds like the right idea to me. Especially as the later is technically deprecated. Please feel free to open a PR with your suggested changes!

@hamersaw hamersaw added flytepropeller and removed untriaged This issues has not yet been looked at by the Maintainers labels Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flytepropeller
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants