File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -700,7 +700,11 @@ func (s *ClusterScope) ControlPlaneOutboundLB() *infrav1.LoadBalancerSpec {
700700
701701// APIServerLBName returns the API Server LB name.
702702func (s * ClusterScope ) APIServerLBName () string {
703- return s .APIServerLB ().Name
703+ apiServerLB := s .APIServerLB ()
704+ if apiServerLB != nil {
705+ return apiServerLB .Name
706+ }
707+ return ""
704708}
705709
706710// IsAPIServerPrivate returns true if the API Server LB is of type Internal.
Original file line number Diff line number Diff line change @@ -4256,3 +4256,46 @@ func TestGroupSpecs(t *testing.T) {
42564256 })
42574257 }
42584258}
4259+
4260+ func TestAPIServerLBName (t * testing.T ) {
4261+ tests := []struct {
4262+ name string
4263+ cluster * ClusterScope
4264+ expected string
4265+ }{
4266+ {
4267+ name : "APIServerLB is not nil" ,
4268+ cluster : & ClusterScope {
4269+ AzureCluster : & infrav1.AzureCluster {
4270+ Spec : infrav1.AzureClusterSpec {
4271+ NetworkSpec : infrav1.NetworkSpec {
4272+ APIServerLB : infrav1.LoadBalancerSpec {
4273+ Name : "test-lb" ,
4274+ },
4275+ },
4276+ },
4277+ },
4278+ },
4279+ expected : "test-lb" ,
4280+ },
4281+ {
4282+ name : "APIServerLB is nil" ,
4283+ cluster : & ClusterScope {
4284+ AzureCluster : & infrav1.AzureCluster {
4285+ Spec : infrav1.AzureClusterSpec {
4286+ NetworkSpec : infrav1.NetworkSpec {},
4287+ },
4288+ },
4289+ },
4290+ expected : "" ,
4291+ },
4292+ }
4293+
4294+ for _ , tt := range tests {
4295+ t .Run (tt .name , func (t * testing.T ) {
4296+ g := NewWithT (t )
4297+ result := tt .cluster .APIServerLBName ()
4298+ g .Expect (result ).To (Equal (tt .expected ))
4299+ })
4300+ }
4301+ }
You can’t perform that action at this time.
0 commit comments