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

refactor: create getMinikubeAdditionalEnvs method for minikube exec #224

Merged
merged 3 commits into from
Nov 12, 2024

Conversation

axel7083
Copy link
Contributor

Split up of #223.

Related issues

Part of #154

process.env type issue

This PR remove the process.env from the envs passed to the exec api because its type is incompatible with the API, and is unessessary.

When running tsc we see the following error

src/create-cluster.ts:58:53 - error TS2322: Type '{ [x: string]: string | undefined; TZ?: string; }' is not assignable to type '{ [key: string]: string; }'.
  'string' index signatures are incompatible.
    Type 'string | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.

58     await processApi.exec(minikubeCli, startArgs, { env, logger, token });

Incompatible type

process.env is incompatible with our RunOptions#env.

process.env is typed as ProcessEnv, which is the following

interface ProcessEnv extends Dict<string> {
                /**
                 * Can be used to change the default timezone at runtime
                 */
                TZ?: string;
            }

This is not compatible with our RunOptions#env defined as

export interface RunOptions {
    env?: { [key: string]: string };
...

Unnecessary

If only the type was incompatible I would have forced the typecheck by casting it, or using some Object.assign magic, but this is not necessary as podman desktop core is already doing it for us.

Podman desktop automatically adds it see main/src/plugin/util/exec.ts#L50

@axel7083 axel7083 requested review from benoitf and a team as code owners November 12, 2024 13:01
@axel7083 axel7083 requested review from cdrage and feloy and removed request for a team November 12, 2024 13:01
@benoitf
Copy link
Contributor

benoitf commented Nov 12, 2024

my point was that it's not only a type checking issue.

It's still changing how the variables are given as we remove content (even it is might be added by a 3rd party later)

fixing only typechecking is done by changing env to { [key: string]: string } type.

Here it's more related to avoiding to pass original env values as they're added by Podman Desktop core.
(and then it can fix a typechecking issue)

env.MINIKUBE_HOME = getMinikubeHome();
const env: Record<string, string> = {
PATH: getMinikubePath(),
MINIKUBE_HOME: getMinikubeHome() ?? '',
Copy link
Contributor

@benoitf benoitf Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be

  • if it exists we add it to env object else we don't
    rather than
    -adding an empty string value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree, fixed 👍

src/extension.ts Outdated
await extensionApi.process.exec(minikubeCli, ['start', '--profile', cluster.name], { env });
await extensionApi.process.exec(minikubeCli, ['start', '--profile', cluster.name], {
env: {
PATH: getMinikubePath(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR but it's strange sometimes we have both MINIKUBE_HOME and sometimes only the PATH

also should we call a custom utility method that will insert minikubePath and MinikubeHome instead of doing that at several places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the core issue actually, thanks for pointing that out, the code should be centralized, and we should have a single function that create the envs required

@benoitf benoitf changed the title fix: process.env typecheck fix: process.env Nov 12, 2024
@axel7083 axel7083 changed the title fix: process.env refactor: create getMinikubeAdditionalEnvs method for minikube exec Nov 12, 2024
@axel7083 axel7083 merged commit 2607b95 into podman-desktop:main Nov 12, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants