sigs.k8s.io/cluster-api-provider-aws@v1.5.5/exp/api/v1alpha3/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 v1alpha3
    18  
    19  import (
    20  	apiconversion "k8s.io/apimachinery/pkg/conversion"
    21  	utilconversion "sigs.k8s.io/cluster-api/util/conversion"
    22  	"sigs.k8s.io/controller-runtime/pkg/conversion"
    23  
    24  	infrav1alpha3 "sigs.k8s.io/cluster-api-provider-aws/api/v1alpha3"
    25  	infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
    26  	infrav1exp "sigs.k8s.io/cluster-api-provider-aws/exp/api/v1beta1"
    27  )
    28  
    29  // ConvertTo converts the v1alpha3 AWSMachinePool receiver to a v1beta1 AWSMachinePool.
    30  func (r *AWSMachinePool) ConvertTo(dstRaw conversion.Hub) error {
    31  	dst := dstRaw.(*infrav1exp.AWSMachinePool)
    32  	if err := Convert_v1alpha3_AWSMachinePool_To_v1beta1_AWSMachinePool(r, dst, nil); err != nil {
    33  		return err
    34  	}
    35  	// Manually restore data.
    36  	restored := &infrav1exp.AWSMachinePool{}
    37  	if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
    38  		return err
    39  	}
    40  
    41  	infrav1alpha3.RestoreAMIReference(&restored.Spec.AWSLaunchTemplate.AMI, &dst.Spec.AWSLaunchTemplate.AMI)
    42  	if restored.Spec.AWSLaunchTemplate.RootVolume != nil {
    43  		if dst.Spec.AWSLaunchTemplate.RootVolume == nil {
    44  			dst.Spec.AWSLaunchTemplate.RootVolume = &infrav1.Volume{}
    45  		}
    46  		infrav1alpha3.RestoreRootVolume(restored.Spec.AWSLaunchTemplate.RootVolume, dst.Spec.AWSLaunchTemplate.RootVolume)
    47  	}
    48  	return nil
    49  }
    50  
    51  // ConvertFrom converts the v1beta1 AWSMachinePool receiver to a v1alpha3 AWSMachinePool.
    52  func (r *AWSMachinePool) ConvertFrom(srcRaw conversion.Hub) error {
    53  	src := srcRaw.(*infrav1exp.AWSMachinePool)
    54  
    55  	if err := Convert_v1beta1_AWSMachinePool_To_v1alpha3_AWSMachinePool(src, r, nil); err != nil {
    56  		return err
    57  	}
    58  	// Preserve Hub data on down-conversion.
    59  	if err := utilconversion.MarshalData(src, r); err != nil {
    60  		return err
    61  	}
    62  	return nil
    63  }
    64  
    65  // ConvertTo converts the v1alpha3 AWSMachinePoolList receiver to a v1beta1 AWSMachinePoolList.
    66  func (r *AWSMachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
    67  	dst := dstRaw.(*infrav1exp.AWSMachinePoolList)
    68  
    69  	return Convert_v1alpha3_AWSMachinePoolList_To_v1beta1_AWSMachinePoolList(r, dst, nil)
    70  }
    71  
    72  // ConvertFrom converts the v1beta1 AWSMachinePoolList receiver to a v1alpha3 AWSMachinePoolList.
    73  func (r *AWSMachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {
    74  	src := srcRaw.(*infrav1exp.AWSMachinePoolList)
    75  
    76  	return Convert_v1beta1_AWSMachinePoolList_To_v1alpha3_AWSMachinePoolList(src, r, nil)
    77  }
    78  
    79  // ConvertTo converts the v1alpha3 AWSManagedMachinePool receiver to a v1beta1 AWSManagedMachinePool.
    80  func (r *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
    81  	dst := dstRaw.(*infrav1exp.AWSManagedMachinePool)
    82  	if err := Convert_v1alpha3_AWSManagedMachinePool_To_v1beta1_AWSManagedMachinePool(r, dst, nil); err != nil {
    83  		return err
    84  	}
    85  
    86  	restored := &infrav1exp.AWSManagedMachinePool{}
    87  	if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
    88  		return err
    89  	}
    90  
    91  	dst.Spec.Taints = restored.Spec.Taints
    92  	dst.Spec.CapacityType = restored.Spec.CapacityType
    93  	dst.Spec.RoleAdditionalPolicies = restored.Spec.RoleAdditionalPolicies
    94  	dst.Spec.UpdateConfig = restored.Spec.UpdateConfig
    95  
    96  	return nil
    97  }
    98  
    99  // ConvertFrom converts the v1beta1 AWSManagedMachinePool receiver to a v1alpha3 AWSManagedMachinePool.
   100  func (r *AWSManagedMachinePool) ConvertFrom(srcRaw conversion.Hub) error {
   101  	src := srcRaw.(*infrav1exp.AWSManagedMachinePool)
   102  
   103  	if err := Convert_v1beta1_AWSManagedMachinePool_To_v1alpha3_AWSManagedMachinePool(src, r, nil); err != nil {
   104  		return err
   105  	}
   106  
   107  	if err := utilconversion.MarshalData(src, r); err != nil {
   108  		return err
   109  	}
   110  
   111  	return nil
   112  }
   113  
   114  // ConvertTo converts the v1alpha3 AWSManagedMachinePoolList receiver to a v1beta1 AWSManagedMachinePoolList.
   115  func (r *AWSManagedMachinePoolList) ConvertTo(dstRaw conversion.Hub) error {
   116  	dst := dstRaw.(*infrav1exp.AWSManagedMachinePoolList)
   117  
   118  	return Convert_v1alpha3_AWSManagedMachinePoolList_To_v1beta1_AWSManagedMachinePoolList(r, dst, nil)
   119  }
   120  
   121  // ConvertFrom converts the v1beta1 AWSManagedMachinePoolList receiver to a v1alpha3 AWSManagedMachinePoolList.
   122  func (r *AWSManagedMachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {
   123  	src := srcRaw.(*infrav1exp.AWSManagedMachinePoolList)
   124  
   125  	return Convert_v1beta1_AWSManagedMachinePoolList_To_v1alpha3_AWSManagedMachinePoolList(src, r, nil)
   126  }
   127  
   128  // ConvertTo converts the v1alpha3 AWSFargateProfile receiver to a v1beta1 AWSFargateProfile.
   129  func (r *AWSFargateProfile) ConvertTo(dstRaw conversion.Hub) error {
   130  	dst := dstRaw.(*infrav1exp.AWSFargateProfile)
   131  
   132  	return Convert_v1alpha3_AWSFargateProfile_To_v1beta1_AWSFargateProfile(r, dst, nil)
   133  }
   134  
   135  // ConvertFrom converts the v1beta1 AWSFargateProfile receiver to a v1alpha3 AWSFargateProfile.
   136  func (r *AWSFargateProfile) ConvertFrom(srcRaw conversion.Hub) error {
   137  	src := srcRaw.(*infrav1exp.AWSFargateProfile)
   138  
   139  	return Convert_v1beta1_AWSFargateProfile_To_v1alpha3_AWSFargateProfile(src, r, nil)
   140  }
   141  
   142  // ConvertTo converts the v1alpha3 AWSFargateProfileList receiver to a v1beta1 AWSFargateProfileList.
   143  func (r *AWSFargateProfileList) ConvertTo(dstRaw conversion.Hub) error {
   144  	dst := dstRaw.(*infrav1exp.AWSFargateProfileList)
   145  
   146  	return Convert_v1alpha3_AWSFargateProfileList_To_v1beta1_AWSFargateProfileList(r, dst, nil)
   147  }
   148  
   149  // ConvertFrom converts the v1beta1 AWSFargateProfileList receiver to a v1alpha3 AWSFargateProfileList.
   150  func (r *AWSFargateProfileList) ConvertFrom(srcRaw conversion.Hub) error {
   151  	src := srcRaw.(*infrav1exp.AWSFargateProfileList)
   152  
   153  	return Convert_v1beta1_AWSFargateProfileList_To_v1alpha3_AWSFargateProfileList(src, r, nil)
   154  }
   155  
   156  // Convert_v1alpha3_AWSResourceReference_To_v1beta1_AWSResourceReference is a conversion function.
   157  func Convert_v1alpha3_AWSResourceReference_To_v1beta1_AWSResourceReference(in *infrav1alpha3.AWSResourceReference, out *infrav1.AWSResourceReference, s apiconversion.Scope) error {
   158  	return infrav1alpha3.Convert_v1alpha3_AWSResourceReference_To_v1beta1_AWSResourceReference(in, out, s)
   159  }
   160  
   161  // Convert_v1beta1_AWSResourceReference_To_v1alpha3_AWSResourceReference conversion function.
   162  func Convert_v1beta1_AWSResourceReference_To_v1alpha3_AWSResourceReference(in *infrav1.AWSResourceReference, out *infrav1alpha3.AWSResourceReference, s apiconversion.Scope) error {
   163  	return infrav1alpha3.Convert_v1beta1_AWSResourceReference_To_v1alpha3_AWSResourceReference(in, out, s)
   164  }
   165  
   166  // Convert_v1beta1_AWSManagedMachinePoolSpec_To_v1alpha3_AWSManagedMachinePoolSpec is a conversion function.
   167  func Convert_v1beta1_AWSManagedMachinePoolSpec_To_v1alpha3_AWSManagedMachinePoolSpec(in *infrav1exp.AWSManagedMachinePoolSpec, out *AWSManagedMachinePoolSpec, s apiconversion.Scope) error {
   168  	return autoConvert_v1beta1_AWSManagedMachinePoolSpec_To_v1alpha3_AWSManagedMachinePoolSpec(in, out, s)
   169  }
   170  
   171  // Convert_v1alpha3_Instance_To_v1beta1_Instance is a conversion function.
   172  func Convert_v1alpha3_Instance_To_v1beta1_Instance(in *infrav1alpha3.Instance, out *infrav1.Instance, s apiconversion.Scope) error {
   173  	return infrav1alpha3.Convert_v1alpha3_Instance_To_v1beta1_Instance(in, out, s)
   174  }
   175  
   176  // Convert_v1alpha3_Volume_To_v1beta1_Volume is a conversion function.
   177  func Convert_v1alpha3_Volume_To_v1beta1_Volume(in *infrav1alpha3.Volume, out *infrav1.Volume, s apiconversion.Scope) error {
   178  	return infrav1alpha3.Convert_v1alpha3_Volume_To_v1beta1_Volume(in, out, s)
   179  }