Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(autoscaling): fix diff issue of auto scaling group #1869

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 49 additions & 27 deletions pkg/controller/autoscaling/autoscalinggroup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package autoscalinggroup

import (
"context"
"fmt"
"sort"

svcsdk "github.com/aws/aws-sdk-go/service/autoscaling"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/google/go-cmp/cmp"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"

svcapitypes "github.com/crossplane-contrib/provider-aws/apis/autoscaling/v1beta1"
Expand Down Expand Up @@ -71,84 +73,90 @@ func isUpToDate(_ context.Context, obj *svcapitypes.AutoScalingGroup, obs *svcsd
asg := obs.AutoScalingGroups[0]

if !cmp.Equal(in.CapacityRebalance, asg.CapacityRebalance) {
return false, "", nil
return false, "spec.forProvider.capacityRebalance", nil
}
// DefaultInstanceWarmup can be updated
if !cmp.Equal(in.DefaultInstanceWarmup, asg.DefaultInstanceWarmup) {
return false, "", nil
return false, "spec.forProvider.defaultInstanceWarmup", nil
}
// DesiredCapacityType can be updated
if !cmp.Equal(in.DesiredCapacityType, asg.DesiredCapacityType) {
return false, "", nil
return false, "spec.forProvider.desiredCapacityType", nil
}
// Context is reserved
// if !cmp.Equal(*in.Context, *asg.Context) {
// return false, nil
// }
// DefaultCooldown can be updated
if !cmp.Equal(in.DefaultCooldown, asg.DefaultCooldown) {
return false, "", nil
return false, "spec.forProvider.defaultCooldown", nil
}
// DesiredCapacity can be updated
if !cmp.Equal(in.DesiredCapacity, asg.DesiredCapacity) {
return false, "", nil
return false, "spec.forProvider.desiredCapacity", nil
}
// HealthCheckGracePeriod can be updated
if !cmp.Equal(in.HealthCheckGracePeriod, asg.HealthCheckGracePeriod) {
return false, "", nil
return false, "spec.forProvider.healthCheckGracePeriod", nil
}
// HealthCheckType can be updated
if !cmp.Equal(in.HealthCheckType, asg.HealthCheckType) {
return false, "", nil
return false, "spec.forProvider.healthCheckType", nil
}
// MaxInstanceLifetime can be updated
if !cmp.Equal(in.MaxInstanceLifetime, asg.MaxInstanceLifetime) {
return false, "", nil
return false, "spec.forProvider.maxInstanceLifetime", nil
}
// MaxSize can be updated
if !cmp.Equal(in.MaxSize, asg.MaxSize) {
return false, "", nil
return false, "spec.forProvider.maxSize", nil
}
// MinSize can be updated
if !cmp.Equal(in.MinSize, asg.MinSize) {
return false, "", nil
return false, "spec.forProvider.minSize", nil
}
// NewInstancesProtectedFromScaleIn can be updated
if !cmp.Equal(in.NewInstancesProtectedFromScaleIn, asg.NewInstancesProtectedFromScaleIn) {
return false, "", nil
return false, "spec.forProvider.newInstancesProtectedFromScaleIn", nil
}
if !cmp.Equal(in.PlacementGroup, asg.PlacementGroup) {
return false, "", nil
return false, "spec.forProvider.placementGroup", nil
}
// VPCZoneIdentifier can be updated
if !cmp.Equal(in.VPCZoneIdentifier, asg.VPCZoneIdentifier) {
return false, "", nil
return false, "spec.forProvider.vpcZoneIdentifier", nil
}
// LaunchTemplate can be updated
if in.LaunchTemplate != nil && asg.LaunchTemplate != nil {
if !cmp.Equal(in.LaunchTemplate.LaunchTemplateID, asg.LaunchTemplate.LaunchTemplateId) {
return false, "", nil
if in.LaunchTemplate.LaunchTemplateID != nil {
MisterMX marked this conversation as resolved.
Show resolved Hide resolved
if !cmp.Equal(in.LaunchTemplate.LaunchTemplateID, asg.LaunchTemplate.LaunchTemplateId) {
return false, "spec.forProvider.launchTemplate.launchTemplateID", nil
}
}
if !cmp.Equal(in.LaunchTemplate.LaunchTemplateName, asg.LaunchTemplate.LaunchTemplateName) {
return false, "", nil
if in.LaunchTemplate.LaunchTemplateName != nil {
if !cmp.Equal(in.LaunchTemplate.LaunchTemplateName, asg.LaunchTemplate.LaunchTemplateName) {
return false, "spec.forProvider.launchTemplate.launchTemplateName", nil
}
}
if !cmp.Equal(in.LaunchTemplate.Version, asg.LaunchTemplate.Version) {
return false, "", nil
if in.LaunchTemplate.Version != nil {
if !cmp.Equal(in.LaunchTemplate.Version, asg.LaunchTemplate.Version) {
return false, "spec.forProvider.launchTemplate.version", nil
}
}
}
// MixedInstancesPolicy can be updated
if in.MixedInstancesPolicy != nil && asg.MixedInstancesPolicy != nil {
if in.MixedInstancesPolicy.InstancesDistribution != nil && asg.MixedInstancesPolicy.InstancesDistribution != nil {
if !cmp.Equal(in.MixedInstancesPolicy.InstancesDistribution, asg.MixedInstancesPolicy.InstancesDistribution) {
return false, "", nil
return false, "spec.forProvider.mixedInstancesPolicy.instancesDistribution", nil
}
}
if in.MixedInstancesPolicy.LaunchTemplate != nil && asg.MixedInstancesPolicy.LaunchTemplate != nil {
if !cmp.Equal(in.MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification, asg.MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification) {
return false, "", nil
return false, "spec.forProvider.mixedInstancesPolicy.launchTemplate.launchTemplateSpecification", nil
}
if !cmp.Equal(in.MixedInstancesPolicy.LaunchTemplate.Overrides, asg.MixedInstancesPolicy.LaunchTemplate.Overrides) {
return false, "", nil
return false, "spec.forProvider.mixedInstancesPolicy.launchTemplate.overrides", nil
}
}
}
Expand All @@ -160,7 +168,7 @@ func isUpToDate(_ context.Context, obj *svcapitypes.AutoScalingGroup, obs *svcsd
return *asg.AvailabilityZones[i] < *asg.AvailabilityZones[j]
})
if !cmp.Equal(in.AvailabilityZones, asg.AvailabilityZones) {
return false, "", nil
return false, "spec.forProvider.availabilityZones", nil
}
// LoadBalancerNames can be updated
sort.Slice(in.LoadBalancerNames, func(i, j int) bool {
Expand All @@ -170,7 +178,7 @@ func isUpToDate(_ context.Context, obj *svcapitypes.AutoScalingGroup, obs *svcsd
return *asg.LoadBalancerNames[i] < *asg.LoadBalancerNames[j]
})
if !cmp.Equal(in.LoadBalancerNames, asg.LoadBalancerNames) {
return false, "", nil
return false, "spec.forProvider.loadBalancerNames", nil
}
// Tags can be updated
sort.Slice(in.Tags, func(i, j int) bool {
Expand All @@ -179,8 +187,21 @@ func isUpToDate(_ context.Context, obj *svcapitypes.AutoScalingGroup, obs *svcsd
sort.Slice(asg.Tags, func(i, j int) bool {
return *asg.Tags[i].Key < *asg.Tags[j].Key
})
if !cmp.Equal(in.Tags, asg.Tags) {
return false, "", nil
if len(in.Tags) != len(asg.Tags) {
return false, "spec.forProvider.tags", nil
}
for i := range in.Tags {
a := in.Tags[i]
b := asg.Tags[i]
if !ptr.Equal(a.Key, b.Key) {
return false, fmt.Sprintf("spec.forProvider.tags[%d].key", i), nil
}
if !ptr.Equal(a.Value, b.Value) {
return false, fmt.Sprintf("spec.forProvider.tags[%d].value", i), nil
}
if !ptr.Equal(a.PropagateAtLaunch, b.PropagateAtLaunch) {
return false, fmt.Sprintf("spec.forProvider.tags[%d].propagateAtLaunch", i), nil
}
}
MisterMX marked this conversation as resolved.
Show resolved Hide resolved

// TargetGroupARNs
Expand All @@ -202,7 +223,7 @@ func isUpToDate(_ context.Context, obj *svcapitypes.AutoScalingGroup, obs *svcsd
return *asg.TerminationPolicies[i] < *asg.TerminationPolicies[j]
})
if !cmp.Equal(in.TerminationPolicies, asg.TerminationPolicies) {
return false, "", nil
return false, "spec.forProvider.terminationPolicies", nil
}

// TrafficSources
Expand Down Expand Up @@ -237,6 +258,7 @@ func lateInitialize(in *svcapitypes.AutoScalingGroupParameters, asg *svcsdk.Desc
in.TargetGroupARNs = awsclients.LateInitializeStringPtrSlice(in.TargetGroupARNs, obs.TargetGroupARNs)
in.TerminationPolicies = awsclients.LateInitializeStringPtrSlice(in.TerminationPolicies, obs.TerminationPolicies)
in.VPCZoneIdentifier = awsclients.LateInitializeStringPtr(in.VPCZoneIdentifier, obs.VPCZoneIdentifier)

return nil
}

Expand Down
Loading