Skip to content

Commit 76e5fb5

Browse files
committed
Ensure IPAddress has a ClusterName label as CAPI resources
Signed-off-by: Gong Zhang <[email protected]>
1 parent 1d47354 commit 76e5fb5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

internal/controllers/ipaddressclaim.go

+6
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ func (r *IPAddressClaimReconciler) allocateAddress(claim *ipamv1.IPAddressClaim,
354354
address.Spec.Gateway = poolSpec.Gateway
355355
address.Spec.Prefix = poolSpec.Prefix
356356

357+
// Ensure the IPAddress has a ClusterNameLabel that can be used when searching for
358+
// resources associated with the target cluster.
359+
if val, ok := claim.Labels[clusterv1.ClusterNameLabel]; ok {
360+
address.Labels[clusterv1.ClusterNameLabel] = val
361+
}
362+
357363
return &address, nil
358364
}
359365

internal/controllers/ipaddressclaim_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ var _ = Describe("IPAddressClaimReconciler", func() {
9090
})
9191

9292
When("the referenced namespaced pool exists", func() {
93-
const poolName = "test-pool"
93+
const (
94+
clusterName = "test-cluster"
95+
poolName = "test-pool"
96+
)
9497

9598
BeforeEach(func() {
9699
pool := v1alpha2.InClusterIPPool{
@@ -115,6 +118,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
115118

116119
It("should allocate an Address from the Pool", func() {
117120
claim := newClaim("test", namespace, "InClusterIPPool", poolName)
121+
claim.Labels = map[string]string{clusterv1.ClusterNameLabel: clusterName}
118122
expectedIPAddress := ipamv1.IPAddress{
119123
ObjectMeta: metav1.ObjectMeta{
120124
Name: "test",
@@ -136,6 +140,7 @@ var _ = Describe("IPAddressClaimReconciler", func() {
136140
Name: poolName,
137141
},
138142
},
143+
Labels: map[string]string{clusterv1.ClusterNameLabel: clusterName},
139144
},
140145
Spec: ipamv1.IPAddressSpec{
141146
ClaimRef: corev1.LocalObjectReference{

0 commit comments

Comments
 (0)