Skip to content

Commit

Permalink
feat(fromKubeconfig): automatically call loadKubeconfig when `kubec…
Browse files Browse the repository at this point in the history
…onfig` a string (#251)
  • Loading branch information
ywangii authored and silasbw committed Apr 9, 2018
1 parent 71ada5d commit 2898b86
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ module.exports.getInCluster = getInCluster;
/* eslint-disable complexity, max-statements */
function fromKubeconfig(kubeconfig, current) {
if (!kubeconfig) kubeconfig = loadKubeconfig();
// if kubeconfig is provided as a path to the yaml file,
// automatically load it.
if (typeof kubeconfig === 'string') kubeconfig = loadKubeconfig(kubeconfig);

current = current || kubeconfig['current-context'];
const context = kubeconfig.contexts
Expand Down
5 changes: 5 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,10 @@ describe('Config', () => {
const args = config.fromKubeconfig(kubeconfig, 'foo-context-2');
assume(args.url).equals('https://192.168.42.122:8443');
});

it('load kubeconfig from provided path', () => {
const args = config.fromKubeconfig('./test/fixtures/kube-fixture.yml');
assume(args.url).equals('https://192.168.42.121:8443');
});
});
});
21 changes: 21 additions & 0 deletions test/fixtures/kube-fixture.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: foo-auth-data
server: https://192.168.42.121:8443
name: foo-cluster-1
contexts:
- context:
cluster: foo-cluster-1
namespace: default
user: foo-user
name: foo-context-1
current-context: foo-context-1
kind: Config
preferences: {}
users:
- name: foo-user
user:
client-certificate-data: foo-cert-data
client-key-data: foo-cert-key

0 comments on commit 2898b86

Please sign in to comment.