Kubernetes dashboard installation stage
-Add a new stage that install Kubernetes dashboard and saves a file with the access token in the $HOME of the user. -Change config files folder structure. Test Plan: PASS: kubernetes dashboard is successfully initiated PASS: token.txt is sent to $HOME Story: 2005051 Task: 47937 Change-Id: Id5a872e14c2620e6064e8593ce28d177a113ffaf Signed-off-by: Daniel Caires <daniel.caires@encora.com>
This commit is contained in:
parent
56aeb98f07
commit
0fce663636
@ -190,6 +190,14 @@ def parse_config_location(parser: ArgumentParser):
|
|||||||
Path to the config file to use
|
Path to the config file to use
|
||||||
""",
|
""",
|
||||||
action='append')
|
action='append')
|
||||||
|
parser.add_argument("--kubernetes-config-files", help=
|
||||||
|
"""
|
||||||
|
Path to a local YAML files (admin-login.yaml and
|
||||||
|
dashboard-values.yml) that will be copied to the
|
||||||
|
home directory of the controller-0 for the kubernetes
|
||||||
|
dashboard instalation and configuration.
|
||||||
|
""",
|
||||||
|
type=str)
|
||||||
|
|
||||||
|
|
||||||
def parse_disk_info(parser: ArgumentParser):
|
def parse_disk_info(parser: ArgumentParser):
|
||||||
@ -284,6 +292,21 @@ def parse_networking(parser: ArgumentParser):
|
|||||||
installed.
|
installed.
|
||||||
""",
|
""",
|
||||||
type=str)
|
type=str)
|
||||||
|
parser.add_argument("--horizon-dashboard-port", help=
|
||||||
|
"""
|
||||||
|
Port for the visualization of the StarlingX
|
||||||
|
Horizon dashboard. If no port value is set, it defaults to port 8080
|
||||||
|
""",
|
||||||
|
type=str,
|
||||||
|
default='8080')
|
||||||
|
parser.add_argument("--kubernetes-dashboard-port", help=
|
||||||
|
"""
|
||||||
|
Port for the visualization of the kubernetes
|
||||||
|
dashboard. If no port value is set, it default
|
||||||
|
to port 32000
|
||||||
|
""",
|
||||||
|
type=str,
|
||||||
|
default='32000')
|
||||||
|
|
||||||
|
|
||||||
def parse_custom_scripts(parser: ArgumentParser):
|
def parse_custom_scripts(parser: ArgumentParser):
|
||||||
|
@ -129,7 +129,6 @@ will be configured and used.
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
VBoxManage natnetwork add --netname NatNetwork --network 10.10.10.0/24 --dhcp off --ipv6 on
|
VBoxManage natnetwork add --netname NatNetwork --network 10.10.10.0/24 --dhcp off --ipv6 on
|
||||||
VBoxManage natnetwork modify --netname NatNetwork --port-forward-4 http-8080:tcp:[]:8080:[10.10.10.3]:8080
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Checkout the repository, and set up Python's Virtual Environment with:
|
3. Checkout the repository, and set up Python's Virtual Environment with:
|
||||||
@ -163,8 +162,9 @@ running it):
|
|||||||
--setup-type AIO-SX \
|
--setup-type AIO-SX \
|
||||||
--iso-location "$HOME/Downloads/stx-8.iso" \
|
--iso-location "$HOME/Downloads/stx-8.iso" \
|
||||||
--labname StarlingX --install-mode serial \
|
--labname StarlingX --install-mode serial \
|
||||||
--config-files-dir ./configs/aio-sx/ \
|
--config-files-dir ./config/labSetupFiles/ \
|
||||||
--ansible-controller-config ./configs/aio-sx/localhost.yml \
|
--ansible-controller-config ./config/ansibleFiles/localhost.yml \
|
||||||
|
--kubernetes-config-files ./config/kubeFiles/ \
|
||||||
--vboxnet-type nat \
|
--vboxnet-type nat \
|
||||||
--vboxnet-name NatNetwork \
|
--vboxnet-name NatNetwork \
|
||||||
--nat-controller0-local-ssh-port 3122 \
|
--nat-controller0-local-ssh-port 3122 \
|
||||||
|
28
virtualbox/pybox/config/kubeFiles/admin-login.yaml
Normal file
28
virtualbox/pybox/config/kubeFiles/admin-login.yaml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: admin-user
|
||||||
|
namespace: kube-system
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
type: kubernetes.io/service-account-token
|
||||||
|
metadata:
|
||||||
|
name: admin-user-sa-token
|
||||||
|
namespace: kube-system
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/service-account.name: admin-user
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: admin-user
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: cluster-admin
|
||||||
|
subjects:
|
||||||
|
kind: ServiceAccount
|
||||||
|
name: admin-user
|
||||||
|
namespace: kube-system
|
12
virtualbox/pybox/config/kubeFiles/dashboard-values.yaml
Normal file
12
virtualbox/pybox/config/kubeFiles/dashboard-values.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
service:
|
||||||
|
type: NodePort
|
||||||
|
nodePort: 32000
|
||||||
|
|
||||||
|
rbac:
|
||||||
|
create: true
|
||||||
|
clusterAdminRole: true
|
||||||
|
|
||||||
|
serviceAccount:
|
||||||
|
create: true
|
||||||
|
name: kubernetes-dashboard
|
@ -421,6 +421,12 @@ def create_lab(m_vboxoptions):
|
|||||||
if 'controller-0' in node:
|
if 'controller-0' in node:
|
||||||
local_port = m_vboxoptions.nat_controller0_local_ssh_port
|
local_port = m_vboxoptions.nat_controller0_local_ssh_port
|
||||||
ip_addr = m_vboxoptions.controller0_ip
|
ip_addr = m_vboxoptions.controller0_ip
|
||||||
|
|
||||||
|
# Add port forward rule for StarlingX dashboard visualization at 8080
|
||||||
|
rule_name = m_vboxoptions.labname + "-horizon-dashbord"
|
||||||
|
vboxmanage.vboxmanage_port_forward(rule_name,
|
||||||
|
m_vboxoptions.vboxnet_name, local_port=m_vboxoptions.horizon_dashboard_port, guest_port='8080', guest_ip=ip_addr)
|
||||||
|
|
||||||
elif 'controller-1' in node:
|
elif 'controller-1' in node:
|
||||||
local_port = m_vboxoptions.nat_controller1_local_ssh_port
|
local_port = m_vboxoptions.nat_controller1_local_ssh_port
|
||||||
ip_addr = m_vboxoptions.controller1_ip
|
ip_addr = m_vboxoptions.controller1_ip
|
||||||
@ -940,7 +946,6 @@ def stage_config_controller(stream): # pylint: disable=too-many-locals
|
|||||||
#Update localhost.yml with system password
|
#Update localhost.yml with system password
|
||||||
new_config_ansible = override_ansible_become_pass()
|
new_config_ansible = override_ansible_become_pass()
|
||||||
|
|
||||||
|
|
||||||
#Send Ansible configuration file to VM
|
#Send Ansible configuration file to VM
|
||||||
LOG.info("Copying Ansible configuration file")
|
LOG.info("Copying Ansible configuration file")
|
||||||
destination_ansible = f'/home/{V_BOX_OPTIONS.username}/localhost.yml'
|
destination_ansible = f'/home/{V_BOX_OPTIONS.username}/localhost.yml'
|
||||||
@ -1352,6 +1357,79 @@ def stage_unlock_workers(ssh_client):
|
|||||||
wait_for_hosts(ssh_client, hosts, 'available')
|
wait_for_hosts(ssh_client, hosts, 'available')
|
||||||
|
|
||||||
|
|
||||||
|
@connect_to_ssh
|
||||||
|
def stage_enable_kubernetes(ssh_client):
|
||||||
|
|
||||||
|
ip_addr, port = get_ssh_ip_and_port()
|
||||||
|
|
||||||
|
local_path = V_BOX_OPTIONS.kubernetes_config_files
|
||||||
|
send_dir(
|
||||||
|
{
|
||||||
|
"source": local_path,
|
||||||
|
"remote_host": ip_addr,
|
||||||
|
"remote_port": port,
|
||||||
|
"destination":'/home/' + V_BOX_OPTIONS.username + '/',
|
||||||
|
"username": V_BOX_OPTIONS.username, "password": V_BOX_OPTIONS.password
|
||||||
|
}
|
||||||
|
)
|
||||||
|
LOG.info("###### Adding port-forward rule for kubernetes dashboard ######")
|
||||||
|
|
||||||
|
# Add port forward rule for Kubernetes dashboard visualization at 32000
|
||||||
|
ip_addr = V_BOX_OPTIONS.controller0_ip
|
||||||
|
rule_name = V_BOX_OPTIONS.labname + "-kubernetes-dasboard"
|
||||||
|
|
||||||
|
vboxmanage.vboxmanage_port_forward(rule_name, V_BOX_OPTIONS.vboxnet_name,
|
||||||
|
local_port=V_BOX_OPTIONS.kubernetes_dashboard_port,
|
||||||
|
guest_port='32000', guest_ip=ip_addr)
|
||||||
|
|
||||||
|
LOG.info("###### Installing Kubernetes dashboard ######")
|
||||||
|
|
||||||
|
_, _, exitcode = run_ssh_cmd(ssh_client,
|
||||||
|
'source /etc/platform/openrc && '
|
||||||
|
'source /etc/profile && '
|
||||||
|
'cp /etc/kubernetes/admin.conf ~/.kube/config && '
|
||||||
|
'helm repo update; helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ && '
|
||||||
|
'helm install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard -f dashboard-values.yaml', timeout=60)
|
||||||
|
|
||||||
|
if exitcode == 0:
|
||||||
|
LOG.info("###### Creating an admin-user service account with cluster-admin provileges ######")
|
||||||
|
|
||||||
|
_, _, exitcode2 = run_ssh_cmd(ssh_client,
|
||||||
|
'kubectl apply -f admin-login.yaml && kubectl -n kube-system '
|
||||||
|
'describe secret $(kubectl get secret | grep admin-user-sa-token | awk "{print $1}") | tee $HOME/token.txt', timeout=60)
|
||||||
|
if exitcode2 == 0:
|
||||||
|
send_token()
|
||||||
|
LOG.info('##### TOKEN CREATED AND FILE CONTAINING TOKEN SENT TO HOST AT /home/%s #####', getpass.getuser())
|
||||||
|
|
||||||
|
if exitcode != 0 or exitcode2 != 0:
|
||||||
|
msg = f'Installation of Kubernetes dashboard failed, expecting exit code of 0 but got {exitcode}.'
|
||||||
|
LOG.info(msg)
|
||||||
|
raise Exception(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def send_token():
|
||||||
|
LOG.info('###### Sending token.txt to /home/%s ######', getpass.getuser())
|
||||||
|
ip_addr, port = get_ssh_ip_and_port()
|
||||||
|
username =V_BOX_OPTIONS.username
|
||||||
|
password = V_BOX_OPTIONS.password
|
||||||
|
source = f'/home/{username}/token.txt'
|
||||||
|
destination = f'/home/{getpass.getuser()}'
|
||||||
|
|
||||||
|
# Send token file to HOME/Desktop using rsync
|
||||||
|
LOG.info("###### rsync command ######")
|
||||||
|
cmd = (f'rsync -avL --rsh="/usr/bin/sshpass -p {password} '
|
||||||
|
f'ssh -p {port} -o StrictHostKeyChecking=no -l {username}" '
|
||||||
|
f'{username}@{ip_addr}:{source}* {destination}')
|
||||||
|
LOG.info('CMD: %s', cmd)
|
||||||
|
|
||||||
|
with subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) as process:
|
||||||
|
for line in iter(process.stdout.readline, b''):
|
||||||
|
LOG.info("%s", line.decode("utf-8").strip())
|
||||||
|
process.wait()
|
||||||
|
if process.returncode:
|
||||||
|
raise Exception(f'Error in rsync, return code: {process.returncode}')
|
||||||
|
|
||||||
|
|
||||||
def run_custom_script(script, timeout, console, mode):
|
def run_custom_script(script, timeout, console, mode):
|
||||||
"""
|
"""
|
||||||
Run a custom script on the environment.
|
Run a custom script on the environment.
|
||||||
@ -1553,6 +1631,7 @@ STG_UNLOCK_STORAGES = "unlock-storages"
|
|||||||
STG_LAB_SETUP4 = "lab-setup4"
|
STG_LAB_SETUP4 = "lab-setup4"
|
||||||
STG_UNLOCK_WORKERS = "unlock-workers"
|
STG_UNLOCK_WORKERS = "unlock-workers"
|
||||||
STG_LAB_SETUP5 = "lab-setup5"
|
STG_LAB_SETUP5 = "lab-setup5"
|
||||||
|
STG_ENABLE_KUBERNETES = "enable-kubernetes"
|
||||||
STG_CUSTOM_SCRIPT1 = "custom-script1"
|
STG_CUSTOM_SCRIPT1 = "custom-script1"
|
||||||
STG_CUSTOM_SCRIPT2 = "custom-script2"
|
STG_CUSTOM_SCRIPT2 = "custom-script2"
|
||||||
STG_CUSTOM_SCRIPT3 = "custom-script3"
|
STG_CUSTOM_SCRIPT3 = "custom-script3"
|
||||||
@ -1612,6 +1691,9 @@ STAGE_CALLBACKS = {
|
|||||||
STG_LAB_SETUP5:
|
STG_LAB_SETUP5:
|
||||||
{CALLBACK: stage_lab_setup5,
|
{CALLBACK: stage_lab_setup5,
|
||||||
HELP: "Run lab_setup with one or more --lab-setup-conf files from controller-0."},
|
HELP: "Run lab_setup with one or more --lab-setup-conf files from controller-0."},
|
||||||
|
STG_ENABLE_KUBERNETES:
|
||||||
|
{CALLBACK: stage_enable_kubernetes,
|
||||||
|
HELP: "Installation and configuration of Kubernetes dashboard"},
|
||||||
STG_CUSTOM_SCRIPT1:
|
STG_CUSTOM_SCRIPT1:
|
||||||
{CALLBACK: stage_custom_script1,
|
{CALLBACK: stage_custom_script1,
|
||||||
HELP: "Run a custom script from /home/wrsroot, make sure you" \
|
HELP: "Run a custom script from /home/wrsroot, make sure you" \
|
||||||
@ -1653,6 +1735,7 @@ AVAILABLE_STAGES = [STG_CREATE_LAB,
|
|||||||
STG_LAB_SETUP4,
|
STG_LAB_SETUP4,
|
||||||
STG_UNLOCK_WORKERS,
|
STG_UNLOCK_WORKERS,
|
||||||
STG_LAB_SETUP5,
|
STG_LAB_SETUP5,
|
||||||
|
STG_ENABLE_KUBERNETES,
|
||||||
STG_CUSTOM_SCRIPT1,
|
STG_CUSTOM_SCRIPT1,
|
||||||
STG_CUSTOM_SCRIPT2,
|
STG_CUSTOM_SCRIPT2,
|
||||||
STG_CUSTOM_SCRIPT3,
|
STG_CUSTOM_SCRIPT3,
|
||||||
@ -1668,6 +1751,7 @@ AIO_SX_STAGES = [
|
|||||||
STG_RSYNC_CONFIG,
|
STG_RSYNC_CONFIG,
|
||||||
STG_LAB_SETUP1,
|
STG_LAB_SETUP1,
|
||||||
STG_UNLOCK_CONTROLLER0,
|
STG_UNLOCK_CONTROLLER0,
|
||||||
|
STG_ENABLE_KUBERNETES,
|
||||||
]
|
]
|
||||||
|
|
||||||
AIO_DX_STAGES = [
|
AIO_DX_STAGES = [
|
||||||
@ -1681,6 +1765,7 @@ AIO_DX_STAGES = [
|
|||||||
STG_LAB_SETUP2,
|
STG_LAB_SETUP2,
|
||||||
STG_UNLOCK_CONTROLLER1,
|
STG_UNLOCK_CONTROLLER1,
|
||||||
STG_LAB_SETUP3,
|
STG_LAB_SETUP3,
|
||||||
|
STG_ENABLE_KUBERNETES,
|
||||||
]
|
]
|
||||||
|
|
||||||
STD_STAGES = [
|
STD_STAGES = [
|
||||||
@ -1694,7 +1779,8 @@ STD_STAGES = [
|
|||||||
STG_LAB_SETUP2,
|
STG_LAB_SETUP2,
|
||||||
STG_UNLOCK_CONTROLLER1,
|
STG_UNLOCK_CONTROLLER1,
|
||||||
STG_LAB_SETUP3,
|
STG_LAB_SETUP3,
|
||||||
STG_UNLOCK_WORKERS
|
STG_UNLOCK_WORKERS,
|
||||||
|
STG_ENABLE_KUBERNETES,
|
||||||
]
|
]
|
||||||
|
|
||||||
STORAGE_STAGES = [
|
STORAGE_STAGES = [
|
||||||
@ -1711,7 +1797,8 @@ STORAGE_STAGES = [
|
|||||||
STG_UNLOCK_STORAGES,
|
STG_UNLOCK_STORAGES,
|
||||||
STG_LAB_SETUP4,
|
STG_LAB_SETUP4,
|
||||||
STG_UNLOCK_WORKERS,
|
STG_UNLOCK_WORKERS,
|
||||||
STG_LAB_SETUP5
|
STG_LAB_SETUP5,
|
||||||
|
STG_ENABLE_KUBERNETES,
|
||||||
]
|
]
|
||||||
|
|
||||||
AIO_SX = 'AIO-SX'
|
AIO_SX = 'AIO-SX'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user