Skip to content

Commit 38bf35d

Browse files
committed
Add InstanceStatus.AvailabilityZone()
This is currently only required by MAPO, where it's used to label the node with its AZ. It doesn't fetch any additional data from OpenStack, just exposes it in Go.
1 parent ac9c503 commit 38bf35d

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

pkg/cloud/services/compute/instance.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -880,19 +880,18 @@ func (s *Service) GetInstanceStatus(resourceID string) (instance *InstanceStatus
880880
if resourceID == "" {
881881
return nil, fmt.Errorf("resourceId should be specified to get detail")
882882
}
883+
883884
mc := metrics.NewMetricPrometheusContext("server", "get")
884-
server, err := servers.Get(s.computeClient, resourceID).Extract()
885+
var server ServerExt
886+
err = servers.Get(s.computeClient, resourceID).ExtractInto(&server)
885887
if mc.ObserveRequestIgnoreNotFound(err) != nil {
886888
if capoerrors.IsNotFound(err) {
887889
return nil, nil
888890
}
889891
return nil, fmt.Errorf("get server %q detail failed: %v", resourceID, err)
890892
}
891-
if server == nil {
892-
return nil, nil
893-
}
894893

895-
return &InstanceStatus{server: server}, nil
894+
return &InstanceStatus{server: &server}, nil
896895
}
897896

898897
func (s *Service) GetInstanceStatusByName(eventObject runtime.Object, name string) (instance *InstanceStatus, err error) {
@@ -913,7 +912,8 @@ func (s *Service) GetInstanceStatusByName(eventObject runtime.Object, name strin
913912
if mc.ObserveRequest(err) != nil {
914913
return nil, fmt.Errorf("get server list: %v", err)
915914
}
916-
serverList, err := servers.ExtractServers(allPages)
915+
var serverList []ServerExt
916+
err = servers.ExtractServersInto(allPages, &serverList)
917917
if err != nil {
918918
return nil, fmt.Errorf("extract server list: %v", err)
919919
}

pkg/cloud/services/compute/instance_types.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ import (
2020
"encoding/json"
2121
"fmt"
2222

23+
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones"
2324
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
2425

2526
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha4"
2627
)
2728

29+
// ServerExt is the base gophercloud Server with extensions used by InstanceStatus.
30+
type ServerExt struct {
31+
servers.Server
32+
availabilityzones.ServerAvailabilityZoneExt
33+
}
34+
2835
// InstanceSpec defines the fields which can be set on a new OpenStack instance.
2936
//
3037
// InstanceSpec does not contain all of the fields of infrav1.Instance, as not
@@ -55,10 +62,10 @@ type InstanceIdentifier struct {
5562

5663
// InstanceStatus represents instance data which has been returned by OpenStack.
5764
type InstanceStatus struct {
58-
server *servers.Server
65+
server *ServerExt
5966
}
6067

61-
func NewInstanceStatusFromServer(server *servers.Server) *InstanceStatus {
68+
func NewInstanceStatusFromServer(server *ServerExt) *InstanceStatus {
6269
return &InstanceStatus{server}
6370
}
6471

@@ -91,6 +98,10 @@ func (is *InstanceStatus) SSHKeyName() string {
9198
return is.server.KeyName
9299
}
93100

101+
func (is *InstanceStatus) AvailabilityZone() string {
102+
return is.server.AvailabilityZone
103+
}
104+
94105
// APIInstance returns an infrav1.Instance object for use by the API.
95106
func (is *InstanceStatus) APIInstance() (*infrav1.Instance, error) {
96107
i := infrav1.Instance{

test/e2e/shared/openstack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ func getOpenStackServers(e2eCtx *E2EContext) (map[string]server, error) {
170170
return nil, fmt.Errorf("error listing server: %v", err)
171171
}
172172

173-
serverList, err := servers.ExtractServers(allPages)
173+
var serverList []compute.ServerExt
174+
err = servers.ExtractServersInto(allPages, &serverList)
174175
if err != nil {
175176
return nil, fmt.Errorf("error extracting server: %v", err)
176177
}

0 commit comments

Comments
 (0)