Skip to content

Commit

Permalink
ensure kubeconfig user can access cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Sep 11, 2017
1 parent 032858a commit 323c429
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions images/installer/root/usr/local/bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ class OpenShiftClient:
call_cmd = 'login {host} -u {u} -p none --config {c}'
return self.call(call_cmd.format(host=host, u=user, c=self.kubeconfig))

def whoami(self):
"""Retrieve information about the current user in the given kubeconfig"""
return self.call('whoami')

def get_nodes(self):
"""Retrieve remote node information as a yaml object"""
return self.call('get nodes -o yaml')
Expand Down Expand Up @@ -250,7 +254,7 @@ def main():
print "Bind-mounted host master configuration file is not of 'kind' MasterConfig. Aborting..."
exit(1)

# finish reading config file and begin gathering
# finish reading config file and begin gathering
# cluster information for inventory file
file_obj.close()

Expand All @@ -273,7 +277,7 @@ def main():
asset_config = y.get("assetConfig")
master_config = y.get("kubernetesMasterConfig")
etcd_config = y.get("etcdClientInfo")

# if master_config is missing, error out; we expect to be running on a master to be able to
# gather enough information to generate the rest of the inventory file.
if not master_config:
Expand All @@ -287,8 +291,19 @@ def main():
print msg.format(master_config_path)
exit(1)

# connect to remote host using `oc login...` and extract all possible node information
oc = OpenShiftClient(admin_kubeconfig_path)

# ensure kubeconfig is logged in with provided user, or fail with a friendly message otherwise
try:
oc.whoami()
except OpenShiftClientError as err:
msg = ("Unable to obtain user information using the provided kubeconfig file. "
"User '{}' does not appear to be logged in, or to have correct authorization. "
"Error returned from server:\n\n{}")
print msg.format(openshift_cluster_user, str(err))
exit(1)

# connect to remote host using the provided config and extract all possible node information
nodes_config = yaml.load(oc.get_nodes())

# contains host types (e.g. masters, nodes, etcd)
Expand Down

0 comments on commit 323c429

Please sign in to comment.