monokle icon indicating copy to clipboard operation
monokle copied to clipboard

Deploy fails with different kubeconfig

Open olensmar opened this issue 3 years ago • 5 comments

I've configured my project to use a different kubeconfig than the default one and I am able to browser my cluster accordingly - but when I try to deploy changes to one of my resources I get the following error:

Title: Applying my-postman-collection to cluster gke_testkube-328312_us-east1-c_testkube-workshop failed. Description: error: context "gke_testkube-328312_us-east1-c_testkube-workshop" does not exist

It seems like the deploy is not using my custom kubeconfig but the default one!?

olensmar avatar Jun 01 '22 07:06 olensmar

I fixed some minor related bugs in this PR, but I cannot reproduce your problem.

What I did was create two Minikube clusters with two separate kubeconfigs (default .kube/config and custom-context.yaml). Afterwards I updated the project settings to use the custom one and I tried to deploy both through the button found on the editor and through the compare modal.

Can you please give additional context (pun intended?)?

WitoDelnat avatar Jun 02 '22 10:06 WitoDelnat

from discussion with Ole

We decided to put this on hold for a bit. It's probably not a major issue since I cannot reproduce.

WitoDelnat avatar Jun 02 '22 11:06 WitoDelnat

I think my fix for multiple resource sets in cluster compare will also fix this.

The bug is very subtle, but before my fix when config is not a string it will ignore the passed context.

export function createKubeClient(config: string | AppConfig, context?: string) {
  const kc = new k8s.KubeConfig();
  const path = typeof config === 'string' ? config : config.projectConfig?.kubeConfig?.path || config.kubeConfig.path;
  if (!path) {
    throw new Error('Missing path to kubeconfing');
  }

  kc.loadFromFile(path);
  let currentContext =
    typeof config === 'string'
      ? context
      : config.projectConfig?.kubeConfig?.currentContext || config.kubeConfig.currentContext;

Combine that with src/redux/thunks/previewCluster.ts:47 and it likely causes your bug:

const kc = createKubeClient(thunkAPI.getState().config, context);

WitoDelnat avatar Jun 02 '22 13:06 WitoDelnat

nice catch @WitoDelnat 💪

olensmar avatar Jun 02 '22 13:06 olensmar

The browse and diff works now. The deploy still fails. No idea why but at this point I'd like to throw out the kubectl apply and replace it with the apply through Kubernetes NodeJs client.

I think that will be equally much effort, a bit cleaner to use consistent client and it will likely solve this problem as well.

WitoDelnat avatar Jun 02 '22 14:06 WitoDelnat

This is an old issue, can we still reproduce it?

devcatalin avatar Mar 28 '23 11:03 devcatalin