Skip to content

Commit eabbd3c

Browse files
committed
Fixes to be more lenient on configs without users.
1 parent 01b721a commit eabbd3c

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

src/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class KubeConfig {
118118
opts.strictSSL = false;
119119
}
120120

121-
if (user.username) {
121+
if (user && user.username) {
122122
opts.auth = {
123123
password: user.password,
124124
username: user.username,
@@ -245,7 +245,9 @@ export class KubeConfig {
245245
private applyHTTPSOptions(opts: request.Options | https.RequestOptions) {
246246
const cluster = this.getCurrentCluster();
247247
const user = this.getCurrentUser();
248-
248+
if (!user) {
249+
return;
250+
}
249251
const ca = cluster != null ? this.bufferFromFileOrString(cluster.caFile, cluster.caData) : null;
250252
if (ca) {
251253
opts.ca = ca;
@@ -262,6 +264,9 @@ export class KubeConfig {
262264

263265
private applyAuthorizationHeader(opts: request.Options | https.RequestOptions) {
264266
const user = this.getCurrentUser();
267+
if (!user) {
268+
return;
269+
}
265270
let token: string | null = null;
266271

267272
if (user.authProvider && user.authProvider.config) {

src/config_test.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,6 @@ describe('KubeConfig', () => {
355355
]);
356356
}).to.throw('contexts[1].context is missing');
357357
});
358-
it('should fail if user is missing from context', () => {
359-
expect(() => {
360-
newContexts([
361-
{
362-
name: 'some-cluster',
363-
context: {
364-
cluster: 'foo',
365-
user: 'bar',
366-
},
367-
},
368-
{
369-
name: 'bar',
370-
context: {
371-
cluster: 'baz',
372-
},
373-
},
374-
]);
375-
}).to.throw('contexts[1].context.user is missing');
376-
});
377358
it('should fail if context is missing from context', () => {
378359
expect(() => {
379360
newContexts([

src/config_types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,10 @@ function contextIterator(): u.ListIterator<any, Context> {
101101
if (!elt.context.cluster) {
102102
throw new Error(`contexts[${i}].context.cluster is missing`);
103103
}
104-
if (!elt.context.user) {
105-
throw new Error(`contexts[${i}].context.user is missing`);
106-
}
107104
return {
108105
cluster: elt.context.cluster,
109106
name: elt.name,
110-
user: elt.context.user,
107+
user: (elt.context.user ? elt.context.user : undefined),
111108
};
112109
};
113110
}

0 commit comments

Comments
 (0)