Vasyl Saienko | 775c1da | 2023-07-13 11:34:25 +0000 | [diff] [blame^] | 1 | export KUBEVIRT_RELEASE=${KUBEVIRT_RELEASE:-"v0.59.0"} |
| 2 | export RELEASE_OPENSTACK_K8S_REPO=${RELEASE_OPENSTACK_K8S_REPO:-https://github.com/Mirantis/release-openstack-k8s} |
| 3 | |
| 4 | export EXTERNAL_SNAPSHOTTER_REPO=${EXTERNAL_SNAPSHOTTER_REPO:-"https://github.com/kubernetes-csi/external-snapshotter"} |
| 5 | export EXTERNAL_SNAPSHOTTER_TAG=${EXTERNAL_SNAPSHOTTER_TAG:-"v6.2.2"} |
| 6 | |
| 7 | export ROOK_REPO=${ROOK_REPO:-"https://github.com/rook/rook"} |
| 8 | export ROOK_TAG=${ROOK_TAG:-"v1.11.4"} |
| 9 | |
| 10 | export KUBE_OVN_REPO=${KUBE_OVN_REPO:-"https://github.com/kubeovn/kube-ovn"} |
| 11 | export KUBE_OVN_TAG=${KUBE_OVN_TAG:-"v1.11.8"} |
| 12 | |
| 13 | export CDI_TAG=${CDI_TAG:-"v1.56.0"} |
| 14 | |
| 15 | ROOT_DIR=$(cd $(dirname "$0") && pwd) |
| 16 | RESOURCES_DIR=${ROOT_DIR}/resources |
| 17 | WORKDIR="$(cd $(dirname "$0") && pwd)/.workdir" |
| 18 | mkdir -p $WORKDIR |
| 19 | |
| 20 | function clone_repo { |
| 21 | local repo=$1 |
| 22 | local tag=$2 |
| 23 | local dst=$3 |
| 24 | |
| 25 | if [[ ! -d $dst ]]; then |
| 26 | git clone $repo $dst |
| 27 | fi |
| 28 | |
| 29 | if [[ -n $tag ]]; then |
| 30 | pushd $dst |
| 31 | git checkout tags/$tag |
| 32 | fi |
| 33 | } |
| 34 | |
| 35 | function install_kubevirt_operator { |
| 36 | kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_RELEASE}/kubevirt-operator.yaml |
| 37 | kubectl apply -f https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_RELEASE}/kubevirt-cr.yaml |
| 38 | } |
| 39 | |
| 40 | function install_virtctl { |
| 41 | if [[ ! -f /usr/sbin/virtctl ]]; then |
| 42 | wget https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_RELEASE}/virtctl-${KUBEVIRT_RELEASE}-linux-amd64 |
| 43 | mv virtctl-${KUBEVIRT_RELEASE}-linux-amd64 /usr/sbin/virtctl |
| 44 | chmod +x /usr/sbin/virtctl |
| 45 | fi |
| 46 | } |
| 47 | |
| 48 | function install_kubevirt { |
| 49 | install_kubevirt_operator |
| 50 | install_virtctl |
| 51 | kubectl apply -f ${RESOURCES_DIR}/kubevirt.yaml |
| 52 | #kubectl apply -f ${RESOURCES_DIR}/libvirt.yaml |
| 53 | } |
| 54 | |
| 55 | function install_cdi { |
| 56 | kubectl apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/${CDI_TAG}/cdi-operator.yaml |
| 57 | kubectl apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/${CDI_TAG}/cdi-cr.yaml |
| 58 | kubectl apply -f ${RESOURCES_DIR}/cdi-uploadproxy-nodeport.yaml |
| 59 | } |
| 60 | |
| 61 | function install_ceph_controller { |
| 62 | pushd $WORKDIR |
| 63 | clone_repo $RELEASE_OPENSTACK_K8S_REPO "" ${WORKDIR}/release-openstack-k8s |
| 64 | mkdir -p customizations/ceph-controller |
| 65 | cat <<EOF > customizations/ceph-controller/ceph-contoller_kubelet_path.json |
| 66 | [ |
| 67 | {"op": "add", |
| 68 | "path": "/spec/releases/0/values/rookExtraConfig", |
| 69 | "value": {"csiKubeletPath": "/var/lib/k0s/kubelet"} |
| 70 | } |
| 71 | ] |
| 72 | EOF |
| 73 | cp release-openstack-k8s/release/50-ceph-controller.yaml customizations/ceph-controller/ |
| 74 | cat <<EOF >customizations/ceph-controller/kustomization.yaml |
| 75 | resources: |
| 76 | - 50-ceph-controller.yaml |
| 77 | patches: |
| 78 | - path: ceph-contoller_kubelet_path.json |
| 79 | target: |
| 80 | group: lcm.mirantis.com |
| 81 | version: v1alpha1 |
| 82 | kind: HelmBundle |
| 83 | name: ceph-operator |
| 84 | namespace: osh-system |
| 85 | EOF |
| 86 | |
| 87 | local release_files="01-namespaces.yaml 02-helmbundle-crd.yaml 30-helm-controller.yaml 40-local-volume-provisioner.yaml ci/50-nodemaintenance.yaml" |
| 88 | for file in $release_files; do |
| 89 | kubectl apply -f release-openstack-k8s/release/$file |
| 90 | done |
| 91 | kubectl apply -k customizations/ceph-controller/ |
| 92 | popd |
| 93 | } |
| 94 | |
| 95 | function is_label_assigned { |
| 96 | local node=$1 |
| 97 | local label=$2 |
| 98 | |
| 99 | if kubectl get node --show-labels $node |grep -q -w $label; then |
| 100 | return 0 |
| 101 | fi |
| 102 | return 1 |
| 103 | } |
| 104 | |
| 105 | function deploy_ceph { |
| 106 | num_ctls=0 |
| 107 | num_osds=0 |
| 108 | seen_nodes="" |
| 109 | mkdir -p $WORKDIR/customizations/ceph-deployment |
| 110 | cp ${RESOURCES_DIR}/miraceph.yaml $WORKDIR/customizations/ceph-deployment/ |
| 111 | pushd $WORKDIR |
| 112 | echo '[' > customizations/ceph-deployment/nodes_path.json |
| 113 | for node in $(kubectl get nodes | awk '{print $1}' |grep -v NAME); do |
| 114 | node_roles="[]" |
| 115 | devices="[]" |
| 116 | if echo $seen_nodes |grep -q $node; then |
| 117 | continue |
| 118 | fi |
| 119 | if is_label_assigned $node openstack-control-plane=enabled; then |
| 120 | num_ctls=$(( num_ctls + 1 )) |
| 121 | if [[ $num_ctls -le 3 ]]; then |
| 122 | node_roles='["mon", "mgr"]' |
| 123 | fi |
| 124 | fi |
| 125 | if is_label_assigned $node role=ceph-osd-node; then |
| 126 | num_osds=$(( num_osds + 1 )) |
| 127 | devices='[{"name": "vdb", "config": {"deviceClass": "hdd"}}]' |
| 128 | fi |
| 129 | if [[ "$node_roles" != "[]" || "$devices" != "[]" ]]; then |
| 130 | cat <<EOF >> customizations/ceph-deployment/nodes_path.json |
| 131 | {"op": "add", |
| 132 | "path": "/spec/nodes/-", |
| 133 | "value": {"name": "$node", "devices": $devices, "roles": $node_roles} |
| 134 | }, |
| 135 | EOF |
| 136 | fi |
| 137 | seen_nodes="$seen_nodes,$node" |
| 138 | done |
| 139 | last_line=$(wc -l customizations/ceph-deployment/nodes_path.json| awk '{print $1}') |
| 140 | sed -i "${last_line}s/},/}/g" customizations/ceph-deployment/nodes_path.json |
| 141 | echo ']' >> customizations/ceph-deployment/nodes_path.json |
| 142 | cat <<EOF >customizations/ceph-deployment/kustomization.yaml |
| 143 | resources: |
| 144 | - miraceph.yaml |
| 145 | patches: |
| 146 | - path: nodes_path.json |
| 147 | target: |
| 148 | group: lcm.mirantis.com |
| 149 | version: v1alpha1 |
| 150 | kind: MiraCeph |
| 151 | name: cephcluster |
| 152 | namespace: ceph-lcm-mirantis |
| 153 | EOF |
| 154 | kubectl apply -k customizations/ceph-deployment/ |
| 155 | popd |
| 156 | } |
| 157 | |
| 158 | function install_ceph { |
| 159 | install_ceph_controller |
| 160 | deploy_ceph |
| 161 | } |
| 162 | |
| 163 | function install_external_snapshotter { |
| 164 | clone_repo $EXTERNAL_SNAPSHOTTER_REPO $EXTERNAL_SNAPSHOTTER_TAG $WORKDIR/external-snapshotter |
| 165 | kubectl apply -f $WORKDIR/external-snapshotter/deploy/kubernetes/snapshot-controller/ |
| 166 | kubectl apply -f $WORKDIR/external-snapshotter/client/config/crd |
| 167 | |
| 168 | clone_repo $ROOK_REPO $ROOK_TAG $WORKDIR/rook |
| 169 | kubectl apply -f $WORKDIR/rook/deploy/examples/csi/rbd/snapshotclass.yaml |
| 170 | |
| 171 | for node in $(kubectl get nodes -o jsonpath='{.items[*].metadata.name}' -l openstack-control-plane=enabled); do |
| 172 | kubectl label node --overwrite $node app=snapshot-controller |
| 173 | done |
| 174 | } |
| 175 | |
| 176 | function install_multus { |
| 177 | kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml |
| 178 | } |
| 179 | |
| 180 | function install_helm { |
| 181 | if [[ ! -f /usr/local/bin/helm3 ]]; then |
| 182 | wget https://binary-mirantis-com.s3.amazonaws.com/openstack/bin/utils/helm/helm-v3.11.2-linux-amd64 |
| 183 | mv helm-v3.11.2-linux-amd64 /usr/local/bin/helm3 |
| 184 | chmod +x /usr/local/bin/helm3 |
| 185 | fi |
| 186 | } |
| 187 | |
| 188 | function install_kube_ovn { |
| 189 | clone_repo $KUBE_OVN_REPO $KUBE_OVN_TAG $WORKDIR/kube-ovn |
| 190 | local master_node_count=0 |
| 191 | local master_node_ips="" |
| 192 | local node_ip="" |
| 193 | for node in $(kubectl get nodes -o jsonpath='{.items[*].metadata.name}' -l openstack-control-plane=enabled); do |
| 194 | if [[ $master_node_count -ge 1 ]]; then |
| 195 | continue |
| 196 | fi |
| 197 | node_ip=$(kubectl get nodes $node -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}') |
| 198 | master_node_ips="$master_node_ips $node_ip" |
| 199 | master_node_ips=$(echo $master_node_ips |sed 's/ /,/g') |
| 200 | kubectl label node --overwrite $node kube-ovn/role=master |
| 201 | master_node_count=$(( master_node_count + 1 )) |
| 202 | done |
| 203 | echo "$master_node_ips" |
| 204 | kubectl label no -lovn.kubernetes.io/ovs_dp_type!=userspace ovn.kubernetes.io/ovs_dp_type=kernel --overwrite |
| 205 | pushd $WORKDIR/kube-ovn |
| 206 | cat <<EOF > $WORKDIR/kube-ovn-master-nodes.yaml |
| 207 | MASTER_NODES: "$master_node_ips," |
| 208 | replicaCount: $master_node_count |
| 209 | EOF |
| 210 | helm3 upgrade --install kube-ovn ./kubeovn-helm -f $RESOURCES_DIR/kube_ovn.yaml -f $WORKDIR/kube-ovn-master-nodes.yaml |
| 211 | popd |
| 212 | } |
| 213 | |
| 214 | install_helm |
| 215 | install_kube_ovn |
| 216 | install_kubevirt |
| 217 | install_cdi |
| 218 | install_ceph |
| 219 | install_external_snapshotter |
| 220 | install_multus |