Skip to content

Commit

Permalink
fix fuzzy conversion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schrej committed Mar 25, 2024
1 parent 9960dda commit b54469d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion exp/ipam/api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ func (src *IPAddressClaim) ConvertTo(dstRaw conversion.Hub) error {
return err
}

dst.Spec.ClusterName = src.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"]
if src.ObjectMeta.Labels != nil {
dst.Spec.ClusterName = src.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"]
if dst.ObjectMeta.Annotations != nil && dst.ObjectMeta.Annotations["conversion.cluster.x-k8s.io/cluster-name-label-set"] != "" {
delete(src.ObjectMeta.Labels, "cluster.x-k8s.io/cluster-name")
delete(src.ObjectMeta.Annotations, "conversion.cluster.x-k8s.io/cluster-name-label-set")
}
}

return nil
}
Expand All @@ -67,6 +73,15 @@ func (dst *IPAddressClaim) ConvertFrom(srcRaw conversion.Hub) error {
}

if src.Spec.ClusterName != "" {
if dst.ObjectMeta.Labels == nil {
dst.ObjectMeta.Labels = map[string]string{}
}
if _, ok := dst.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"]; !ok {
if dst.ObjectMeta.Annotations == nil {
dst.ObjectMeta.Annotations = map[string]string{}
}
dst.ObjectMeta.Annotations["conversion.cluster.x-k8s.io/cluster-name-label-set"] = "false"
}
dst.ObjectMeta.Labels["cluster.x-k8s.io/cluster-name"] = src.Spec.ClusterName
}

Expand Down

0 comments on commit b54469d

Please sign in to comment.