|
| 1 | +- name: Set up Kubernetes local cluster |
| 2 | + hosts: all |
| 3 | + roles: |
| 4 | + - export-vexxhost-openrc |
| 5 | + become: yes |
| 6 | + tasks: |
| 7 | + - name: Set up Kubernetes local cluster |
| 8 | + shell: |
| 9 | + cmd: | |
| 10 | + set -x |
| 11 | + set -e |
| 12 | + set -o pipefail |
| 13 | +
|
| 14 | + # Create cloud-config |
| 15 | + mkdir -p /etc/kubernetes/ |
| 16 | + cat << EOF >> /etc/kubernetes/cloud-config |
| 17 | + [Global] |
| 18 | + domain-name = $OS_USER_DOMAIN_NAME |
| 19 | + tenant-id = $OS_PROJECT_ID |
| 20 | + auth-url = $OS_AUTH_URL |
| 21 | + password = $OS_PASSWORD |
| 22 | + username = $OS_USERNAME |
| 23 | + region = $OS_REGION_NAME |
| 24 | + [BlockStorage] |
| 25 | + bs-version = v2 |
| 26 | + ignore-volume-az = yes |
| 27 | + EOF |
| 28 | +
|
| 29 | + export API_HOST_IP=$(ifconfig | awk '/^docker0/ {getline; print $2}' | awk -F ':' '{print $2}') |
| 30 | + export KUBELET_HOST="0.0.0.0" |
| 31 | + export ALLOW_SECURITY_CONTEXT=true |
| 32 | + export ENABLE_CRI=false |
| 33 | + export ENABLE_HOSTPATH_PROVISIONER=true |
| 34 | + export ENABLE_SINGLE_CA_SIGNER=true |
| 35 | + export KUBE_ENABLE_CLUSTER_DNS=false |
| 36 | + export LOG_LEVEL=4 |
| 37 | + # We want to use the openstack cloud provider |
| 38 | + export CLOUD_PROVIDER=openstack |
| 39 | + # We want to run a separate cloud-controller-manager for openstack |
| 40 | + export EXTERNAL_CLOUD_PROVIDER=true |
| 41 | + # DO NOT change the location of the cloud-config file. It is important for the old cinder provider to work |
| 42 | + export CLOUD_CONFIG=/etc/kubernetes/cloud-config |
| 43 | + # Specify the OCCM binary |
| 44 | + export EXTERNAL_CLOUD_PROVIDER_BINARY=./openstack-cloud-controller-manager |
| 45 | +
|
| 46 | + # location of where the kubernetes processes log their output |
| 47 | + mkdir -p '{{ ansible_user_dir }}/workspace/logs/kubernetes' |
| 48 | + export LOG_DIR='{{ ansible_user_dir }}/workspace/logs/kubernetes' |
| 49 | + # We need this for one of the conformance tests |
| 50 | + export ALLOW_PRIVILEGED=true |
| 51 | + # Just kick off all the processes and drop down to the command line |
| 52 | + export ENABLE_DAEMON=true |
| 53 | + export HOSTNAME_OVERRIDE=$(curl http://169.254.169.254/openstack/latest/meta_data.json | python -c "import sys, json; print json.load(sys.stdin)['name']") |
| 54 | + export MAX_TIME_FOR_URL_API_SERVER=5 |
| 55 | +
|
| 56 | + # Requirements to deploy the csi cinder driver |
| 57 | + export FEATURE_GATES="CSIPersistentVolume=true,MountPropagation=true" |
| 58 | + export RUNTIME_CONFIG="storage.k8s.io/v1alpha1=true" |
| 59 | +
|
| 60 | + k8s_root="$GOPATH/src/k8s.io/kubernetes" |
| 61 | + kubectl="$k8s_root/cluster/kubectl.sh" |
| 62 | + # -E preserves the current env vars, but we need to special case PATH |
| 63 | + sudo -E PATH=$PATH SHELLOPTS=$SHELLOPTS "$k8s_root/hack/local-up-cluster.sh" -O |
| 64 | +
|
| 65 | + # set up the config we need for kubectl to work |
| 66 | + "$kubectl" config set-cluster local --server=https://localhost:6443 --certificate-authority=/var/run/kubernetes/server-ca.crt |
| 67 | + "$kubectl" config set-credentials myself --client-key=/var/run/kubernetes/client-admin.key --client-certificate=/var/run/kubernetes/client-admin.crt |
| 68 | + "$kubectl" config set-context local --cluster=local --user=myself |
| 69 | + "$kubectl" config use-context local |
| 70 | +
|
| 71 | + # Hack for RBAC for all for the new cloud-controller process, we need to do better than this |
| 72 | + "$kubectl" create clusterrolebinding --user system:serviceaccount:kube-system:default kube-system-cluster-admin-1 --clusterrole cluster-admin |
| 73 | + "$kubectl" create clusterrolebinding --user system:serviceaccount:kube-system:pvl-controller kube-system-cluster-admin-2 --clusterrole cluster-admin |
| 74 | + "$kubectl" create clusterrolebinding --user system:serviceaccount:kube-system:cloud-node-controller kube-system-cluster-admin-3 --clusterrole cluster-admin |
| 75 | + "$kubectl" create clusterrolebinding --user system:serviceaccount:kube-system:cloud-controller-manager kube-system-cluster-admin-4 --clusterrole cluster-admin |
| 76 | + "$kubectl" create clusterrolebinding --user system:serviceaccount:kube-system:shared-informers kube-system-cluster-admin-5 --clusterrole cluster-admin |
| 77 | + "$kubectl" create clusterrolebinding --user system:kube-controller-manager kube-system-cluster-admin-6 --clusterrole cluster-admin |
| 78 | +
|
| 79 | + # Where csi provisioner reads instance id from |
| 80 | + INSTANCE_UUID=$(curl http://169.254.169.254/openstack/latest/meta_data.json | python -c "import sys, json; print json.load(sys.stdin)['uuid']") |
| 81 | + echo "$INSTANCE_UUID" > /var/lib/cloud/data/instance-id |
| 82 | +
|
| 83 | + # Build latest images from source |
| 84 | + cat << EOF > Dockerfile |
| 85 | + # Based on centos |
| 86 | + FROM centos:7.4.1708 |
| 87 | + LABEL maintainers="Kubernetes Authors" |
| 88 | + LABEL description="Cinder CSI Plugin" |
| 89 | + # Copy cinderplugin from build directory |
| 90 | + COPY cinder-csi-plugin /cinderplugin |
| 91 | + # Install e4fsprogs for format |
| 92 | + RUN yum -y install e4fsprogs |
| 93 | + # Define default command |
| 94 | + ENTRYPOINT ["/cinderplugin"] |
| 95 | + EOF |
| 96 | + docker build -t docker.io/k8scloudprovider/cinder-csi-plugin:latest . |
| 97 | +
|
| 98 | + git clone https://github.com/kubernetes-csi/external-provisioner ${GOPATH}/src/github.com/kubernetes-csi/external-provisioner |
| 99 | + make -C ${GOPATH}/src/github.com/kubernetes-csi/external-provisioner container |
| 100 | + docker tag quay.io/k8scsi/csi-provisioner:canary docker.io/k8scsi/csi-provisioner:latest |
| 101 | +
|
| 102 | + git clone https://github.com/kubernetes-csi/external-attacher ${GOPATH}/src/github.com/kubernetes-csi/external-attacher |
| 103 | + make -C ${GOPATH}/src/github.com/kubernetes-csi/external-attacher container |
| 104 | + docker tag quay.io/k8scsi/csi-attacher:canary docker.io/k8scsi/csi-attacher:latest |
| 105 | +
|
| 106 | + git clone https://github.com/kubernetes-csi/driver-registrar ${GOPATH}/src/github.com/kubernetes-csi/driver-registrar |
| 107 | + make -C ${GOPATH}/src/github.com/kubernetes-csi/driver-registrar container |
| 108 | + docker tag quay.io/k8scsi/driver-registrar:canary docker.io/k8scsi/driver-registrar:latest |
| 109 | +
|
| 110 | + # Replace custom cloud config |
| 111 | + { |
| 112 | + cloud_cfg=$(base64 -w 0 ${CLOUD_CONFIG}) |
| 113 | + sed "s/cloud.conf.*$/cloud.conf: $cloud_cfg/g" -i manifests/cinder-csi-plugin/csi-secret-cinderplugin.yaml |
| 114 | + } > /dev/null 2>&1 |
| 115 | +
|
| 116 | + # Enable services |
| 117 | + "$kubectl" create -f manifests/cinder-csi-plugin |
| 118 | + sleep 5 |
| 119 | + # If services up |
| 120 | + if kubectl="$kubectl" timeout 10 bash -c ' |
| 121 | + while : |
| 122 | + do |
| 123 | + "$kubectl" get pod | sed "1d" | awk '\''$2 != "2/2" || $3 != "Running" {err = 1} END {exit err}'\'' && break |
| 124 | + sleep 1 |
| 125 | + done |
| 126 | + ' |
| 127 | + then |
| 128 | + echo 'Run services successful' |
| 129 | + "$kubectl" get pod |
| 130 | + else |
| 131 | + echo 'Run services failed' |
| 132 | + "$kubectl" get pod |
| 133 | + exit 1 |
| 134 | + fi |
| 135 | +
|
| 136 | + # Make test |
| 137 | + "$kubectl" create -f examples/cinder-csi-plugin/nginx.yaml |
| 138 | + # If test passed |
| 139 | + if kubectl="$kubectl" timeout 100 bash -c ' |
| 140 | + while : |
| 141 | + do |
| 142 | + [[ $("$kubectl" describe pod nginx | awk "/^Status:/ {print \$2}") == Running ]] && break |
| 143 | + sleep 1 |
| 144 | + done |
| 145 | + ' |
| 146 | + then |
| 147 | + echo 'Run test successful' |
| 148 | + "$kubectl" get pod |
| 149 | + else |
| 150 | + echo 'Run test failed' |
| 151 | + "$kubectl" get pod |
| 152 | + "$kubectl" describe pod nginx |
| 153 | + "$kubectl" describe pvc csi-pvc-cinderplugin |
| 154 | + exit 1 |
| 155 | + fi |
| 156 | + executable: /bin/bash |
| 157 | + chdir: '{{ zuul.project.src_dir }}' |
| 158 | + environment: '{{ golang_env | combine(vexxhost_openrc) }}' |
0 commit comments