File tree 2 files changed +14
-2
lines changed 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,9 @@ func (src *IPAddressClaim) ConvertTo(dstRaw conversion.Hub) error {
54
54
return err
55
55
}
56
56
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
+ }
58
60
59
61
return nil
60
62
}
@@ -67,6 +69,9 @@ func (dst *IPAddressClaim) ConvertFrom(srcRaw conversion.Hub) error {
67
69
}
68
70
69
71
if src .Spec .ClusterName != "" {
72
+ if dst .ObjectMeta .Labels == nil {
73
+ dst .ObjectMeta .Labels = map [string ]string {}
74
+ }
70
75
dst .ObjectMeta .Labels ["cluster.x-k8s.io/cluster-name" ] = src .Spec .ClusterName
71
76
}
72
77
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ limitations under the License.
17
17
package v1alpha1
18
18
19
19
import (
20
+ "sigs.k8s.io/controller-runtime/pkg/conversion"
20
21
"testing"
21
22
22
23
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
@@ -32,7 +33,13 @@ func TestFuzzyConversion(t *testing.T) {
32
33
FuzzerFuncs : []fuzzer.FuzzerFuncs {},
33
34
}))
34
35
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
+ },
36
43
Spoke : & IPAddressClaim {},
37
44
FuzzerFuncs : []fuzzer.FuzzerFuncs {},
38
45
}))
You can’t perform that action at this time.
0 commit comments