Skip to content

Commit 398ccf0

Browse files
authored
Merge pull request #147 from brendandburns/fixes
Fixes to be more lenient on configs without users.
2 parents 45e0987 + eabbd3c commit 398ccf0

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
@@ -119,7 +119,7 @@ export class KubeConfig {
119119
opts.strictSSL = false;
120120
}
121121

122-
if (user.username) {
122+
if (user && user.username) {
123123
opts.auth = {
124124
password: user.password,
125125
username: user.username,
@@ -253,7 +253,9 @@ export class KubeConfig {
253253
private applyHTTPSOptions(opts: request.Options | https.RequestOptions) {
254254
const cluster = this.getCurrentCluster();
255255
const user = this.getCurrentUser();
256-
256+
if (!user) {
257+
return;
258+
}
257259
const ca = cluster != null ? this.bufferFromFileOrString(cluster.caFile, cluster.caData) : null;
258260
if (ca) {
259261
opts.ca = ca;
@@ -270,6 +272,9 @@ export class KubeConfig {
270272

271273
private applyAuthorizationHeader(opts: request.Options | https.RequestOptions) {
272274
const user = this.getCurrentUser();
275+
if (!user) {
276+
return;
277+
}
273278
let token: string | null = null;
274279

275280
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)