@@ -27,6 +27,7 @@ import (
27
27
apierrors "k8s.io/apimachinery/pkg/api/errors"
28
28
"k8s.io/apimachinery/pkg/types"
29
29
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
30
+ capipamv1 "sigs.k8s.io/cluster-api/exp/ipam/api/v1beta1"
30
31
"sigs.k8s.io/cluster-api/util/annotations"
31
32
"sigs.k8s.io/cluster-api/util/patch"
32
33
"sigs.k8s.io/cluster-api/util/predicates"
@@ -56,6 +57,10 @@ type IPPoolReconciler struct {
56
57
// +kubebuilder:rbac:groups=ipam.metal3.io,resources=ipclaims/status,verbs=get;update;patch
57
58
// +kubebuilder:rbac:groups=ipam.metal3.io,resources=ipaddresses,verbs=get;list;watch;create;update;patch;delete
58
59
// +kubebuilder:rbac:groups=ipam.metal3.io,resources=ipaddresses/status,verbs=get;update;patch
60
+ // +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddressclaims,verbs=get;list;watch;create;update;patch;delete
61
+ // +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddressclaims/status,verbs=get;update;patch
62
+ // +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddresses,verbs=get;list;watch;create;update;patch;delete
63
+ // +kubebuilder:rbac:groups=ipam.cluster.x-k8s.io,resources=ipaddresses/status,verbs=get;update;patch
59
64
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters,verbs=get;list;watch
60
65
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters/status,verbs=get
61
66
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch
@@ -98,7 +103,7 @@ func (r *IPPoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ c
98
103
ipamv1IPPool .ObjectMeta .Labels = make (map [string ]string )
99
104
}
100
105
ipamv1IPPool .ObjectMeta .Labels [clusterv1 .ClusterNameLabel ] = * ipamv1IPPool .Spec .ClusterName
101
- ipamv1IPPool .ObjectMeta .Labels [clusterv1 .ProviderNameLabel ] = "infrastructure -metal3"
106
+ ipamv1IPPool .ObjectMeta .Labels [clusterv1 .ProviderNameLabel ] = "ipam -metal3"
102
107
103
108
// Fetch the Cluster. Ignore an error if the deletion timestamp is set
104
109
err = r .Client .Get (ctx , key , cluster )
@@ -172,7 +177,7 @@ func (r *IPPoolReconciler) reconcileDelete(ctx context.Context,
172
177
}
173
178
174
179
// SetupWithManager will add watches for this controller.
175
- func (r * IPPoolReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
180
+ func (r * IPPoolReconciler ) SetupWithManagerForIPClaim (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
176
181
return ctrl .NewControllerManagedBy (mgr ).
177
182
For (& ipamv1.IPPool {}).
178
183
WithOptions (options ).
@@ -184,6 +189,19 @@ func (r *IPPoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manage
184
189
Complete (r )
185
190
}
186
191
192
+ // SetupWithManager will add watches for this controller.
193
+ func (r * IPPoolReconciler ) SetupWithManagerForIPAddressClaim (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
194
+ return ctrl .NewControllerManagedBy (mgr ).
195
+ For (& ipamv1.IPPool {}).
196
+ WithOptions (options ).
197
+ Watches (
198
+ & capipamv1.IPAddressClaim {},
199
+ handler .EnqueueRequestsFromMapFunc (r .IPAddressClaimToIPPool ),
200
+ ).
201
+ WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (ctrl .LoggerFrom (ctx ), r .WatchFilterValue )).
202
+ Complete (r )
203
+ }
204
+
187
205
// IPClaimToIPPool will return a reconcile request for a
188
206
// Metal3DataTemplate if the event is for a
189
207
// IPClaim and that IPClaim references a Metal3DataTemplate.
@@ -207,6 +225,23 @@ func (r *IPPoolReconciler) IPClaimToIPPool(_ context.Context, obj client.Object)
207
225
return []ctrl.Request {}
208
226
}
209
227
228
+ func (r * IPPoolReconciler ) IPAddressClaimToIPPool (_ context.Context , obj client.Object ) []ctrl.Request {
229
+ if ipac , ok := obj .(* capipamv1.IPAddressClaim ); ok {
230
+ if ipac .Spec .PoolRef .Name != "" {
231
+ namespace := ipac .Namespace
232
+ return []ctrl.Request {
233
+ {
234
+ NamespacedName : types.NamespacedName {
235
+ Name : ipac .Spec .PoolRef .Name ,
236
+ Namespace : namespace ,
237
+ },
238
+ },
239
+ }
240
+ }
241
+ }
242
+ return []ctrl.Request {}
243
+ }
244
+
210
245
// checkReconcileError checks if the error is a transient or terminal error.
211
246
// If it is transient, it returns a Result with Requeue set to true.
212
247
// Non-reconcile errors are returned as-is.
0 commit comments