From e997c862e8ad372bd1c6318ed525e4ca3225a71e Mon Sep 17 00:00:00 2001 From: Aleksandar Kostadinov Date: Fri, 4 Jan 2019 22:31:49 +0200 Subject: [PATCH] ocp4 admin credentials --- config/config.yaml | 14 ++++++++++++++ lib/admin_credentials.rb | 18 ++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 9eb8c63a5f..25fe2aed46 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -84,6 +84,20 @@ environments: admin_creds: MasterOsAdminCredentials api_port: 8443 # version: 3.6.1.44.16 + ocp4: + # hosts: use OPENSHIFT_ENV_OSE_HOSTS=host:role1:...,host2:role1:... + hosts_type: SSHAccessibleHost + # this is the user for remote access to the OpenShift nodes + user: core + type: StaticEnvironment + user_manager: auto + # set users in OPENSHIFT_ENV_OSE_USER_MANAGER_USERS=user:password,... + # user_manager_users: joe:redhat,alice:redhat + #cli: MasterOsPerUserCliExecutor + cli: SharedLocalCliExecutor + admin_creds: MasterOsAdminCredentials + api_port: 6443 + version: 4.0.0.0 # version not supported on cluster (yet) optional_classes: tcms_tc_manager: diff --git a/lib/admin_credentials.rb b/lib/admin_credentials.rb index 1e1adde218..8ed20aac69 100644 --- a/lib/admin_credentials.rb +++ b/lib/admin_credentials.rb @@ -19,7 +19,21 @@ def initialize(env, **opts) # @return [APIAccessor] def get - res = master_host.exec_as(:admin, "cat /root/.kube/config", quiet: true) + res = master_host.exec_admin("cat /root/.kube/config", quiet: true) + if !res[:success] && res[:response].include?("No such file or directory") + # try to find kubeconfig in other locations + locations = [["kubeconfig", "/etc/kubernetes/static-pod-resources"]] + configs = locations.each do |pattern, path| + find = master_host.exec_admin( + "find '#{path}' -name '#{pattern}'", quiet: true) + if find[:success] && !find[:response].empty? + kubeconfig = find[:response].lines.first.strip + res = master_host.exec_admin("cat '#{kubeconfig}'", quiet: true) + break + end + end + end + if res[:success] logger.plain res[:response], false # host_pattern = '(?:' << env.master_hosts.map{|h| Regexp.escape h.hostname).join('|') << ')' @@ -43,7 +57,7 @@ def get ) else logger.error(res[:response]) - raise "error running command on master #{master_host.hostname} as admin, see log" + raise "error getting kubeconfig from master #{master_host.hostname}, see log" end end end