Skip to content

Commit 843c128

Browse files
fix: Update IPAM attribute to align with UDN API changes (#2329) (#2341)
* Update IPAM attribute to align with UDN API changes Signed-off-by: Shahaf Bahar <[email protected]> Co-authored-by: Shahaf Bahar <[email protected]>
1 parent da8665e commit 843c128

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ocp_resources/user_defined_network.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, Dict, Optional
44
from ocp_resources.resource import NamespacedResource, MissingRequiredArgumentError
55
from typing import List
6+
from warnings import warn
67

78

89
class UserDefinedNetwork(NamespacedResource):
@@ -102,6 +103,7 @@ def __init__(
102103
subnets: Optional[List[str]] = None,
103104
join_subnets: Optional[List[str]] = None,
104105
ipam_lifecycle: Optional[str] = None,
106+
ipam: Optional[dict[str, Any]] = None,
105107
**kwargs,
106108
):
107109
"""
@@ -113,6 +115,7 @@ def __init__(
113115
subnets (Optional[List[str]]): subnets are used for the pod network across the cluster.
114116
join_subnets (Optional[List[str]]): join_subnets are used inside the OVN network topology.
115117
ipam_lifecycle (Optional[str]): ipam_lifecycle controls IP addresses management lifecycle.
118+
ipam (Optional[dict[str, Any]]): ipam section contains IPAM-related configuration for the network.
116119
"""
117120
super().__init__(
118121
topology=self.LAYER2,
@@ -123,6 +126,7 @@ def __init__(
123126
self.subnets = subnets
124127
self.join_subnets = join_subnets
125128
self.ipam_lifecycle = ipam_lifecycle
129+
self.ipam = ipam
126130

127131
def to_dict(self) -> None:
128132
super().to_dict()
@@ -144,6 +148,17 @@ def to_dict(self) -> None:
144148

145149
if self.ipam_lifecycle:
146150
_layer2["ipamLifecycle"] = self.ipam_lifecycle
151+
if self.ipam:
152+
raise ValueError("Cannot use both 'ipam_lifecycle' and 'ipam'.")
153+
154+
warn(
155+
message="ipam_lifecycle is deprecated and will be removed in v4.19. Use ipam instead.",
156+
category=DeprecationWarning,
157+
stacklevel=2,
158+
)
159+
_layer2["ipam"] = self.ipam_lifecycle
160+
if self.ipam:
161+
_layer2["ipam"] = self.ipam
147162

148163

149164
class Layer3UserDefinedNetwork(UserDefinedNetwork):

0 commit comments

Comments
 (0)