Skip to content

Commit c853d7d

Browse files
committed
fix: ensure correct APIVersion in AWSClusterControllerIdentity conversion
The conversion webhook for AWSClusterControllerIdentity was failing with: - expected infrastructure.cluster.x-k8s.io/v1beta2, received infrastructure.cluster.x-k8s.io/v1beta1 - Error from server: conversion webhook returned invalid object: invalid groupVersion Root cause: The auto-generated conversion function (Convert_v1beta1_AWSClusterControllerIdentity_To_v1beta2_AWSClusterControllerIdentity) copies TypeMeta directly from the source object, which includes the APIVersion field. This results in the converted v1beta2 object retaining the v1beta1 APIVersion, causing the conversion webhook to reject it as invalid. Fix: Explicitly set the APIVersion to the target version (v1beta2) after calling the auto-generated conversion function in both ConvertTo methods for AWSClusterControllerIdentity and AWSClusterControllerIdentityList. This ensures the converted object has the correct APIVersion that matches the target API version expected by Kubernetes. This fix ensures that when Kubernetes requests conversion from v1beta1 to v1beta2, the webhook returns objects with the correct APIVersion, allowing the conversion to succeed.
1 parent 9274e10 commit c853d7d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

api/v1beta1/awsidentity_conversion.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ import (
2525
// ConvertTo converts the v1beta1 AWSClusterControllerIdentity receiver to a v1beta2 AWSClusterControllerIdentity.
2626
func (src *AWSClusterControllerIdentity) ConvertTo(dstRaw conversion.Hub) error {
2727
dst := dstRaw.(*infrav1.AWSClusterControllerIdentity)
28-
return Convert_v1beta1_AWSClusterControllerIdentity_To_v1beta2_AWSClusterControllerIdentity(src, dst, nil)
28+
if err := Convert_v1beta1_AWSClusterControllerIdentity_To_v1beta2_AWSClusterControllerIdentity(src, dst, nil); err != nil {
29+
return err
30+
}
31+
// Ensure the APIVersion is set correctly after conversion
32+
dst.APIVersion = infrav1.GroupVersion.String()
33+
return nil
2934
}
3035

3136
// ConvertFrom converts the v1beta2 AWSClusterControllerIdentity to a v1beta1 AWSClusterControllerIdentity.
@@ -38,7 +43,12 @@ func (dst *AWSClusterControllerIdentity) ConvertFrom(srcRaw conversion.Hub) erro
3843
// ConvertTo converts the v1beta1 AWSClusterControllerIdentityList receiver to a v1beta2 AWSClusterControllerIdentityList.
3944
func (src *AWSClusterControllerIdentityList) ConvertTo(dstRaw conversion.Hub) error {
4045
dst := dstRaw.(*infrav1.AWSClusterControllerIdentityList)
41-
return Convert_v1beta1_AWSClusterControllerIdentityList_To_v1beta2_AWSClusterControllerIdentityList(src, dst, nil)
46+
if err := Convert_v1beta1_AWSClusterControllerIdentityList_To_v1beta2_AWSClusterControllerIdentityList(src, dst, nil); err != nil {
47+
return err
48+
}
49+
// Ensure the APIVersion is set correctly after conversion
50+
dst.APIVersion = infrav1.GroupVersion.String()
51+
return nil
4252
}
4353

4454
// ConvertFrom converts the v1beta2 AWSClusterControllerIdentityList to a v1beta1 AWSClusterControllerIdentityList.

0 commit comments

Comments
 (0)