blob: 951f71844caa83547a9887ee780c7e5f2481bb2b [file] [log] [blame]
Alanny Lopezaef0a492017-12-28 16:03:14 -06001#!/bin/bash
2###############################################################################
3#
4# This script is for initializing the Kubernetes environement needed to run all
5# the kubernetes integrated scripts in Kubernetes.
6# - Provisions the PV's and PVC's for:
7# * The Kubernetes JNLP Jenkins slave's shared workspace
8# * Shared state cache
9# * Openbmc/openbmc git reference repository
10# * Openbmc/qemu git reference repository
11# - Create docker-registry secret for pulling from the internal repo
12# - Create the config.json used to mount docker configuration to Kubernetes
13# Jenkins slaves that build and push docker images via shell scripts.
14# Optionally:
15# - Launch a Jenkins Master deployment into Kubernetes.
16# - Provision the PV and PVC for the Jenkin Master home directory
17#
18# Instructions:
19# Suggested way to run is to create a seperate script that will export all the
20# necessary variables and then source in this script. But editing this one
21# works as well.
22#
23###############################################################################
24#
25# Requirements:
26# - NFS server with directory to use as path for mount
27# - Access to an existing Kubernetes Cluster
28# - Kubectl installed and configured on machine running script
29#
30###############################################################################
31#
32# Variables used to initialize environment:
33# ns = Name of namespace we will be deploying the components into,
34# defaults to "openbmc".
35# nfsip = IP address of the NFS server we will be using for mounting a
36# Persistent Volume (PV) to, defaults to "10.0.0.0", should be
37# replaced with an actual IP address of an NFS server.
38# reclaim = The reclaim policy that will be used when creating the PV
39# look at k8s docs for more info on this. Defaults to "Retain".
40# path_prefix = The prefix we will add to the nfspath of the directories we
41# intend to mount. This is used to place all the different
42# directories into the same parent folder on the NFS server.
43# defaults to "/san_mount/openbmc_k8s", should be changed to
44# a valid path on your NFS server.
45# regserver = The docker registry which will be used when pushing and
46# pulling images. For internal use, it will be the internal
47# registry created by ICP, defaults to "master.icp:8500" must
48# be changed to an actual registry.
49# username = The username that will be used to login to the regserver,
50# defaults to "admin", should be changed.
51# pass = The password that will be used to login to the regserver,
52# defaults to "password", should be changed.
53# email = The email that will be used to login to the regserver,
54# defaults to "email@place.holder", should be changed.
55# k8s_master = Set to True if you want to deploy a Jenkins Master into k8s,
56# defaults to True.
57###############################################################################
58
59build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."}
60
61ns=${ns:-openbmc}
62nfsip=${nfsip:-10.0.0.0}
63regserver=${regserver:-master.icp:8500}
64reclaim=${reclaim:-Retain}
65path_prefix=${path_prefix:-/san_mount/openbmc_k8s}
66username=${username:-admin}
67pass=${pass:-password}
68email=${email:-email\@place.holder}
69k8s_master=${k8s_master:-True}
70
71echo "Create the Jenkins Slave Workspace PVC"
72name="jenkins-slave-space"
73size="100Gi"
74mode="ReadWriteMany"
75nfspath="${path_prefix}/jenkins-slave-space"
76source ${build_scripts_dir}/kubernetes/storage-setup.sh
77
78echo "Create the Shared State Cache PVC"
79name="shared-state-cache"
80size="100Gi"
81mode="ReadWriteMany"
82nfspath="${path_prefix}/sstate-cache"
83source ${build_scripts_dir}/kubernetes/storage-setup.sh
84
85echo "Create the Openbmc Reference PVC"
86name="openbmc-reference-repo"
87size="1Gi"
88mode="ReadWriteMany"
89nfspath="${path_prefix}/openbmc"
90source ${build_scripts_dir}/kubernetes/storage-setup.sh
91
92echo "Create the QEMU Reference PVC"
93name="qemu-repo"
94size="1Gi"
95mode="ReadWriteMany"
96nfspath="${path_prefix}/qemu"
97source ${build_scripts_dir}/kubernetes/storage-setup.sh
98
99# Create the regkey secret for the internal docker registry
100kubectl create secret docker-registry regkey -n $ns \
101--docker-username=${username} \
102--docker-password=${pass} \
103--docker-email=${email} \
104--docker-server=${regserver}
105
106# Create the docker config.json secret using the base64 encode of
107# '${username}:${pass}'
108
109base64up=$( echo -n "${username}:${pass}" | base64 )
110cat >> config.json << EOF
111{
112 "auths": {
113 "${regserver}": {
114 "auth": "${base64up}"
115 }
116 }
117}
118EOF
119
120chmod ugo+rw config.json
121kubectl create secret generic docker-config -n $ns --from-file=./config.json
122rm -f ./config.json
123
124if [[ "${k8s_master}" == "True" ]]; then
125 # Create the Jenkins Master Home PVC
126 echo "Create the Jenkins Master Home PVC"
127 name="jenkins-home"
128 size="2Gi"
129 mode="ReadWriteOnce"
130 nfspath="${path_prefix}/jenkins-master-home"
131 source ${build_scripts_dir}/kubernetes/storage-setup.sh
132
133 # Launch the Jenkins Master
134 launch="k8s"
135 # Clean up variables before sourcing the build-jenkins.sh
136 unset ns \
137 nfsip \
138 regserver \
139 reclaim \
140 path_prefix \
141 username \
142 pass email
143 source ${build_scripts_dir}/build-jenkins.sh
144fi