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 @@ -769,7 +769,11 @@ func (s *ClusterScope) ControlPlaneOutboundLB() *infrav1.LoadBalancerSpec {
769769
770770// APIServerLBName returns the API Server LB name.
771771func (s * ClusterScope ) APIServerLBName () string {
772- return s .APIServerLB ().Name
772+ apiServerLB := s .APIServerLB ()
773+ if apiServerLB != nil {
774+ return apiServerLB .Name
775+ }
776+ return ""
773777}
774778
775779// IsAPIServerPrivate returns true if the API Server LB is of type Internal.
Original file line number Diff line number Diff line change @@ -3973,3 +3973,46 @@ func TestGroupSpecs(t *testing.T) {
39733973 })
39743974 }
39753975}
3976+
3977+ func TestAPIServerLBName (t * testing.T ) {
3978+ tests := []struct {
3979+ name string
3980+ cluster * ClusterScope
3981+ expected string
3982+ }{
3983+ {
3984+ name : "APIServerLB is not nil" ,
3985+ cluster : & ClusterScope {
3986+ AzureCluster : & infrav1.AzureCluster {
3987+ Spec : infrav1.AzureClusterSpec {
3988+ NetworkSpec : infrav1.NetworkSpec {
3989+ APIServerLB : & infrav1.LoadBalancerSpec {
3990+ Name : "test-lb" ,
3991+ },
3992+ },
3993+ },
3994+ },
3995+ },
3996+ expected : "test-lb" ,
3997+ },
3998+ {
3999+ name : "APIServerLB is nil" ,
4000+ cluster : & ClusterScope {
4001+ AzureCluster : & infrav1.AzureCluster {
4002+ Spec : infrav1.AzureClusterSpec {
4003+ NetworkSpec : infrav1.NetworkSpec {},
4004+ },
4005+ },
4006+ },
4007+ expected : "" ,
4008+ },
4009+ }
4010+
4011+ for _ , tt := range tests {
4012+ t .Run (tt .name , func (t * testing.T ) {
4013+ g := NewWithT (t )
4014+ result := tt .cluster .APIServerLBName ()
4015+ g .Expect (result ).To (Equal (tt .expected ))
4016+ })
4017+ }
4018+ }
You can’t perform that action at this time.
0 commit comments