Skip to content

Commit c0bd2df

Browse files
authored
Merge pull request #3871 from giantswarm/pr-set-lb-conditions
Update LoadBalancerReadyCondition on deletion
2 parents 712fe65 + cd7273f commit c0bd2df

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

controllers/awscluster_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
171171
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
172172
infrav1.PrincipalCredentialRetrievedCondition,
173173
infrav1.PrincipalUsageAllowedCondition,
174+
infrav1.LoadBalancerReadyCondition,
174175
}})
175176
if e != nil {
176177
fmt.Println(e.Error())

pkg/cloud/services/elb/loadbalancer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ func (s *Service) deleteAPIServerELB() error {
484484

485485
apiELB, err := s.describeClassicELB(elbName)
486486
if IsNotFound(err) {
487+
s.scope.Debug("Control plane load balancer not found, skipping deletion")
488+
conditions.MarkFalse(s.scope.InfraCluster(), infrav1.LoadBalancerReadyCondition, clusterv1.DeletedReason, clusterv1.ConditionSeverityInfo, "")
487489
return nil
488490
}
489491
if err != nil {
@@ -492,6 +494,7 @@ func (s *Service) deleteAPIServerELB() error {
492494

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

pkg/cloud/services/elb/loadbalancer_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
4141
"sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
4242
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
43+
"sigs.k8s.io/cluster-api/util/conditions"
4344
)
4445

4546
func TestELBName(t *testing.T) {
@@ -1587,8 +1588,9 @@ func TestDeleteAPIServerELB(t *testing.T) {
15871588
clusterName := "bar" //nolint:goconst // does not need to be a package-level const
15881589
elbName := "bar-apiserver"
15891590
tests := []struct {
1590-
name string
1591-
elbAPIMocks func(m *mocks.MockELBAPIMockRecorder)
1591+
name string
1592+
elbAPIMocks func(m *mocks.MockELBAPIMockRecorder)
1593+
verifyAWSCluster func(*infrav1.AWSCluster)
15921594
}{
15931595
{
15941596
name: "if control plane ELB is not found, do nothing",
@@ -1597,6 +1599,16 @@ func TestDeleteAPIServerELB(t *testing.T) {
15971599
LoadBalancerNames: aws.StringSlice([]string{elbName}),
15981600
})).Return(nil, awserr.New(elb.ErrCodeAccessPointNotFoundException, "", nil))
15991601
},
1602+
verifyAWSCluster: func(awsCluster *infrav1.AWSCluster) {
1603+
loadBalancerConditionReady := conditions.IsTrue(awsCluster, infrav1.LoadBalancerReadyCondition)
1604+
if loadBalancerConditionReady {
1605+
t.Fatalf("Expected LoadBalancerReady condition to be False, but was True")
1606+
}
1607+
loadBalancerConditionReason := conditions.GetReason(awsCluster, infrav1.LoadBalancerReadyCondition)
1608+
if loadBalancerConditionReason != clusterv1.DeletedReason {
1609+
t.Fatalf("Expected LoadBalancerReady condition reason to be Deleted, but was %s", loadBalancerConditionReason)
1610+
}
1611+
},
16001612
},
16011613
{
16021614
name: "if control plane ELB is found, and it is not managed, do nothing",
@@ -1636,6 +1648,16 @@ func TestDeleteAPIServerELB(t *testing.T) {
16361648
nil,
16371649
)
16381650
},
1651+
verifyAWSCluster: func(awsCluster *infrav1.AWSCluster) {
1652+
loadBalancerConditionReady := conditions.IsTrue(awsCluster, infrav1.LoadBalancerReadyCondition)
1653+
if loadBalancerConditionReady {
1654+
t.Fatalf("Expected LoadBalancerReady condition to be False, but was True")
1655+
}
1656+
loadBalancerConditionReason := conditions.GetReason(awsCluster, infrav1.LoadBalancerReadyCondition)
1657+
if loadBalancerConditionReason != clusterv1.DeletedReason {
1658+
t.Fatalf("Expected LoadBalancerReady condition reason to be Deleted, but was %s", loadBalancerConditionReason)
1659+
}
1660+
},
16391661
},
16401662
{
16411663
name: "if control plane ELB is found, and it is managed, delete the ELB",
@@ -1688,6 +1710,16 @@ func TestDeleteAPIServerELB(t *testing.T) {
16881710
nil,
16891711
)
16901712
},
1713+
verifyAWSCluster: func(awsCluster *infrav1.AWSCluster) {
1714+
loadBalancerConditionReady := conditions.IsTrue(awsCluster, infrav1.LoadBalancerReadyCondition)
1715+
if loadBalancerConditionReady {
1716+
t.Fatalf("Expected LoadBalancerReady condition to be False, but was True")
1717+
}
1718+
loadBalancerConditionReason := conditions.GetReason(awsCluster, infrav1.LoadBalancerReadyCondition)
1719+
if loadBalancerConditionReason != clusterv1.DeletedReason {
1720+
t.Fatalf("Expected LoadBalancerReady condition reason to be Deleted, but was %s", loadBalancerConditionReason)
1721+
}
1722+
},
16911723
},
16921724
}
16931725

@@ -1742,6 +1774,8 @@ func TestDeleteAPIServerELB(t *testing.T) {
17421774
if err != nil {
17431775
t.Fatal(err)
17441776
}
1777+
1778+
tc.verifyAWSCluster(awsCluster)
17451779
})
17461780
}
17471781
}

0 commit comments

Comments
 (0)