hall / kubenix

Kubernetes management with Nix
https://kubenix.org/
MIT License
319 stars 30 forks source link

kubeconfig: unbound variable #46

Open pizzapim opened 1 year ago

pizzapim commented 1 year ago

Hi, I wanted to try Kubenix, but I couldn't get the example to work. I have the following flake taken from the examples:

{
  inputs.kubenix.url = "github:hall/kubenix";
  outputs = { self, ... }@inputs:
    let system = "x86_64-linux";
    in {
      kubenix = inputs.kubenix.packages.${system}.default.override {
        module = { kubenix, ... }: {
          imports = [ kubenix.modules.k8s ];
          kubernetes.resources.pods.example.spec.containers.nginx.image =
            "nginx";
        };
      };
    };
}

Then I use nix run .#kubenix, which produces:

error: builder for '/nix/store/7v7s2h891xicsa9bcijvsb6016aj82fk-kubenix.drv' failed with exit code 1;
       last 1 log lines:
       > /build/.attr-0l2nkwhif96f51f4amnlf414lhl4rv9vh8iffyp431v6s28gsr90: line 8: kubeconfig: unbound variable
       For full logs, run 'nix log /nix/store/7v7s2h891xicsa9bcijvsb6016aj82fk-kubenix.drv'.
hall commented 1 year ago

Thanks for reporting, @pizzapim!

This error is because executing the kubenix package through nix run attempts to apply resources to a target cluster while something like nix build will only evaluate the output to ./result without touching any target cluster. So the former needs kubernetes.kubeconfig while the latter does not.

I do think we could throw a better error message though (and probably update the README.md CLI section to show more than a vague import ./cluster) so I'll leave this open to at least track that.

pizzapim commented 1 year ago

Thanks for the reply, that makes total sense. Mentioning the kubeconfig option in the README would be useful for new users.

zarelit commented 11 months ago

I got the same error in the beginning as well. @hall many other tools rely on kubectl being "already configured" so maybe it makes sense to have $HOME/.kube/config as the default for kubernetes.kubeconfig option?

hall commented 11 months ago

Hey @zarelit! I agree that'd be a sensible default. I've started a PR to do just that.

adrian-gierakowski commented 8 months ago

just got bitten by it as well trying to help with another issues :)