Skip to content

Commit 37677ea

Browse files
refactor: centralize DEFAULT_KUBE_TAG constant and update ClusterLabels extraction
1 parent 363a362 commit 37677ea

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

magnum_cluster_api/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from oslo_utils import uuidutils # type: ignore
2929
from responses import matchers
3030

31-
from magnum_cluster_api import driver
31+
from magnum_cluster_api import driver, magnum_cluster_api
3232

3333

3434
@pytest.fixture
@@ -179,7 +179,7 @@ def mock_certificates(mock_get_cluster_ca_certificate, mock_get_cluster_magnum_c
179179

180180
@pytest.fixture(scope="session")
181181
def kube_tag():
182-
return os.getenv("KUBE_TAG", "v1.25.3")
182+
return os.getenv("KUBE_TAG", magnum_cluster_api.DEFAULT_KUBE_TAG)
183183

184184

185185
@pytest.fixture()

magnum_cluster_api/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from oslo_utils import strutils, uuidutils # type: ignore
3535
from tenacity import retry, retry_if_exception_type
3636

37-
from magnum_cluster_api import clients
37+
from magnum_cluster_api import clients, magnum_cluster_api
3838
from magnum_cluster_api import exceptions as mcapi_exceptions
3939
from magnum_cluster_api import image_utils, images, objects
4040
from magnum_cluster_api.cache import ServerGroupCache
@@ -188,7 +188,7 @@ def generate_manila_csi_cloud_config(
188188

189189

190190
def get_kube_tag(cluster: magnum_objects.Cluster) -> str:
191-
return cluster.labels.get("kube_tag", "v1.25.3")
191+
return cluster.labels.get("kube_tag", magnum_cluster_api.DEFAULT_KUBE_TAG)
192192

193193

194194
def get_auto_scaling_enabled(cluster: magnum_objects.Cluster) -> bool:

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ fn magnum_cluster_api(m: &Bound<'_, PyModule>) -> PyResult<()> {
1818
m.add_class::<driver::Driver>()?;
1919
m.add_class::<monitor::Monitor>()?;
2020

21+
// Expose constants to Python
22+
m.add("DEFAULT_KUBE_TAG", magnum::DEFAULT_KUBE_TAG)?;
23+
2124
Ok(())
2225
}

src/magnum.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,93 +18,105 @@ use std::collections::BTreeMap;
1818
use thiserror::Error;
1919
use typed_builder::TypedBuilder;
2020

21+
/// Default Kubernetes version for clusters
22+
pub const DEFAULT_KUBE_TAG: &str = "v1.30.0";
23+
2124
#[derive(Clone, Default, Deserialize, FromPyObject)]
2225
pub struct ClusterTemplate {
2326
pub network_driver: String,
2427
}
2528

26-
#[derive(Clone, Default, Deserialize, FromPyObject, TypedBuilder)]
29+
#[derive(Clone, Default, Deserialize, TypedBuilder)]
2730
#[pyo3(from_item_all)]
2831
pub struct ClusterLabels {
2932
/// The tag of the Cilium container image to use for the cluster.
3033
#[builder(default="v1.15.3".to_owned())]
31-
#[pyo3(default="v1.15.3".to_owned())]
3234
pub cilium_tag: String,
3335

3436
/// The IP address range to use for the Cilium IPAM pool.
3537
#[builder(default="10.100.0.0/16".to_owned())]
36-
#[pyo3(default="10.100.0.0/16".to_owned())]
3738
pub cilium_ipv4pool: String,
3839

3940
/// Enable the use of the Cinder CSI driver for the cluster.
4041
#[builder(default = true)]
41-
#[pyo3(default = true)]
4242
pub cinder_csi_enabled: bool,
4343

4444
/// The tag of the Cinder CSI container image to use for the cluster.
4545
#[builder(default="v1.32.0".to_owned())]
46-
#[pyo3(default="v1.32.0".to_owned())]
4746
pub cinder_csi_plugin_tag: String,
4847

4948
/// Enable the use of the Manila CSI driver for the cluster.
5049
#[builder(default = true)]
51-
#[pyo3(default = true)]
5250
pub manila_csi_enabled: bool,
5351

5452
/// The tag of the Manila CSI container image to use for the cluster.
5553
#[builder(default="v1.32.0".to_owned())]
56-
#[pyo3(default="v1.32.0".to_owned())]
5754
pub manila_csi_plugin_tag: String,
5855

5956
/// The tag to use for the OpenStack cloud controller provider
6057
/// when bootstrapping the cluster. If not specified, it will be
6158
/// automatically selected based on the Kubernetes version.
6259
#[builder(default)]
63-
#[pyo3(default)]
6460
pub cloud_provider_tag: Option<String>,
6561

6662
/// The prefix of the container images to use for the cluster, which
6763
/// defaults to the upstream images if not set.
6864
#[builder(default)]
69-
#[pyo3(default)]
7065
pub container_infra_prefix: Option<String>,
7166

7267
/// CSI attacher tag to use for the cluster.
7368
#[builder(default="v4.7.0".to_owned())]
74-
#[pyo3(default="v4.7.0".to_owned())]
7569
pub csi_attacher_tag: String,
7670

7771
/// CSI liveness probe tag to use for the cluster.
7872
#[builder(default="v2.14.0".to_owned())]
79-
#[pyo3(default="v2.14.0".to_owned())]
8073
pub csi_liveness_probe_tag: String,
8174

8275
/// CSI Node Driver Registrar tag to use for the cluster.
8376
#[builder(default="v2.12.0".to_owned())]
84-
#[pyo3(default="v2.12.0".to_owned())]
8577
pub csi_node_driver_registrar_tag: String,
8678

8779
// CSI Provisioner tag to use for the cluster.
8880
#[builder(default="v5.1.0".to_owned())]
89-
#[pyo3(default="v5.1.0".to_owned())]
9081
pub csi_provisioner_tag: String,
9182

9283
/// CSI Resizer tag to use for the cluster.
9384
#[builder(default="v1.12.0".to_owned())]
94-
#[pyo3(default="v1.12.0".to_owned())]
9585
pub csi_resizer_tag: String,
9686

9787
/// CSI Snapshotter tag to use for the cluster.
9888
#[builder(default="v8.1.0".to_owned())]
99-
#[pyo3(default="v8.1.0".to_owned())]
10089
pub csi_snapshotter_tag: String,
10190

10291
/// The Kubernetes version to use for the cluster.
103-
#[builder(default="v1.30.0".to_owned())]
104-
#[pyo3(default="v1.30.0".to_owned())]
92+
#[builder(default=DEFAULT_KUBE_TAG.to_owned())]
10593
pub kube_tag: String,
10694
}
10795

96+
impl<'py> FromPyObject<'py> for ClusterLabels {
97+
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
98+
let mut labels = ClusterLabels::default();
99+
100+
if let Ok(val) = ob.get_item("cilium_tag") { labels.cilium_tag = val.extract()?; }
101+
if let Ok(val) = ob.get_item("cilium_ipv4pool") { labels.cilium_ipv4pool = val.extract()?; }
102+
if let Ok(val) = ob.get_item("cinder_csi_enabled") { labels.cinder_csi_enabled = val.extract()?; }
103+
if let Ok(val) = ob.get_item("cinder_csi_plugin_tag") { labels.cinder_csi_plugin_tag = val.extract()?; }
104+
if let Ok(val) = ob.get_item("manila_csi_enabled") { labels.manila_csi_enabled = val.extract()?; }
105+
if let Ok(val) = ob.get_item("manila_csi_plugin_tag") { labels.manila_csi_plugin_tag = val.extract()?; }
106+
if let Ok(val) = ob.get_item("cloud_provider_tag") { labels.cloud_provider_tag = val.extract()?; }
107+
if let Ok(val) = ob.get_item("container_infra_prefix") { labels.container_infra_prefix = val.extract()?; }
108+
if let Ok(val) = ob.get_item("csi_attacher_tag") { labels.csi_attacher_tag = val.extract()?; }
109+
if let Ok(val) = ob.get_item("csi_liveness_probe_tag") { labels.csi_liveness_probe_tag = val.extract()?; }
110+
if let Ok(val) = ob.get_item("csi_node_driver_registrar_tag") { labels.csi_node_driver_registrar_tag = val.extract()?; }
111+
if let Ok(val) = ob.get_item("csi_provisioner_tag") { labels.csi_provisioner_tag = val.extract()?; }
112+
if let Ok(val) = ob.get_item("csi_resizer_tag") { labels.csi_resizer_tag = val.extract()?; }
113+
if let Ok(val) = ob.get_item("csi_snapshotter_tag") { labels.csi_snapshotter_tag = val.extract()?; }
114+
if let Ok(val) = ob.get_item("kube_tag") { labels.kube_tag = val.extract()?; }
115+
116+
Ok(labels)
117+
}
118+
}
119+
108120
impl ClusterLabels {
109121
const DEFAULT_CLOUD_PROVIDER_TAG: &'static str = "v1.34.1";
110122

0 commit comments

Comments
 (0)