Skip to content

Commit

Permalink
feat: support etcd volume (#305)
Browse files Browse the repository at this point in the history
* feat: support etcd volume

* fix device name

* Add a condition for cinder

* revert cinder enabled check condition

* fix typo

* fix az omit

* fix az omit

* fix block device type supported by capo

this doc is wrong https://cluster-api-openstack.sigs.k8s.io/topics/crd-changes/v1alpha6-to-v1alpha7#creation-of-additionalblockdevices
storage.type should be `Volume` in uppercase

* fix device name for etcd volume

* make sure /var/lib/etcd path is empty before kubeadm init

* fix lint error

* fix etcdVolumeType

---------

Co-authored-by: Mohammed Naser <[email protected]>
  • Loading branch information
okozachenko1203 and mnaser committed Feb 15, 2024
1 parent 83535e7 commit 544cb77
Showing 1 changed file with 160 additions and 10 deletions.
170 changes: 160 additions & 10 deletions magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def get_object(self) -> objects.KubeadmControlPlaneTemplate:
"magnum_cluster_api.manifests", "audit"
)
audit_policy = open(os.path.join(manifests_path, "policy.yaml")).read()

return objects.KubeadmControlPlaneTemplate(
self.api,
{
Expand Down Expand Up @@ -601,6 +600,9 @@ def get_object(self) -> objects.KubeadmControlPlaneTemplate:
},
},
},
"preKubeadmCommands": [
"rm /var/lib/etcd/lost+found -rf"
],
},
},
},
Expand Down Expand Up @@ -652,7 +654,10 @@ def get_object(self) -> objects.OpenStackMachineTemplate:
},
"spec": {
"template": {
"spec": {"cloudName": "default", "flavor": PLACEHOLDER}
"spec": {
"cloudName": "default",
"flavor": PLACEHOLDER,
}
}
},
},
Expand Down Expand Up @@ -1045,6 +1050,42 @@ def get_object(self) -> objects.ClusterClass:
},
},
},
{
"name": "enableEtcdVolume",
"required": True,
"schema": {
"openAPIV3Schema": {
"type": "boolean",
},
},
},
{
"name": "etcdVolumeSize",
"required": True,
"schema": {
"openAPIV3Schema": {
"type": "integer",
},
},
},
{
"name": "etcdVolumeType",
"required": True,
"schema": {
"openAPIV3Schema": {
"type": "string",
},
},
},
{
"name": "availabilityZone",
"required": True,
"schema": {
"openAPIV3Schema": {
"type": "string",
},
},
},
],
"patches": [
{
Expand Down Expand Up @@ -1217,14 +1258,12 @@ def get_object(self) -> objects.ClusterClass:
"jsonPatches": [
{
"op": "add",
"path": "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands",
"value": [
textwrap.dedent(
"""\
bash -c "sed -i 's/__REPLACE_NODE_NAME__/$(hostname -s)/g' /etc/kubeadm.yml"
""" # noqa: E501
)
],
"path": "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands/-",
"value": textwrap.dedent(
"""\
bash -c "sed -i 's/__REPLACE_NODE_NAME__/$(hostname -s)/g' /etc/kubeadm.yml"
""" # noqa: E501
),
},
{
"op": "replace",
Expand Down Expand Up @@ -1565,6 +1604,83 @@ def get_object(self) -> objects.ClusterClass:
},
],
},
{
"name": "etcdVolume",
"enabledIf": "{{ if .enableEtcdVolume }}true{{end}}",
"definitions": [
{
"selector": {
"apiVersion": objects.KubeadmControlPlaneTemplate.version,
"kind": objects.KubeadmControlPlaneTemplate.kind,
"matchResources": {
"controlPlane": True,
},
},
"jsonPatches": [
{
"op": "add",
"path": "/spec/template/spec/kubeadmConfigSpec/diskSetup",
"valueFrom": {
"template": textwrap.dedent(
"""\
"partitions":
- "device": "/dev/vdb"
"tableType": "gpt"
"layout": True
"overwrite": False
"filesystems":
- "label": "etcd_disk"
"filesystem": "ext4"
"device": "/dev/vdb"
"extraOpts": ["-F", "-E", "lazy_itable_init=1,lazy_journal_init=1"] # noqa: E501
"""
),
},
},
{
"op": "add",
"path": "/spec/template/spec/kubeadmConfigSpec/mounts",
"valueFrom": {
"template": textwrap.dedent(
"""\
- - LABEL=etcd_disk
- /var/lib/etcd
"""
),
},
},
],
},
{
"selector": {
"apiVersion": objects.OpenStackMachineTemplate.version,
"kind": objects.OpenStackMachineTemplate.kind,
"matchResources": {
"controlPlane": True,
},
},
"jsonPatches": [
{
"op": "add",
"path": "/spec/template/spec/additionalBlockDevices",
"valueFrom": {
"template": textwrap.dedent(
"""\
- name: etcd
sizeGiB: {{ .etcdVolumeSize }}
storage:
type: Volume
volume:
type: "{{ .etcdVolumeType }}"
availabilityZone: "{{ .availabilityZone }}"
"""
),
},
},
],
},
],
},
{
"name": "controlPlaneConfig",
"definitions": [
Expand Down Expand Up @@ -1862,6 +1978,8 @@ def get_observed_generation(self) -> int:
raise Exception("Cluster doesn't exists.")

def get_object(self) -> objects.Cluster:
osc = clients.get_openstack_api(self.context)
default_volume_type = osc.cinder().volume_types.default()
return objects.Cluster(
self.api,
{
Expand Down Expand Up @@ -2098,6 +2216,38 @@ def get_object(self) -> objects.Cluster:
"name": "operatingSystem",
"value": utils.get_operating_system(self.cluster),
},
{
"name": "enableEtcdVolume",
"value": utils.get_cluster_label_as_int(
self.cluster,
"etcd_volume_size",
0,
)
> 0,
},
{
"name": "etcdVolumeSize",
"value": utils.get_cluster_label_as_int(
self.cluster,
"etcd_volume_size",
0,
),
},
{
"name": "etcdVolumeType",
"value": utils.get_cluster_label(
self.cluster,
"etcd_volume_type",
default_volume_type.name,
),
},
{
"name": "availabilityZone",
"value": utils.get_cluster_label(
self.cluster, "availability_zone", ""
)
or "",
},
],
},
},
Expand Down

0 comments on commit 544cb77

Please sign in to comment.