Skip to content

Commit dbc96ca

Browse files
committed
fix fuzzy conversion tests
1 parent 9960dda commit dbc96ca

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

exp/ipam/api/v1alpha1/conversion.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ func (src *IPAddressClaim) ConvertTo(dstRaw conversion.Hub) error {
5454
return err
5555
}
5656

57-
dst.Spec.ClusterName = src.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"]
57+
if src.ObjectMeta.Labels != nil {
58+
dst.Spec.ClusterName = src.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"]
59+
}
5860

5961
return nil
6062
}
@@ -67,6 +69,9 @@ func (dst *IPAddressClaim) ConvertFrom(srcRaw conversion.Hub) error {
6769
}
6870

6971
if src.Spec.ClusterName != "" {
72+
if dst.ObjectMeta.Labels == nil {
73+
dst.ObjectMeta.Labels = map[string]string{}
74+
}
7075
dst.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"] = src.Spec.ClusterName
7176
}
7277

exp/ipam/api/v1alpha1/conversion_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"sigs.k8s.io/controller-runtime/pkg/conversion"
2021
"testing"
2122

2223
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
@@ -32,7 +33,13 @@ func TestFuzzyConversion(t *testing.T) {
3233
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
3334
}))
3435
t.Run("for IPAddressClaim", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
35-
Hub: &ipamv1.IPAddressClaim{},
36+
Hub: &ipamv1.IPAddressClaim{},
37+
HubAfterMutation: func(hub conversion.Hub) {
38+
addr := hub.(*ipamv1.IPAddressClaim)
39+
if addr.Labels != nil {
40+
delete(addr.Labels, "cluster.x-k8s.io/cluster-name")
41+
}
42+
},
3643
Spoke: &IPAddressClaim{},
3744
FuzzerFuncs: []fuzzer.FuzzerFuncs{},
3845
}))

0 commit comments

Comments
 (0)