Skip to content

Commit add8105

Browse files
authored
Merge pull request #125 from scrungus/stackhpc/yoga
Upstream changes to magnum to enable cluster-api
2 parents d92a110 + ddd64a6 commit add8105

File tree

24 files changed

+4049
-20
lines changed

24 files changed

+4049
-20
lines changed

devstack/contrib/new-devstack.sh

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
#
3+
# These instructions assume an Ubuntu-based host or VM for running devstack.
4+
# Please note that if you are running this in a VM, it is vitally important
5+
# that the underlying hardware have nested virtualization enabled or you will
6+
# experience very poor amphora performance.
7+
#
8+
# Heavily based on:
9+
# https://opendev.org/openstack/octavia/src/branch/master/devstack/contrib/new-octavia-devstack.sh
10+
11+
set -ex
12+
13+
# Set up the packages we need. Ubuntu package manager is assumed.
14+
sudo apt-get update
15+
sudo apt-get install git vim apparmor apparmor-utils -y
16+
17+
# Clone the devstack repo
18+
sudo mkdir -p /opt/stack
19+
if [ ! -f /opt/stack/stack.sh ]; then
20+
sudo chown -R ${USER}. /opt/stack
21+
git clone https://git.openstack.org/openstack-dev/devstack /opt/stack
22+
fi
23+
24+
cat <<EOF > /opt/stack/local.conf
25+
[[local|localrc]]
26+
enable_plugin barbican https://opendev.org/openstack/barbican
27+
enable_plugin heat https://opendev.org/openstack/heat
28+
enable_plugin neutron https://opendev.org/openstack/neutron
29+
# NOTE: you can reference your gerrit patch here
30+
# enable_plugin magnum https://review.opendev.org/openstack/magnum refs/<etc>
31+
enable_plugin magnum https://opendev.org/openstack/magnum
32+
enable_plugin magnum-ui https://opendev.org/openstack/magnum-ui
33+
enable_plugin octavia https://opendev.org/openstack/octavia
34+
enable_plugin octavia-dashboard https://opendev.org/openstack/octavia-dashboard
35+
LIBS_FROM_GIT+=python-octaviaclient
36+
DATABASE_PASSWORD=secretdatabase
37+
RABBIT_PASSWORD=secretrabbit
38+
ADMIN_PASSWORD=secretadmin
39+
HOST_IP=$(hostname -i)
40+
SERVICE_PASSWORD=secretservice
41+
SERVICE_TOKEN=111222333444
42+
# Enable Logging
43+
LOGFILE=/opt/stack/logs/stack.sh.log
44+
VERBOSE=True
45+
LOG_COLOR=True
46+
# Octavia services
47+
enable_service octavia o-api o-cw o-da o-hk o-hm
48+
enable_service tempest
49+
GLANCE_LIMIT_IMAGE_SIZE_TOTAL=10000
50+
LIBVIRT_TYPE=kvm
51+
52+
[[post-config|/etc/neutron/neutron.conf]]
53+
[DEFAULT]
54+
advertise_mtu = True
55+
EOF
56+
57+
# Fix permissions on current tty so screens can attach
58+
sudo chmod go+rw `tty`
59+
60+
# Stack that stack!
61+
/opt/stack/stack.sh
62+
63+
#
64+
# Install this checkout and restart the Magnum services
65+
#
66+
SELF_PATH="$(realpath "${BASH_SOURCE[0]:-${(%):-%x}}")"
67+
REPO_PATH="$(dirname "$(dirname "$(dirname "$SELF_PATH")")")"
68+
python3 -m pip install -e "$REPO_PATH"
69+
sudo systemctl restart devstack@magnum-api devstack@magnum-cond
70+
71+
source /opt/stack/openrc admin admin
72+
73+
pip install python-magnumclient
74+
75+
# Add a k8s image
76+
curl -O https://object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_f0dc9cb312144d0aa44037c9149d2513/azimuth-images-prerelease/ubuntu-focal-kube-v1.26.3-230411-1504.qcow2
77+
openstack image create ubuntu-focal-kube-v1.26.3 \
78+
--file ubuntu-focal-kube-v1.26.3-230411-1504.qcow2 \
79+
--disk-format qcow2 \
80+
--container-format bare \
81+
--public
82+
openstack image set ubuntu-focal-kube-v1.26.3 --os-distro ubuntu --os-version 20.04
83+
openstack image set ubuntu-focal-kube-v1.26.3 --property kube_version=v1.26.3
84+
85+
curl -O https://object.arcus.openstack.hpc.cam.ac.uk/swift/v1/AUTH_f0dc9cb312144d0aa44037c9149d2513/azimuth-images-prerelease/ubuntu-focal-kube-v1.27.0-230418-0937.qcow2
86+
openstack image create ubuntu-focal-kube-v1.27.0 \
87+
--file ubuntu-focal-kube-v1.27.0-230418-0937.qcow2 \
88+
--disk-format qcow2 \
89+
--container-format bare \
90+
--public
91+
openstack image set ubuntu-focal-kube-v1.27.0 --os-distro ubuntu --os-version 20.04
92+
openstack image set ubuntu-focal-kube-v1.27.0 --property kube_version=v1.27.0
93+
94+
# Register template for cluster api driver
95+
openstack coe cluster template create new_driver \
96+
--coe kubernetes \
97+
--image $(openstack image show ubuntu-focal-kube-v1.26.3 -c id -f value) \
98+
--external-network public \
99+
--master-flavor ds2G20 \
100+
--flavor ds2G20 \
101+
--public \
102+
--master-lb-enabled
103+
104+
openstack coe cluster template create new_driver_upgrade \
105+
--coe kubernetes \
106+
--image $(openstack image show ubuntu-focal-kube-v1.27.0 -c id -f value) \
107+
--external-network public \
108+
--master-flavor ds2G20 \
109+
--flavor ds2G20 \
110+
--public \
111+
--master-lb-enabled
112+
113+
# You can test it like this:
114+
# openstack coe cluster create devstacktest \
115+
# --cluster-template new_driver \
116+
# --master-count 1 \
117+
# --node-count 2
118+
# openstack coe cluster list
119+
# openstack coe cluster config devstacktest

devstack/lib/magnum

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,22 @@ function magnum_register_image {
311311
echo "Unknown image extension in $image_filename, supported extensions: tgz, img, qcow2, iso, vhd, vhdx, tar.gz, img.gz, img.bz2, vhd.gz, vhdx.gz, qcow2.xz"; false
312312
fi
313313

314+
# Cluster API driver sets kube_version on the image
315+
# as the image includes the k8s binaries
316+
if [ ! -z "$MAGNUM_IMAGE_KUBE_VERSION" ]; then
317+
magnum_image_property=$magnum_image_property" --property kube_version=$MAGNUM_IMAGE_KUBE_VERSION"
318+
fi
319+
314320
openstack image set $image_name $magnum_image_property
321+
openstack image set --public $image_name
322+
openstack image show -f yaml $image_name
315323
}
316324

317325
#magnum_configure_flavor - set hw_rng property for flavor to address the potential entropy issue
318326
function magnum_configure_flavor {
327+
# add a new flavor with two vcpus and just enough RAM
328+
openstack flavor create ds2G20 --ram 2048 --disk 20 --id d5 --vcpus 2 --public
329+
319330
local magnum_flavor_property="--property hw_rng:allowed=True --property hw_rng:rate_bytes=1024 --property hw_rng:rate_period=1"
320331

321332
local FLAVOR_LIST=$(openstack flavor list -c Name -f value)
@@ -333,12 +344,122 @@ function install_magnumclient {
333344
fi
334345
}
335346

347+
function setup_capi_management_cluster {
348+
349+
# # Install `kubectl` CLI
350+
curl -fsLo /tmp/kubectl "https://dl.k8s.io/release/$(curl -fsL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
351+
sudo install -o root -g root -m 0755 /tmp/kubectl /usr/local/bin/kubectl
352+
353+
# K3s has issues without apparmor, so we add it here
354+
sudo apt install -y apparmor apparmor-utils
355+
356+
# Install k3s
357+
curl -fsL https://get.k3s.io | sudo bash -s - --disable traefik
358+
359+
# copy kubeconfig file into standard location
360+
mkdir -p $HOME/.kube
361+
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
362+
sudo chown $USER $HOME/.kube/config
363+
364+
# Install helm
365+
curl -fsL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
366+
367+
{
368+
# Install cert manager
369+
helm upgrade cert-manager cert-manager \
370+
--install \
371+
--namespace cert-manager \
372+
--create-namespace \
373+
--repo https://charts.jetstack.io \
374+
--version v1.10.1 \
375+
--set installCRDs=true \
376+
--wait \
377+
--timeout 10m
378+
} || {
379+
kubectl -n cert-manager get pods | awk '$1 && $1!="NAME" { print $1 }' | xargs -n1 kubectl -n cert-manager logs
380+
exit
381+
}
382+
383+
# Install Cluster API resources
384+
mkdir -p capi
385+
cat <<EOF > capi/kustomization.yaml
386+
---
387+
resources:
388+
- >-
389+
https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.3.2/cluster-api-components.yaml
390+
- >-
391+
https://github.com/kubernetes-sigs/cluster-api-provider-openstack/releases/download/v0.7.2/infrastructure-components.yaml
392+
patches:
393+
- patch: |-
394+
- op: replace
395+
path: /spec/template/spec/containers/0/args
396+
value:
397+
- --leader-elect
398+
- --metrics-bind-addr=localhost:8080
399+
target:
400+
kind: Deployment
401+
namespace: capi-system
402+
name: capi-controller-manager
403+
- patch: |-
404+
- op: replace
405+
path: /spec/template/spec/containers/0/args
406+
value:
407+
- --leader-elect
408+
- --metrics-bind-addr=localhost:8080
409+
target:
410+
kind: Deployment
411+
namespace: capi-kubeadm-bootstrap-system
412+
name: capi-kubeadm-bootstrap-controller-manager
413+
- patch: |-
414+
- op: replace
415+
path: /spec/template/spec/containers/0/args
416+
value:
417+
- --leader-elect
418+
- --metrics-bind-addr=localhost:8080
419+
target:
420+
kind: Deployment
421+
namespace: capi-kubeadm-control-plane-system
422+
name: capi-kubeadm-control-plane-controller-manager
423+
EOF
424+
425+
kubectl apply -k capi
426+
427+
kubectl rollout status deployment/capi-controller-manager \
428+
--namespace capi-system \
429+
--timeout 5m \
430+
&& \
431+
kubectl rollout status deployment/capi-kubeadm-bootstrap-controller-manager \
432+
--namespace capi-kubeadm-bootstrap-system \
433+
--timeout 5m \
434+
&& \
435+
kubectl rollout status deployment/capi-kubeadm-control-plane-controller-manager \
436+
--namespace capi-kubeadm-control-plane-system \
437+
--timeout 5m \
438+
&& \
439+
kubectl rollout status deployment/capo-controller-manager \
440+
--namespace capo-system \
441+
--timeout 10m
442+
443+
# Install addon manager
444+
helm upgrade cluster-api-addon-provider cluster-api-addon-provider \
445+
--install \
446+
--repo https://stackhpc.github.io/cluster-api-addon-provider \
447+
--version 0.1.0-dev.0.main.26 \
448+
--namespace capi-addon-system \
449+
--create-namespace \
450+
--wait \
451+
--timeout 10m
452+
}
453+
336454
# install_magnum() - Collect source and prepare
337455
function install_magnum {
338456
install_apache_uwsgi
339457

340458
git_clone $MAGNUM_REPO $MAGNUM_DIR $MAGNUM_BRANCH
341459
setup_develop $MAGNUM_DIR
460+
461+
# get ready for capi driver
462+
setup_capi_management_cluster
342463
}
343464

344465
# start_magnum_api() - Start the API process ahead of other things

magnum/common/clients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
from barbicanclient.v1 import client as barbicanclient
15+
from barbicanclient import client as barbicanclient
1616
from cinderclient.v3 import client as cinder_client
1717
from glanceclient import client as glanceclient
1818
from heatclient import client as heatclient

magnum/common/exception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ class OSDistroFieldNotFound(ResourceNotFound):
301301
code = 400
302302

303303

304+
class KubeVersionPropertyNotFound(Invalid):
305+
message = _("Image %(image_id)s does not have a kube_version property.")
306+
307+
304308
class X509KeyPairNotFound(ResourceNotFound):
305309
message = _("A key pair %(x509keypair)s could not be found.")
306310

magnum/common/urlfetch.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ def get(url, allowed_schemes=('http', 'https')):
3434
"""Get the data at the specified URL.
3535
3636
The URL must use the http: or https: schemes.
37-
The file: scheme is also supported if you override
38-
the allowed_schemes argument.
3937
Raise an IOError if getting the data fails.
4038
"""
4139
LOG.info('Fetching data from %s', url)
@@ -45,14 +43,8 @@ def get(url, allowed_schemes=('http', 'https')):
4543
if components.scheme not in allowed_schemes:
4644
raise URLFetchError(_('Invalid URL scheme %s') % components.scheme)
4745

48-
if components.scheme == 'file': # nosec
49-
try:
50-
return urllib.request.urlopen(url).read()
51-
except urllib.error.URLError as uex:
52-
raise URLFetchError(_('Failed to retrieve manifest: %s') % uex)
53-
5446
try:
55-
resp = requests.get(url, stream=True)
47+
resp = requests.get(url, stream=True, timeout=60)
5648
resp.raise_for_status()
5749

5850
# We cannot use resp.text here because it would download the

magnum/conf/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from magnum.conf import api
1919
from magnum.conf import barbican
20+
from magnum.conf import capi_driver
2021
from magnum.conf import certificates
2122
from magnum.conf import cinder
2223
from magnum.conf import cluster
@@ -48,6 +49,7 @@
4849

4950
api.register_opts(CONF)
5051
barbican.register_opts(CONF)
52+
capi_driver.register_opts(CONF)
5153
cluster.register_opts(CONF)
5254
cluster_templates.register_opts(CONF)
5355
cluster_heat.register_opts(CONF)

0 commit comments

Comments
 (0)