Skip to content

fix: avoid exporting kubeconfig if not set#121

Merged
adrian-gierakowski merged 2 commits intohall:mainfrom
moduon:kubeconfig-default-null
Feb 23, 2026
Merged

fix: avoid exporting kubeconfig if not set#121
adrian-gierakowski merged 2 commits intohall:mainfrom
moduon:kubeconfig-default-null

Conversation

@yajo
Copy link
Contributor

@yajo yajo commented Feb 18, 2026

This will respect outer $KUBECONFIG by default, unless something is specified.

This fixes downstream builds that were failing with:

nix build .#kubenix
error (ignored): SQLite database '/home/yajo/.cache/nix/eval-cache-v6/e2c155d8289bbf5b9d7ff161ad125c5026e61dbadddaf55652c23ef99249c588.sqlite' is busy
error: Cannot build '/nix/store/askjbhnkiz6wwn17kk88xa2clgwc3ysi-kubenix.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/8hlx23350igvj88f0ghi6j74iazym4p1-kubenix
       Last 7 log lines:
       >
       > In /nix/store/8hlx23350igvj88f0ghi6j74iazym4p1-kubenix/bin/kubenix line 4:
       > KUBECONFIG='$HOME/.kube/config'
       >            ^------------------^ SC2016 (info): Expressions don't expand in single quotes, use double quotes for that.
       >
       > For more information:
       >   https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...
       For full logs, run:
         nix log /nix/store/askjbhnkiz6wwn17kk88xa2clgwc3ysi-kubenix.drv
         ```

         @moduon MT-1075

@adrian-gierakowski
Copy link
Collaborator

CI is failing

@yajo yajo force-pushed the kubeconfig-default-null branch from d18f08f to 06d05d9 Compare February 19, 2026 10:28
@yajo
Copy link
Contributor Author

yajo commented Feb 19, 2026

Should be fixed.

@yajo yajo force-pushed the kubeconfig-default-null branch 2 times, most recently from 5872a33 to f1bca11 Compare February 19, 2026 11:12
@yajo
Copy link
Contributor Author

yajo commented Feb 19, 2026

I pushed another commit that is slightly out of scope but:

  • Requires the previous fix to work.
  • Adds the use case why this is more important.

A command like this:

nix run .#kubenix -- apply -l kubenix/module-instance=one

Will now do what you'd expect.

With it, you can render a lot of manifests without having to apply them all at once.

Before, we were getting errors like:

line 2: set: u: invalid option name
line 3: set: o: invalid option name
error: unknown shorthand flag: 'l' in -l
See 'kubectl --help' for usage.
error: unknown command "kubenix/module-instance=instance-a" for "kubectl"

yajo added 2 commits February 19, 2026 11:15
This will respect outer $KUBECONFIG by default, unless something is specified.

This fixes downstream builds that were failing with:

```
nix build .#kubenix
error (ignored): SQLite database '/home/yajo/.cache/nix/eval-cache-v6/e2c155d8289bbf5b9d7ff161ad125c5026e61dbadddaf55652c23ef99249c588.sqlite' is busy
error: Cannot build '/nix/store/askjbhnkiz6wwn17kk88xa2clgwc3ysi-kubenix.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/8hlx23350igvj88f0ghi6j74iazym4p1-kubenix
       Last 7 log lines:
       >
       > In /nix/store/8hlx23350igvj88f0ghi6j74iazym4p1-kubenix/bin/kubenix line 4:
       > KUBECONFIG='$HOME/.kube/config'
       >            ^------------------^ SC2016 (info): Expressions don't expand in single quotes, use double quotes for that.
       >
       > For more information:
       >   https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...
For full logs, run:
    nix log /nix/store/askjbhnkiz6wwn17kk88xa2clgwc3ysi-kubenix.drv
```

@moduon MT-1075
Turns out that kubenix was looping over its args, effectively disabling the possibility to pass extra flags to the underlying kubectl.

Now it will let you customize the command, such as with `kubenix apply -l kubenix/project=someproject`, to let you render a lot of manifests but apply only a part of them.

@moduon MT-1075
@yajo yajo force-pushed the kubeconfig-default-null branch from f1bca11 to 6422312 Compare February 19, 2026 11:15
@yajo
Copy link
Contributor Author

yajo commented Feb 23, 2026

This should be ready to merge. Anything missing? Thanks!

@adrian-gierakowski
Copy link
Collaborator

I see this is fixing a regression introduced by your earlier PR. However the behaviour is still subtly different than before, since previously it was possible to override the kubeconfig at runtime by setting KUBECONFIG. While now if one sets kubeconfig it will not be irrecoverable. Also, if someone previously manually set kubeconfig to "$HOME/.kube/config", $HOME will not be resolved at runtime, due to quoting done by runtimeEnv

Can we please revert to old behaviour as I'd consider this a breaking change? Thanks!

@adrian-gierakowski
Copy link
Collaborator

I see this is fixing a regression introduced by your earlier PR. However the behaviour is still subtly different than before, since previously it was possible to override the kubeconfig at runtime by setting KUBECONFIG. While now if one sets kubeconfig it will not be irrecoverable. Also, if someone previously manually set kubeconfig to "$HOME/.kube/config", $HOME will not be resolved at runtime, due to quoting done by runtimeEnv

Can we please revert to old behaviour as I'd consider this a breaking change? Thanks!

scratch that, I prefer the new behaviour since:

  1. not quoting values presents a security risk
  2. if someone sets kubeconfig it's probably best best to keep it hermetic and not make execution dependent on env. User can still override with --kubeconfig flag

@adrian-gierakowski adrian-gierakowski merged commit 2f00962 into hall:main Feb 23, 2026
1 check passed
@adrian-gierakowski
Copy link
Collaborator

we should cut a 0.4 release in the near future

@yajo yajo deleted the kubeconfig-default-null branch March 2, 2026 13:12
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