Skip to content

Commit

Permalink
fix(kubeconfig): handle optional kubeconfig user exec properties (#351)
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Carl <grounded042@icloud.com>
  • Loading branch information
grounded042 authored and silasbw committed Oct 31, 2018
1 parent c6bb0a1 commit a854fef
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ function fromKubeconfig(kubeconfig, current) {

if (user.exec) {
const env = {};
user.exec.env.forEach(variable => {
env[variable.name] = variable.value;
});
const args = user.exec.args.join(' ');
if (user.exec.env) {
user.exec.env.forEach(variable => {
env[variable.name] = variable.value;
});
}
let args = '';
if (user.exec.args) {
args = user.exec.args.join(' ');
}
auth = {
provider: {
type: 'cmd',
Expand Down
42 changes: 42 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,48 @@ describe('Config', () => {
expect(args.auth.provider.config['cmd-env']).deep.equals({ [envKey]: envValue });
});

it('handles user.exec without optional env and args', () => {
const command = 'foo-command';
const kubeconfig = {
'apiVersion': 'v1',
'kind': 'Config',
'preferences': {},
'current-context': 'foo-context',
'contexts': [
{
name: 'foo-context',
context: {
cluster: 'foo-cluster',
user: 'foo-user'
}
}
],
'clusters': [
{
name: 'foo-cluster',
cluster: {
server: 'https://192.168.42.121:8443'
}
}
],
'users': [
{
name: 'foo-user',
user: {
exec: {
command
}
}
}
]
};
const args = config.fromKubeconfig(kubeconfig);
expect(args.auth.provider.type).equals('cmd');
expect(args.auth.provider.config['cmd-args']).equals('');
expect(args.auth.provider.config['cmd-path']).equals(command);
expect(args.auth.provider.config['cmd-env']).deep.equals({});
});

it('handles manually specified current-context', () => {
const kubeconfig = {
'apiVersion': 'v1',
Expand Down

0 comments on commit a854fef

Please sign in to comment.