From 73237c04bf278ef7f838fa1abd83b545f20e57e3 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Mon, 19 Apr 2021 20:40:14 +0200 Subject: [PATCH] scaleway_sd_config: be more cautious with pointers Signed-off-by: Julien Pivotto --- discovery/scaleway/instance.go | 43 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/discovery/scaleway/instance.go b/discovery/scaleway/instance.go index 836044b61..2666fc65c 100644 --- a/discovery/scaleway/instance.go +++ b/discovery/scaleway/instance.go @@ -134,23 +134,32 @@ func (d *instanceDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, var targets []model.LabelSet for _, server := range servers.Servers { labels := model.LabelSet{ - instanceBootTypeLabel: model.LabelValue(server.BootType), - instanceHostnameLabel: model.LabelValue(server.Hostname), - instanceIDLabel: model.LabelValue(server.ID), - instanceImageArchLabel: model.LabelValue(server.Image.Arch), - instanceImageIDLabel: model.LabelValue(server.Image.ID), - instanceImageNameLabel: model.LabelValue(server.Image.Name), - instanceLocationClusterID: model.LabelValue(server.Location.ClusterID), - instanceLocationHypervisorID: model.LabelValue(server.Location.HypervisorID), - instanceLocationNodeID: model.LabelValue(server.Location.NodeID), - instanceNameLabel: model.LabelValue(server.Name), - instanceOrganizationLabel: model.LabelValue(server.Organization), - instanceProjectLabel: model.LabelValue(server.Project), - instanceSecurityGroupIDLabel: model.LabelValue(server.SecurityGroup.ID), - instanceSecurityGroupNameLabel: model.LabelValue(server.SecurityGroup.Name), - instanceStateLabel: model.LabelValue(server.State), - instanceTypeLabel: model.LabelValue(server.CommercialType), - instanceZoneLabel: model.LabelValue(server.Zone.String()), + instanceBootTypeLabel: model.LabelValue(server.BootType), + instanceHostnameLabel: model.LabelValue(server.Hostname), + instanceIDLabel: model.LabelValue(server.ID), + instanceNameLabel: model.LabelValue(server.Name), + instanceOrganizationLabel: model.LabelValue(server.Organization), + instanceProjectLabel: model.LabelValue(server.Project), + instanceStateLabel: model.LabelValue(server.State), + instanceTypeLabel: model.LabelValue(server.CommercialType), + instanceZoneLabel: model.LabelValue(server.Zone.String()), + } + + if server.Image != nil { + labels[instanceImageArchLabel] = model.LabelValue(server.Image.Arch) + labels[instanceImageIDLabel] = model.LabelValue(server.Image.ID) + labels[instanceImageNameLabel] = model.LabelValue(server.Image.Name) + } + + 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 {