Skip to content

Commit

Permalink
kubernetes: Fix hangs when connecting
Browse files Browse the repository at this point in the history
If a kube config has no user data for a context
kubectl prompts. Unfortunately there is no way
to stop this. So only run kubectl version when
when know we have a user with a auth-provider
section. Make sure this is the default user by using
--minify to get the current user only.

Closes #7707
Fixes #7688
Reviewed-by: Stef Walter <stefw@redhat.com>
  • Loading branch information
petervo authored and stefwalter committed Sep 20, 2017
1 parent 2bed810 commit f5473bf
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions pkg/kubernetes/scripts/kube-client-cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,14 +897,39 @@
function read() {
var cmd = ["kubectl", "config", "view", "--output=json", "--raw"];

/* Call kubectl version first incase we have a auth-provider
* that needs to be populated */
return runCommand(["kubectl", "version"])
.then(function() {
return runCommand(cmd);
}, function () {
return runCommand(cmd);
});
/* Call kubectl minified config view. That only outputs
* the objects that would be used by a connection */
return runCommand(["kubectl", "config", "view", "--minify", "--output=json"])
.then(function (data) {
var p;
var auth_provider;
var user;

/* If the default data has a 'auth-provider'
* section then call kubectl version to try to
* get it to fill in any token data.
*/
try {
user = JSON.parse(data)["users"][0];
if (user && user['user'])
auth_provider = user['user']['auth-provider'];
} catch(ex) {
console.warn("received invalid kubectl config", ex);
}

if (auth_provider) {
p = runCommand(["kubectl", "version"])
.then(function () {
return runCommand(cmd);
}, function () {
return runCommand(cmd);
});
} else {
p = runCommand(cmd);
}

return p;
});
}

return {
Expand Down

0 comments on commit f5473bf

Please sign in to comment.