sigs.k8s.io/cluster-api@v1.7.1/internal/apis/core/exp/v1alpha4/conversion.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1alpha4
    18  
    19  import (
    20  	"sigs.k8s.io/controller-runtime/pkg/conversion"
    21  
    22  	expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
    23  	utilconversion "sigs.k8s.io/cluster-api/util/conversion"
    24  )
    25  
    26  func (src *MachinePool) ConvertTo(dstRaw conversion.Hub) error {
    27  	dst := dstRaw.(*expv1.MachinePool)
    28  
    29  	if err := Convert_v1alpha4_MachinePool_To_v1beta1_MachinePool(src, dst, nil); err != nil {
    30  		return err
    31  	}
    32  
    33  	// Manually restore data.
    34  	restored := &expv1.MachinePool{}
    35  	if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
    36  		return err
    37  	}
    38  	dst.Spec.Template.Spec.NodeDeletionTimeout = restored.Spec.Template.Spec.NodeDeletionTimeout
    39  	dst.Spec.Template.Spec.NodeVolumeDetachTimeout = restored.Spec.Template.Spec.NodeVolumeDetachTimeout
    40  	return nil
    41  }
    42  
    43  func (dst *MachinePool) ConvertFrom(srcRaw conversion.Hub) error {
    44  	src := srcRaw.(*expv1.MachinePool)
    45  
    46  	if err := Convert_v1beta1_MachinePool_To_v1alpha4_MachinePool(src, dst, nil); err != nil {
    47  		return err
    48  	}
    49  	return utilconversion.MarshalData(src, dst)
    50  }
    51  
    52  func (src *MachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
    53  	dst := dstRaw.(*expv1.MachinePoolList)
    54  
    55  	return Convert_v1alpha4_MachinePoolList_To_v1beta1_MachinePoolList(src, dst, nil)
    56  }
    57  
    58  func (dst *MachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {
    59  	src := srcRaw.(*expv1.MachinePoolList)
    60  
    61  	return Convert_v1beta1_MachinePoolList_To_v1alpha4_MachinePoolList(src, dst, nil)
    62  }