sigs.k8s.io/cluster-api-provider-aws@v1.5.5/api/v1alpha4/awscluster_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  	apiconversion "k8s.io/apimachinery/pkg/conversion"
    21  	infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
    22  	clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
    23  	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
    24  	utilconversion "sigs.k8s.io/cluster-api/util/conversion"
    25  	"sigs.k8s.io/controller-runtime/pkg/conversion"
    26  )
    27  
    28  // ConvertTo converts the v1alpha4 AWSCluster receiver to a v1beta1 AWSCluster.
    29  func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
    30  	dst := dstRaw.(*infrav1.AWSCluster)
    31  
    32  	if err := Convert_v1alpha4_AWSCluster_To_v1beta1_AWSCluster(src, dst, nil); err != nil {
    33  		return err
    34  	}
    35  	// Manually restore data.
    36  	restored := &infrav1.AWSCluster{}
    37  	if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
    38  		return err
    39  	}
    40  
    41  	if restored.Spec.ControlPlaneLoadBalancer != nil {
    42  		if dst.Spec.ControlPlaneLoadBalancer == nil {
    43  			dst.Spec.ControlPlaneLoadBalancer = &infrav1.AWSLoadBalancerSpec{}
    44  		}
    45  		restoreControlPlaneLoadBalancer(restored.Spec.ControlPlaneLoadBalancer, dst.Spec.ControlPlaneLoadBalancer)
    46  	}
    47  
    48  	dst.Spec.S3Bucket = restored.Spec.S3Bucket
    49  
    50  	return nil
    51  }
    52  
    53  // restoreControlPlaneLoadBalancer manually restores the control plane loadbalancer data.
    54  // Assumes restored and dst are non-nil.
    55  func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec) {
    56  	dst.Name = restored.Name
    57  	dst.HealthCheckProtocol = restored.HealthCheckProtocol
    58  }
    59  
    60  // ConvertFrom converts the v1beta1 AWSCluster receiver to a v1alpha4 AWSCluster.
    61  func (r *AWSCluster) ConvertFrom(srcRaw conversion.Hub) error {
    62  	src := srcRaw.(*infrav1.AWSCluster)
    63  
    64  	if err := Convert_v1beta1_AWSCluster_To_v1alpha4_AWSCluster(src, r, nil); err != nil {
    65  		return err
    66  	}
    67  
    68  	// Preserve Hub data on down-conversion.
    69  	if err := utilconversion.MarshalData(src, r); err != nil {
    70  		return err
    71  	}
    72  
    73  	return nil
    74  }
    75  
    76  // Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint .
    77  func Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint(in *clusterv1alpha4.APIEndpoint, out *clusterv1.APIEndpoint, s apiconversion.Scope) error {
    78  	return clusterv1alpha4.Convert_v1alpha4_APIEndpoint_To_v1beta1_APIEndpoint(in, out, s)
    79  }
    80  
    81  // Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint .
    82  func Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in *clusterv1.APIEndpoint, out *clusterv1alpha4.APIEndpoint, s apiconversion.Scope) error {
    83  	return clusterv1alpha4.Convert_v1beta1_APIEndpoint_To_v1alpha4_APIEndpoint(in, out, s)
    84  }
    85  
    86  // ConvertTo converts the v1alpha4 AWSClusterList receiver to a v1beta1 AWSClusterList.
    87  func (src *AWSClusterList) ConvertTo(dstRaw conversion.Hub) error {
    88  	dst := dstRaw.(*infrav1.AWSClusterList)
    89  
    90  	return Convert_v1alpha4_AWSClusterList_To_v1beta1_AWSClusterList(src, dst, nil)
    91  }
    92  
    93  // ConvertFrom converts the v1beta1 AWSClusterList receiver to a v1alpha4 AWSClusterList.
    94  func (r *AWSClusterList) ConvertFrom(srcRaw conversion.Hub) error {
    95  	src := srcRaw.(*infrav1.AWSClusterList)
    96  
    97  	return Convert_v1beta1_AWSClusterList_To_v1alpha4_AWSClusterList(src, r, nil)
    98  }
    99  
   100  func Convert_v1beta1_AWSLoadBalancerSpec_To_v1alpha4_AWSLoadBalancerSpec(in *infrav1.AWSLoadBalancerSpec, out *AWSLoadBalancerSpec, s apiconversion.Scope) error {
   101  	return autoConvert_v1beta1_AWSLoadBalancerSpec_To_v1alpha4_AWSLoadBalancerSpec(in, out, s)
   102  }