diff --git a/src/config.ts b/src/config.ts index 43638cfb46..e190aeed81 100644 --- a/src/config.ts +++ b/src/config.ts @@ -531,6 +531,7 @@ export function findObject(list: T[], name: string, key: string for (const obj of list) { if (obj.name === name) { if (obj[key]) { + obj[key].name = name; return obj[key]; } return obj; diff --git a/src/config_test.ts b/src/config_test.ts index ae7edfe399..4135f5c5db 100644 --- a/src/config_test.ts +++ b/src/config_test.ts @@ -924,6 +924,32 @@ describe('KubeConfig', () => { expect(opts.headers.Authorization).to.equal(`Bearer ${token}`); } }); + it('should cache exec with name', async () => { + const config = new KubeConfig(); + const token = 'token'; + const responseStr = `{ + "apiVersion": "client.authentication.k8s.io/v1beta1", + "kind": "ExecCredential", + "status": { + "token": "${token}" + } + }`; + config.loadFromClusterAndUser( + { skipTLSVerify: false } as Cluster, + { + name: 'exec', + exec: { + command: 'echo', + args: [`${responseStr}`], + }, + } as User, + ); + // TODO: inject the exec command here? + const opts = {} as requestlib.Options; + await config.applyToRequest(opts); + expect((KubeConfig as any).authenticators[1].tokenCache['exec']).to.deep.equal(JSON.parse(responseStr)); + }); + it('should throw with no command.', () => { const config = new KubeConfig(); config.loadFromClusterAndUser(