Skip to content

Commit

Permalink
Cannot login to existing cluster #3935
Browse files Browse the repository at this point in the history
The `openshiftToolkit.failOnBrokenKubeConfigEntry` (boolean) option is added with the
default set to `false` in order to make Kube config loading more robust.
If it's required to fully check the correctness of the Kube config on startup, users can
set its value to `true`, so Kubernetes Client will throw errors if any.

Fixes: #3935

Signed-off-by: Victor Rubezhny <[email protected]>
  • Loading branch information
vrubezhny committed Jan 20, 2025
1 parent ae8e689 commit 092349c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,11 @@
"openshiftToolkit.disable-namespace-info-status-bar": {
"type": "boolean",
"description": "Disable displaying the active namespace in VS Code's status bar."
},
"openshiftToolkit.failOnBrokenKubeConfigEntry": {
"type": "boolean",
"default": false,
"description": "Fail on broken Kube config entry"
}
}
},
Expand Down
11 changes: 7 additions & 4 deletions src/util/kubeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*-----------------------------------------------------------------------------------------------*/

import { KubeConfig, findHomeDir, loadYaml } from '@kubernetes/client-node';
import { Cluster, Context, User } from '@kubernetes/client-node/dist/config_types';
import { ActionOnInvalid, Cluster, Context, User } from '@kubernetes/client-node/dist/config_types';
import * as fs from 'fs';
import * as path from 'path';
import { QuickPickItem, window } from 'vscode';
import { QuickPickItem, window, workspace } from 'vscode';
import { CommandText } from '../base/command';
import { CliChannel, ExecutionContext } from '../cli';
import { Platform } from './platform';
Expand All @@ -27,8 +27,11 @@ export class KubeConfigUtils extends KubeConfig {
constructor() {
super();
try {
this.loadFromDefault();
} catch {
const failOnBrokenEntry: boolean = workspace.getConfiguration('openshiftToolkit')
.get('failOnBrokenKubeConfigEntry');
const onInvalidEntry = failOnBrokenEntry ? ActionOnInvalid.THROW : ActionOnInvalid.FILTER;
this.loadFromDefault({onInvalidEntry});
} catch {
throw new Error('Kubernetes configuration cannot be loaded. Please check configuration files for errors and fix them to continue.');
}
// k8s nodejs-client ignores all unknown properties,
Expand Down

0 comments on commit 092349c

Please sign in to comment.