Skip to content

Commit 6df68e2

Browse files
authored
Merge pull request #3835 from Ankitasw/remove-ARN-field
Remove ARN field from AWSResourceReference
2 parents 8dca968 + 054ee17 commit 6df68e2

14 files changed

+156
-86
lines changed

api/v1beta1/awsmachine_conversion.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (dst *AWSMachineList) ConvertFrom(srcRaw conversion.Hub) error {
6565
return Convert_v1beta2_AWSMachineList_To_v1beta1_AWSMachineList(src, dst, nil)
6666
}
6767

68-
// ConvertTo converts the v1beta1 AWSCluster receiver to a v1beta2 AWSCluster.
68+
// ConvertTo converts the v1beta1 AWSMachineTemplate receiver to a v1beta2 AWSMachineTemplate.
6969
func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
7070
dst := dstRaw.(*infrav1.AWSMachineTemplate)
7171

@@ -113,4 +113,3 @@ func (dst *AWSMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error {
113113

114114
return Convert_v1beta2_AWSMachineTemplateList_To_v1beta1_AWSMachineTemplateList(src, dst, nil)
115115
}
116-

api/v1beta1/conversion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ import (
2424
func Convert_v1beta2_AWSClusterSpec_To_v1beta1_AWSClusterSpec(in *v1beta2.AWSClusterSpec, out *AWSClusterSpec, s conversion.Scope) error {
2525
return autoConvert_v1beta2_AWSClusterSpec_To_v1beta1_AWSClusterSpec(in, out, s)
2626
}
27+
28+
func Convert_v1beta1_AWSResourceReference_To_v1beta2_AWSResourceReference(in *AWSResourceReference, out *v1beta2.AWSResourceReference, s conversion.Scope) error {
29+
return autoConvert_v1beta1_AWSResourceReference_To_v1beta2_AWSResourceReference(in, out, s)
30+
}

api/v1beta1/conversion_test.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,51 @@ import (
2121

2222
. "github.com/onsi/gomega"
2323

24-
runtime "k8s.io/apimachinery/pkg/runtime"
25-
v1beta2 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
24+
fuzz "github.com/google/gofuzz"
25+
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
26+
"k8s.io/apimachinery/pkg/runtime"
27+
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
"sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
2629
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2730
)
2831

32+
func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
33+
return []interface{}{
34+
AWSMachineFuzzer,
35+
AWSMachineTemplateFuzzer,
36+
}
37+
}
38+
39+
func AWSMachineFuzzer(obj *AWSMachine, c fuzz.Continue) {
40+
c.FuzzNoCustom(obj)
41+
42+
// AWSMachine.Spec.Subnet.ARN and AWSMachine.Spec.AdditionalSecurityGroups.ARN has been removed in v1beta2, so setting it to nil in order to avoid v1beta1 --> v1beta2 --> v1beta1 round trip errors.
43+
if obj.Spec.Subnet != nil {
44+
obj.Spec.Subnet.ARN = nil
45+
}
46+
restored := make([]AWSResourceReference, len(obj.Spec.AdditionalSecurityGroups))
47+
for _, sg := range obj.Spec.AdditionalSecurityGroups {
48+
sg.ARN = nil
49+
restored = append(restored, sg)
50+
}
51+
obj.Spec.AdditionalSecurityGroups = restored
52+
}
53+
54+
func AWSMachineTemplateFuzzer(obj *AWSMachineTemplate, c fuzz.Continue) {
55+
c.FuzzNoCustom(obj)
56+
57+
// AWSMachineTemplate.Spec.Template.Spec.FailureDomain, AWSMachineTemplate.Spec.Template.Spec.Subnet.ARN and AWSMachineTemplate.Spec.Template.Spec.AdditionalSecurityGroups.ARN has been removed in v1beta2, so setting it to nil in order to avoid v1beta1 --> v1beta2 --> v1beta round trip errors.
58+
if obj.Spec.Template.Spec.Subnet != nil {
59+
obj.Spec.Template.Spec.Subnet.ARN = nil
60+
}
61+
restored := make([]AWSResourceReference, len(obj.Spec.Template.Spec.AdditionalSecurityGroups))
62+
for _, sg := range obj.Spec.Template.Spec.AdditionalSecurityGroups {
63+
sg.ARN = nil
64+
restored = append(restored, sg)
65+
}
66+
obj.Spec.Template.Spec.AdditionalSecurityGroups = restored
67+
}
68+
2969
func TestFuzzyConversion(t *testing.T) {
3070
g := NewWithT(t)
3171
scheme := runtime.NewScheme()
@@ -42,12 +82,14 @@ func TestFuzzyConversion(t *testing.T) {
4282
Scheme: scheme,
4383
Hub: &v1beta2.AWSMachine{},
4484
Spoke: &AWSMachine{},
85+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
4586
}))
4687

4788
t.Run("for AWSMachineTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
4889
Scheme: scheme,
4990
Hub: &v1beta2.AWSMachineTemplate{},
5091
Spoke: &AWSMachineTemplate{},
92+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
5193
}))
5294

5395
t.Run("for AWSClusterStaticIdentity", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{

api/v1beta1/zz_generated.conversion.go

Lines changed: 90 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awsmachine_webhook.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ func (r *AWSMachine) validateAdditionalSecurityGroups() field.ErrorList {
252252
if len(additionalSecurityGroup.Filters) > 0 && additionalSecurityGroup.ID != nil {
253253
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.additionalSecurityGroups"), "only one of ID or Filters may be specified, specifying both is forbidden"))
254254
}
255-
if additionalSecurityGroup.ARN != nil {
256-
log.Info("ARN field is deprecated and is no operation function.")
257-
}
258255
}
259256
return allErrs
260257
}

api/v1beta2/types.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ type AWSResourceReference struct {
3030
// +optional
3131
ID *string `json:"id,omitempty"`
3232

33-
// ARN of resource.
34-
// +optional
35-
// Deprecated: This field has no function and is going to be removed in the next release.
36-
ARN *string `json:"arn,omitempty"`
37-
3833
// Filters is a set of key/value pairs used to identify a resource
3934
// They are applied according to the rules defined by the AWS API:
4035
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Filtering.html

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinepools.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ spec:
8787
be specified. Specifying more than one will result in a validation
8888
error.
8989
properties:
90-
arn:
91-
description: 'ARN of resource. Deprecated: This field has
92-
no function and is going to be removed in the next release.'
93-
type: string
9490
filters:
9591
description: 'Filters is a set of key/value pairs used to
9692
identify a resource They are applied according to the
@@ -341,10 +337,6 @@ spec:
341337
resource by ID or filters. Only one of ID or Filters may be specified.
342338
Specifying more than one will result in a validation error.
343339
properties:
344-
arn:
345-
description: 'ARN of resource. Deprecated: This field has no
346-
function and is going to be removed in the next release.'
347-
type: string
348340
filters:
349341
description: 'Filters is a set of key/value pairs used to identify
350342
a resource They are applied according to the rules defined
@@ -562,10 +554,6 @@ spec:
562554
be specified. Specifying more than one will result in a validation
563555
error.
564556
properties:
565-
arn:
566-
description: 'ARN of resource. Deprecated: This field has
567-
no function and is going to be removed in the next release.'
568-
type: string
569557
filters:
570558
description: 'Filters is a set of key/value pairs used to
571559
identify a resource They are applied according to the
@@ -821,10 +809,6 @@ spec:
821809
resource by ID or filters. Only one of ID or Filters may be specified.
822810
Specifying more than one will result in a validation error.
823811
properties:
824-
arn:
825-
description: 'ARN of resource. Deprecated: This field has no
826-
function and is going to be removed in the next release.'
827-
type: string
828812
filters:
829813
description: 'Filters is a set of key/value pairs used to identify
830814
a resource They are applied according to the rules defined

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,6 @@ spec:
545545
resource by ID or filters. Only one of ID or Filters may be specified.
546546
Specifying more than one will result in a validation error.
547547
properties:
548-
arn:
549-
description: 'ARN of resource. Deprecated: This field has no
550-
function and is going to be removed in the next release.'
551-
type: string
552548
filters:
553549
description: 'Filters is a set of key/value pairs used to identify
554550
a resource They are applied according to the rules defined
@@ -799,10 +795,6 @@ spec:
799795
description: Subnet is a reference to the subnet to use for this instance.
800796
If not specified, the cluster subnet will be used.
801797
properties:
802-
arn:
803-
description: 'ARN of resource. Deprecated: This field has no function
804-
and is going to be removed in the next release.'
805-
type: string
806798
filters:
807799
description: 'Filters is a set of key/value pairs used to identify
808800
a resource They are applied according to the rules defined by

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,6 @@ spec:
487487
may be specified. Specifying more than one will result
488488
in a validation error.
489489
properties:
490-
arn:
491-
description: 'ARN of resource. Deprecated: This field
492-
has no function and is going to be removed in the
493-
next release.'
494-
type: string
495490
filters:
496491
description: 'Filters is a set of key/value pairs used
497492
to identify a resource They are applied according
@@ -754,11 +749,6 @@ spec:
754749
this instance. If not specified, the cluster subnet will
755750
be used.
756751
properties:
757-
arn:
758-
description: 'ARN of resource. Deprecated: This field
759-
has no function and is going to be removed in the next
760-
release.'
761-
type: string
762752
filters:
763753
description: 'Filters is a set of key/value pairs used
764754
to identify a resource They are applied according to

0 commit comments

Comments
 (0)