sigs.k8s.io/cluster-api-provider-aws@v1.5.5/api/v1alpha4/awsclustertemplate_conversion.go (about)

     1  /*
     2  Copyright 2022 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  	apiconversion "k8s.io/apimachinery/pkg/conversion"
    21  	infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
    22  	utilconversion "sigs.k8s.io/cluster-api/util/conversion"
    23  	"sigs.k8s.io/controller-runtime/pkg/conversion"
    24  )
    25  
    26  // ConvertTo converts the v1alpha4 AWSClusterTemplate receiver to a v1beta1 AWSClusterTemplate.
    27  func (r *AWSClusterTemplate) ConvertTo(dstRaw conversion.Hub) error {
    28  	dst := dstRaw.(*infrav1.AWSClusterTemplate)
    29  
    30  	if err := Convert_v1alpha4_AWSClusterTemplate_To_v1beta1_AWSClusterTemplate(r, dst, nil); err != nil {
    31  		return err
    32  	}
    33  
    34  	// Manually restore data.
    35  	restored := &infrav1.AWSClusterTemplate{}
    36  	if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
    37  		return err
    38  	}
    39  
    40  	dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta
    41  
    42  	return nil
    43  }
    44  
    45  // ConvertFrom converts the v1beta1 AWSClusterTemplate receiver to a v1alpha4 AWSClusterTemplate.
    46  func (r *AWSClusterTemplate) ConvertFrom(srcRaw conversion.Hub) error {
    47  	src := srcRaw.(*infrav1.AWSClusterTemplate)
    48  
    49  	if err := Convert_v1beta1_AWSClusterTemplate_To_v1alpha4_AWSClusterTemplate(src, r, nil); err != nil {
    50  		return err
    51  	}
    52  
    53  	// Preserve Hub data on down-conversion.
    54  	if err := utilconversion.MarshalData(src, r); err != nil {
    55  		return err
    56  	}
    57  
    58  	return nil
    59  }
    60  
    61  // ConvertTo converts the v1alpha4 AWSClusterTemplateList receiver to a v1beta1 AWSClusterTemplateList.
    62  func (r *AWSClusterTemplateList) ConvertTo(dstRaw conversion.Hub) error {
    63  	dst := dstRaw.(*infrav1.AWSClusterTemplateList)
    64  
    65  	if err := Convert_v1alpha4_AWSClusterTemplateList_To_v1beta1_AWSClusterTemplateList(r, dst, nil); err != nil {
    66  		return err
    67  	}
    68  
    69  	return nil
    70  }
    71  
    72  // ConvertFrom converts the v1beta1 AWSClusterTemplateList receiver to a v1alpha4 AWSClusterTemplateList.
    73  func (r *AWSClusterTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
    74  	src := srcRaw.(*infrav1.AWSClusterTemplateList)
    75  
    76  	if err := Convert_v1beta1_AWSClusterTemplateList_To_v1alpha4_AWSClusterTemplateList(src, r, nil); err != nil {
    77  		return err
    78  	}
    79  
    80  	return nil
    81  }
    82  
    83  func Convert_v1beta1_AWSClusterTemplateResource_To_v1alpha4_AWSClusterTemplateResource(in *infrav1.AWSClusterTemplateResource, out *AWSClusterTemplateResource, s apiconversion.Scope) error {
    84  	return autoConvert_v1beta1_AWSClusterTemplateResource_To_v1alpha4_AWSClusterTemplateResource(in, out, s)
    85  }