scaleway_sd_config: be more cautious with pointers

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2021-04-19 20:40:14 +02:00
parent a9a5f04ff9
commit 73237c04bf

View File

@ -134,23 +134,32 @@ func (d *instanceDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group,
var targets []model.LabelSet var targets []model.LabelSet
for _, server := range servers.Servers { for _, server := range servers.Servers {
labels := model.LabelSet{ labels := model.LabelSet{
instanceBootTypeLabel: model.LabelValue(server.BootType), instanceBootTypeLabel: model.LabelValue(server.BootType),
instanceHostnameLabel: model.LabelValue(server.Hostname), instanceHostnameLabel: model.LabelValue(server.Hostname),
instanceIDLabel: model.LabelValue(server.ID), instanceIDLabel: model.LabelValue(server.ID),
instanceImageArchLabel: model.LabelValue(server.Image.Arch), instanceNameLabel: model.LabelValue(server.Name),
instanceImageIDLabel: model.LabelValue(server.Image.ID), instanceOrganizationLabel: model.LabelValue(server.Organization),
instanceImageNameLabel: model.LabelValue(server.Image.Name), instanceProjectLabel: model.LabelValue(server.Project),
instanceLocationClusterID: model.LabelValue(server.Location.ClusterID), instanceStateLabel: model.LabelValue(server.State),
instanceLocationHypervisorID: model.LabelValue(server.Location.HypervisorID), instanceTypeLabel: model.LabelValue(server.CommercialType),
instanceLocationNodeID: model.LabelValue(server.Location.NodeID), instanceZoneLabel: model.LabelValue(server.Zone.String()),
instanceNameLabel: model.LabelValue(server.Name), }
instanceOrganizationLabel: model.LabelValue(server.Organization),
instanceProjectLabel: model.LabelValue(server.Project), if server.Image != nil {
instanceSecurityGroupIDLabel: model.LabelValue(server.SecurityGroup.ID), labels[instanceImageArchLabel] = model.LabelValue(server.Image.Arch)
instanceSecurityGroupNameLabel: model.LabelValue(server.SecurityGroup.Name), labels[instanceImageIDLabel] = model.LabelValue(server.Image.ID)
instanceStateLabel: model.LabelValue(server.State), labels[instanceImageNameLabel] = model.LabelValue(server.Image.Name)
instanceTypeLabel: model.LabelValue(server.CommercialType), }
instanceZoneLabel: model.LabelValue(server.Zone.String()),
if server.Location != nil {
labels[instanceLocationClusterID] = model.LabelValue(server.Location.ClusterID)
labels[instanceLocationHypervisorID] = model.LabelValue(server.Location.HypervisorID)
labels[instanceLocationNodeID] = model.LabelValue(server.Location.NodeID)
}
if server.SecurityGroup != nil {
labels[instanceSecurityGroupIDLabel] = model.LabelValue(server.SecurityGroup.ID)
labels[instanceSecurityGroupNameLabel] = model.LabelValue(server.SecurityGroup.Name)
} }
if region, err := server.Zone.Region(); err == nil { if region, err := server.Zone.Region(); err == nil {