Skip to content

Commit

Permalink
feat: add 1.27 support
Browse files Browse the repository at this point in the history
This contains a few things:

- Allow deleting clusters when creating unsupported versions
- Stop using quay.io/vexxhost natively and rely on upstream registries
- Start using the "ubuntu" os_distro instead.
  • Loading branch information
mnaser committed Jul 4, 2023
1 parent ba484d4 commit c256e74
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
run: |
source /opt/stack/openrc
curl -LO https://object-storage.public.mtl1.vexxhost.net/swift/v1/a91f106f55e64246babde7402c21b87a/magnum-capi/ubuntu-2004-v1.25.3.qcow2
openstack image create ubuntu-2004-v1.25.3 --disk-format=qcow2 --container-format=bare --property os_distro=ubuntu-focal --file=ubuntu-2004-v1.25.3.qcow2
openstack image create ubuntu-2004-v1.25.3 --disk-format=qcow2 --container-format=bare --property os_distro=ubuntu --file=ubuntu-2004-v1.25.3.qcow2
- name: Run functional tests
run: |
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ steps to be able to test and develop the project.
pushd /tmp
source /opt/stack/openrc
for version in v1.23.13 v1.24.7 v1.25.3; do \
curl -LO https://object-storage.public.mtl1.vexxhost.net/swift/v1/a91f106f55e64246babde7402c21b87a/magnum-capi/ubuntu-2004-${version}.qcow2; \
openstack image create ubuntu-2004-${version} --disk-format=qcow2 --container-format=bare --property os_distro=ubuntu-focal --file=ubuntu-2004-${version}.qcow2; \
curl -LO https://object-storage.public.mtl1.vexxhost.net/swift/v1/a91f106f55e64246babde7402c21b87a/magnum-capi/ubuntu-2204-kube-${version}.qcow2; \
openstack image create ubuntu-2204-kube-${version} --disk-format=qcow2 --container-format=bare --property os_distro=ubuntu --file=ubuntu-2204-kube-${version}.qcow2; \
openstack coe cluster template create \
--image $(openstack image show ubuntu-2004-${version} -c id -f value) \
--image $(openstack image show ubuntu-2204-kube-${version} -c id -f value) \
--external-network public \
--dns-nameserver 8.8.8.8 \
--master-lb-enabled \
Expand Down
12 changes: 6 additions & 6 deletions docs/user/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ The Cluster API driver for Magnum is designed to be fast. It is capable of
deploying a Kubernetes cluster in under 5 minutes. However, there are several
factors that can slow down the deployment process:

* **Operating system image size**
* **Operating system image size**
The average size of the operating system image is around 4 GB. The image
needs to be downloaded to each node before deploying the cluster, and the
download speed depends on the network connection. The compute service caches
images locally, so the initial cluster deployment is slower than subsequent
deployments.

* **Network connectivity**
* **Network connectivity**
When the cluster goes up, it needs to pull all the container images from the
container registry. By default, it will pull all the images from the
`quay.io/vexxhost` registry. If you have a slow network connection, you can
use a local registry to speed up the deployment process and read more about
pointing to it in the [Labels](labels.md#images) section.
container registry. By default, it will pull all the images from the upstream
registries. If you have a slow network connection, you can use a local
registry to speed up the deployment process and read more about pointing to
it in the [Labels](labels.md#images) section.

!!! note

Expand Down
8 changes: 4 additions & 4 deletions docs/user/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ specify the volume size and type using the following labels:

`boot_volume_size`

: The size in gigabytes of the boot volume.
: The size in gigabytes of the boot volume.
**Default value**: `[cinder]/default_boot_volume_size` from Magnum configuration.

`boot_volume_type`

: The volume type of the boot volume.
: The volume type of the boot volume.
**Default value**: `[cinder]/default_boot_volume_type` from Magnum configuration.

!!! note
Expand All @@ -36,8 +36,8 @@ deployment process.

`container_infra_prefix`

: The prefix of the container images to use for the cluster.
**Default value**: `quay.io/vexxhost`
: The prefix of the container images to use for the cluster.
**Default value**: None, defaults to upstream images.

## Auditing

Expand Down
36 changes: 33 additions & 3 deletions magnum_cluster_api/cmd/image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,31 @@
]


def validate_version(_, __, value):
if not value.startswith("v"):
raise click.BadParameter("Version should start with 'v'")
return value


@click.command()
@click.option(
"--operating-system",
show_default=True,
default="ubuntu-2004",
default="ubuntu-2204",
type=click.Choice(["ubuntu-2004", "ubuntu-2204"]),
help="Operating system to build image for",
)
@click.option(
"--version",
show_default=True,
default="v1.26.2",
default="v1.27.3",
callback=validate_version,
help="Kubernetes version",
)
@click.option(
"--image-builder-version",
show_default=True,
default="v0.1.14",
default="d37da2a",
help="Image builder tag (or commit) to use for building image",
)
def main(operating_system, version, image_builder_version):
Expand Down Expand Up @@ -111,6 +118,29 @@ def main(operating_system, version, image_builder_version):
"kubernetes_semver": f"{version}",
"kubernetes_series": f"{kubernetes_series}",
}

# NOTE(mnaser): We use the latest tested daily ISO for Ubuntu 22.04 in order
# to avoid a lengthy upgrade process.
if operating_system == "ubuntu-2204":
iso = "jammy-live-server-amd64.iso"

customization[
"iso_url"
] = f"http://cdimage.ubuntu.com/ubuntu-server/jammy/daily-live/current/{iso}"

# Get the SHA256 sum for the ISO
r = requests.get(
"http://cdimage.ubuntu.com/ubuntu-server/jammy/daily-live/current/SHA256SUMS"
)
r.raise_for_status()
for line in r.text.splitlines():
if iso in line:
customization["iso_checksum"] = line.split()[0]
break

# Assert that we have the checksum
assert "iso_checksum" in customization

with tempfile.NamedTemporaryFile(suffix=".json") as fp:
fp.write(json.dumps(customization).encode("utf-8"))
fp.flush()
Expand Down
4 changes: 2 additions & 2 deletions magnum_cluster_api/cmd/image_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
CONF.auto_scaling.v1_24_image,
CONF.auto_scaling.v1_25_image,
CONF.auto_scaling.v1_26_image,
CONF.auto_scaling.v1_27_image,
"registry.k8s.io/etcd:3.5.1-0",
"registry.k8s.io/etcd:3.5.3-0",
"registry.k8s.io/etcd:3.5.3-0",
Expand Down Expand Up @@ -82,8 +83,7 @@
@click.command()
@click.option(
"--repository",
show_default=True,
default="quay.io/vexxhost",
required=True,
help="Target image repository",
)
@click.option(
Expand Down
15 changes: 10 additions & 5 deletions magnum_cluster_api/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,34 @@
),
cfg.StrOpt(
"v1_22_image",
default="$image_repository/cluster-autoscaler:v1.22.1",
default="$image_repository/cluster-autoscaler:v1.22.3",
help="Image for the cluster auto-scaler for Kubernetes v1.22.",
),
cfg.StrOpt(
"v1_23_image",
default="$image_repository/cluster-autoscaler:v1.23.0",
default="$image_repository/cluster-autoscaler:v1.23.1",
help="Image for the cluster auto-scaler for Kubernetes v1.23.",
),
cfg.StrOpt(
"v1_24_image",
default="$image_repository/cluster-autoscaler:v1.24.1",
default="$image_repository/cluster-autoscaler:v1.24.2",
help="Image for the cluster auto-scaler for Kubernetes v1.24.",
),
cfg.StrOpt(
"v1_25_image",
default="$image_repository/cluster-autoscaler:v1.25.1",
default="$image_repository/cluster-autoscaler:v1.25.5",
help="Image for the cluster auto-scaler for Kubernetes v1.25.",
),
cfg.StrOpt(
"v1_26_image",
default="$image_repository/cluster-autoscaler:v1.26.1",
default="$image_repository/cluster-autoscaler:v1.26.3",
help="Image for the cluster auto-scaler for Kubernetes v1.26.",
),
cfg.StrOpt(
"v1_27_image",
default="$image_repository/cluster-autoscaler:v1.27.2",
help="Image for the cluster auto-scaler for Kubernetes v1.27.",
),
]


Expand Down
2 changes: 1 addition & 1 deletion magnum_cluster_api/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_image(name: str, repository: str = None):
Get the image name from the target registry given a full image name.
"""

if repository is None:
if not repository:
return name

new_image_name = name
Expand Down
90 changes: 63 additions & 27 deletions magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,29 @@

class ClusterAutoscalerHelmRelease:
def __init__(self, api, cluster) -> None:
self.cluster = cluster

@property
def apply(self):
image = images.get_cluster_autoscaler_image(
utils.get_kube_tag(cluster),
utils.get_kube_tag(self.cluster),
)
image_repo, image_tag = image.split(":", 1)

self.apply = helm.UpgradeReleaseCommand(
return helm.UpgradeReleaseCommand(
namespace="magnum-system",
release_name=cluster.stack_id,
release_name=self.cluster.stack_id,
chart_ref=os.path.join(
pkg_resources.resource_filename("magnum_cluster_api", "charts"),
"cluster-autoscaler/",
),
values={
"fullnameOverride": f"{cluster.stack_id}-autoscaler",
"fullnameOverride": f"{self.cluster.stack_id}-autoscaler",
"cloudProvider": "clusterapi",
"clusterAPIMode": "kubeconfig-incluster",
"clusterAPIKubeconfigSecret": f"{cluster.stack_id}-kubeconfig",
"clusterAPIKubeconfigSecret": f"{self.cluster.stack_id}-kubeconfig",
"autoDiscovery": {
"clusterName": cluster.stack_id,
"clusterName": self.cluster.stack_id,
},
"image": {
"repository": image_repo,
Expand All @@ -81,9 +85,11 @@ def __init__(self, api, cluster) -> None:
},
)

self.delete = helm.DeleteReleaseCommand(
@property
def delete(self):
return helm.DeleteReleaseCommand(
namespace="magnum-system",
release_name=cluster.stack_id,
release_name=self.cluster.stack_id,
skip_missing=True,
)

Expand Down Expand Up @@ -1313,6 +1319,54 @@ def get_object(self) -> objects.ClusterClass:
},
],
},
{
"name": "customImageRepository",
"enabledIf": '{{ if ne .imageRepository "" }}true{{end}}',
"definitions": [
{
"selector": {
"apiVersion": objects.KubeadmControlPlaneTemplate.version,
"kind": objects.KubeadmControlPlaneTemplate.kind,
"matchResources": {
"controlPlane": True,
},
},
"jsonPatches": [
{
"op": "add",
"path": "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/imageRepository", # noqa: E501
"valueFrom": {
"variable": "imageRepository",
},
},
],
},
{
"selector": {
"apiVersion": objects.KubeadmConfigTemplate.version,
"kind": objects.KubeadmConfigTemplate.kind,
"matchResources": {
"machineDeploymentClass": {
"names": ["default-worker"],
}
},
},
"jsonPatches": [
{
"op": "add",
"path": "/spec/template/spec/clusterConfiguration",
"valueFrom": {
"template": textwrap.dedent(
"""\
imageRepository: "{{ .imageRepository }}"
"""
),
},
},
],
},
],
},
{
"name": "controlPlaneConfig",
"definitions": [
Expand Down Expand Up @@ -1340,13 +1394,6 @@ def get_object(self) -> objects.ClusterClass:
)
},
},
{
"op": "add",
"path": "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/imageRepository", # noqa: E501
"valueFrom": {
"variable": "imageRepository",
},
},
{
"op": "add",
"path": "/spec/template/spec/kubeadmConfigSpec/clusterConfiguration/apiServer/certSANs", # noqa: E501
Expand Down Expand Up @@ -1389,17 +1436,6 @@ def get_object(self) -> objects.ClusterClass:
},
},
"jsonPatches": [
{
"op": "add",
"path": "/spec/template/spec/clusterConfiguration",
"valueFrom": {
"template": textwrap.dedent(
"""\
imageRepository: "{{ .imageRepository }}"
"""
),
},
},
{
"op": "add",
"path": "/spec/template/spec/files",
Expand Down Expand Up @@ -1497,7 +1533,7 @@ def generate_machine_deployments_for_cluster(
context,
ng,
"container_infra_prefix",
"quay.io/vexxhost",
"",
),
},
{
Expand Down
2 changes: 1 addition & 1 deletion magnum_cluster_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_cluster_container_infra_prefix(cluster: magnum_objects.Cluster) -> str:
return get_cluster_label(
cluster,
"container_infra_prefix",
"quay.io/vexxhost",
"",
)


Expand Down

0 comments on commit c256e74

Please sign in to comment.