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

Update LoadBalancerReadyCondition on deletion #3871

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions controllers/awscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
infrav1.PrincipalCredentialRetrievedCondition,
infrav1.PrincipalUsageAllowedCondition,
infrav1.LoadBalancerReadyCondition,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change really needed?
Does setting LoadBalancerReadyCondition as done in loadbalancer.go would not suffice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking this as there are many other conditions which are patched fine without this change, hence not added here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our observation was that it didn't work without having the condition in that list. My understanding is that the patch helper will ignore conditions not owned by the controller. At least that's the impression I'm left with by the documentation here.

I'll double check, since it's been a while since I submitted this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @richardcase if you have any opinions

}})
if e != nil {
fmt.Println(e.Error())
Expand Down
3 changes: 3 additions & 0 deletions pkg/cloud/services/elb/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func (s *Service) deleteAPIServerELB() error {

apiELB, err := s.describeClassicELB(elbName)
if IsNotFound(err) {
s.scope.Debug("Control plane load balancer not found, skipping deletion")
conditions.MarkFalse(s.scope.InfraCluster(), infrav1.LoadBalancerReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "")
return nil
}
if err != nil {
Expand All @@ -156,6 +158,7 @@ func (s *Service) deleteAPIServerELB() error {

if apiELB.IsUnmanaged(s.scope.Name()) {
s.scope.Debug("Found unmanaged classic load balancer for apiserver, skipping deletion", "api-server-elb-name", apiELB.Name)
conditions.MarkFalse(s.scope.InfraCluster(), infrav1.LoadBalancerReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "")
return nil
}

Expand Down
38 changes: 36 additions & 2 deletions pkg/cloud/services/elb/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
"sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
)

func TestELBName(t *testing.T) {
Expand Down Expand Up @@ -600,8 +601,9 @@ func TestDeleteAPIServerELB(t *testing.T) {
clusterName := "bar" //nolint:goconst // does not need to be a package-level const
elbName := "bar-apiserver"
tests := []struct {
name string
elbAPIMocks func(m *mocks.MockELBAPIMockRecorder)
name string
elbAPIMocks func(m *mocks.MockELBAPIMockRecorder)
verifyAWSCluster func(*infrav1.AWSCluster)
}{
{
name: "if control plane ELB is not found, do nothing",
Expand All @@ -610,6 +612,16 @@ func TestDeleteAPIServerELB(t *testing.T) {
LoadBalancerNames: aws.StringSlice([]string{elbName}),
})).Return(nil, awserr.New(elb.ErrCodeAccessPointNotFoundException, "", nil))
},
verifyAWSCluster: func(awsCluster *infrav1.AWSCluster) {
loadBalancerConditionReady := conditions.IsTrue(awsCluster, infrav1.LoadBalancerReadyCondition)
if loadBalancerConditionReady {
t.Fatalf("Expected LoadBalancerReady condition to be False, but was True")
}
loadBalancerConditionReason := conditions.GetReason(awsCluster, infrav1.LoadBalancerReadyCondition)
if loadBalancerConditionReason != clusterv1.DeletedReason {
t.Fatalf("Expected LoadBalancerReady condition reason to be Deleted, but was %s", loadBalancerConditionReason)
}
},
},
{
name: "if control plane ELB is found, and it is not managed, do nothing",
Expand Down Expand Up @@ -649,6 +661,16 @@ func TestDeleteAPIServerELB(t *testing.T) {
nil,
)
},
verifyAWSCluster: func(awsCluster *infrav1.AWSCluster) {
loadBalancerConditionReady := conditions.IsTrue(awsCluster, infrav1.LoadBalancerReadyCondition)
if loadBalancerConditionReady {
t.Fatalf("Expected LoadBalancerReady condition to be False, but was True")
}
loadBalancerConditionReason := conditions.GetReason(awsCluster, infrav1.LoadBalancerReadyCondition)
if loadBalancerConditionReason != clusterv1.DeletedReason {
t.Fatalf("Expected LoadBalancerReady condition reason to be Deleted, but was %s", loadBalancerConditionReason)
}
},
},
{
name: "if control plane ELB is found, and it is managed, delete the ELB",
Expand Down Expand Up @@ -701,6 +723,16 @@ func TestDeleteAPIServerELB(t *testing.T) {
nil,
)
},
verifyAWSCluster: func(awsCluster *infrav1.AWSCluster) {
loadBalancerConditionReady := conditions.IsTrue(awsCluster, infrav1.LoadBalancerReadyCondition)
if loadBalancerConditionReady {
t.Fatalf("Expected LoadBalancerReady condition to be False, but was True")
}
loadBalancerConditionReason := conditions.GetReason(awsCluster, infrav1.LoadBalancerReadyCondition)
if loadBalancerConditionReason != clusterv1.DeletedReason {
t.Fatalf("Expected LoadBalancerReady condition reason to be Deleted, but was %s", loadBalancerConditionReason)
}
},
},
}

Expand Down Expand Up @@ -755,6 +787,8 @@ func TestDeleteAPIServerELB(t *testing.T) {
if err != nil {
t.Fatal(err)
}

tc.verifyAWSCluster(awsCluster)
})
}
}
Expand Down