Skip to content

Commit

Permalink
Merge pull request #3835 from Ankitasw/remove-ARN-field
Browse files Browse the repository at this point in the history
Remove ARN field from AWSResourceReference
  • Loading branch information
k8s-ci-robot authored Nov 15, 2022
2 parents 8dca968 + 054ee17 commit 6df68e2
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 86 deletions.
3 changes: 1 addition & 2 deletions api/v1beta1/awsmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (dst *AWSMachineList) ConvertFrom(srcRaw conversion.Hub) error {
return Convert_v1beta2_AWSMachineList_To_v1beta1_AWSMachineList(src, dst, nil)
}

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

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

return Convert_v1beta2_AWSMachineTemplateList_To_v1beta1_AWSMachineTemplateList(src, dst, nil)
}

4 changes: 4 additions & 0 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ import (
func Convert_v1beta2_AWSClusterSpec_To_v1beta1_AWSClusterSpec(in *v1beta2.AWSClusterSpec, out *AWSClusterSpec, s conversion.Scope) error {
return autoConvert_v1beta2_AWSClusterSpec_To_v1beta1_AWSClusterSpec(in, out, s)
}

func Convert_v1beta1_AWSResourceReference_To_v1beta2_AWSResourceReference(in *AWSResourceReference, out *v1beta2.AWSResourceReference, s conversion.Scope) error {
return autoConvert_v1beta1_AWSResourceReference_To_v1beta2_AWSResourceReference(in, out, s)
}
46 changes: 44 additions & 2 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,51 @@ import (

. "github.com/onsi/gomega"

runtime "k8s.io/apimachinery/pkg/runtime"
v1beta2 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
fuzz "github.com/google/gofuzz"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/runtime"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
AWSMachineFuzzer,
AWSMachineTemplateFuzzer,
}
}

func AWSMachineFuzzer(obj *AWSMachine, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// 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.
if obj.Spec.Subnet != nil {
obj.Spec.Subnet.ARN = nil
}
restored := make([]AWSResourceReference, len(obj.Spec.AdditionalSecurityGroups))
for _, sg := range obj.Spec.AdditionalSecurityGroups {
sg.ARN = nil
restored = append(restored, sg)
}
obj.Spec.AdditionalSecurityGroups = restored
}

func AWSMachineTemplateFuzzer(obj *AWSMachineTemplate, c fuzz.Continue) {
c.FuzzNoCustom(obj)

// 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.
if obj.Spec.Template.Spec.Subnet != nil {
obj.Spec.Template.Spec.Subnet.ARN = nil
}
restored := make([]AWSResourceReference, len(obj.Spec.Template.Spec.AdditionalSecurityGroups))
for _, sg := range obj.Spec.Template.Spec.AdditionalSecurityGroups {
sg.ARN = nil
restored = append(restored, sg)
}
obj.Spec.Template.Spec.AdditionalSecurityGroups = restored
}

func TestFuzzyConversion(t *testing.T) {
g := NewWithT(t)
scheme := runtime.NewScheme()
Expand All @@ -42,12 +82,14 @@ func TestFuzzyConversion(t *testing.T) {
Scheme: scheme,
Hub: &v1beta2.AWSMachine{},
Spoke: &AWSMachine{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
}))

t.Run("for AWSMachineTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1beta2.AWSMachineTemplate{},
Spoke: &AWSMachineTemplate{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
}))

t.Run("for AWSClusterStaticIdentity", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Expand Down
110 changes: 90 additions & 20 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions api/v1beta2/awsmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ func (r *AWSMachine) validateAdditionalSecurityGroups() field.ErrorList {
if len(additionalSecurityGroup.Filters) > 0 && additionalSecurityGroup.ID != nil {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.additionalSecurityGroups"), "only one of ID or Filters may be specified, specifying both is forbidden"))
}
if additionalSecurityGroup.ARN != nil {
log.Info("ARN field is deprecated and is no operation function.")
}
}
return allErrs
}
Expand Down
5 changes: 0 additions & 5 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ type AWSResourceReference struct {
// +optional
ID *string `json:"id,omitempty"`

// ARN of resource.
// +optional
// Deprecated: This field has no function and is going to be removed in the next release.
ARN *string `json:"arn,omitempty"`

// Filters is a set of key/value pairs used to identify a resource
// They are applied according to the rules defined by the AWS API:
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Filtering.html
Expand Down
5 changes: 0 additions & 5 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ spec:
be specified. Specifying more than one will result in a validation
error.
properties:
arn:
description: 'ARN of resource. Deprecated: This field has
no function and is going to be removed in the next release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used to
identify a resource They are applied according to the
Expand Down Expand Up @@ -341,10 +337,6 @@ spec:
resource by ID or filters. Only one of ID or Filters may be specified.
Specifying more than one will result in a validation error.
properties:
arn:
description: 'ARN of resource. Deprecated: This field has no
function and is going to be removed in the next release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used to identify
a resource They are applied according to the rules defined
Expand Down Expand Up @@ -562,10 +554,6 @@ spec:
be specified. Specifying more than one will result in a validation
error.
properties:
arn:
description: 'ARN of resource. Deprecated: This field has
no function and is going to be removed in the next release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used to
identify a resource They are applied according to the
Expand Down Expand Up @@ -821,10 +809,6 @@ spec:
resource by ID or filters. Only one of ID or Filters may be specified.
Specifying more than one will result in a validation error.
properties:
arn:
description: 'ARN of resource. Deprecated: This field has no
function and is going to be removed in the next release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used to identify
a resource They are applied according to the rules defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,6 @@ spec:
resource by ID or filters. Only one of ID or Filters may be specified.
Specifying more than one will result in a validation error.
properties:
arn:
description: 'ARN of resource. Deprecated: This field has no
function and is going to be removed in the next release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used to identify
a resource They are applied according to the rules defined
Expand Down Expand Up @@ -799,10 +795,6 @@ spec:
description: Subnet is a reference to the subnet to use for this instance.
If not specified, the cluster subnet will be used.
properties:
arn:
description: 'ARN of resource. Deprecated: This field has no function
and is going to be removed in the next release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used to identify
a resource They are applied according to the rules defined by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,6 @@ spec:
may be specified. Specifying more than one will result
in a validation error.
properties:
arn:
description: 'ARN of resource. Deprecated: This field
has no function and is going to be removed in the
next release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used
to identify a resource They are applied according
Expand Down Expand Up @@ -754,11 +749,6 @@ spec:
this instance. If not specified, the cluster subnet will
be used.
properties:
arn:
description: 'ARN of resource. Deprecated: This field
has no function and is going to be removed in the next
release.'
type: string
filters:
description: 'Filters is a set of key/value pairs used
to identify a resource They are applied according to
Expand Down
Loading

0 comments on commit 6df68e2

Please sign in to comment.