From 12f7e3aa3b0b9ed72b6d92c0c76517cacdbcd953 Mon Sep 17 00:00:00 2001 From: Robert Glonek Date: Fri, 30 Aug 2024 13:19:49 -0700 Subject: [PATCH] gcp do not require zone for expiry setting --- CHANGELOG/7.6.0.md | 1 + src/backendGcp.go | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG/7.6.0.md b/CHANGELOG/7.6.0.md index b7e4b2f4..653a3872 100644 --- a/CHANGELOG/7.6.0.md +++ b/CHANGELOG/7.6.0.md @@ -58,6 +58,7 @@ _Release Date: Month Day, Year_ * GCP: add option to specify minimum CPU platform during cluster and client creation. * GCP: expiry system updated to use `go122` runtime. * GCP: support using a single static key for all clusters and clients (must be located in `${AEROLAB_HOME}/sshkey(.pub)`; if it exists, will automatically be used). +* GCP: Do not require zone for instances when setting labels. * Inventory List: expose gcp/aws/docker tags/labels and metadata in json output. * Partitioner: when configuring index on device, parse partition tree sprig configs and fix if required. * Upgrade: added `aerolab upgrade --bugfix` - will upgrade to latest fix version, not bleeding edge version. diff --git a/src/backendGcp.go b/src/backendGcp.go index 83c39caf..e1a86e40 100644 --- a/src/backendGcp.go +++ b/src/backendGcp.go @@ -127,6 +127,7 @@ type gcpInstancePricing struct { type gcpClusterExpiryInstances struct { labelFingerprint string labels map[string]string + zone string } func (d *backendGcp) GetAZName(subnetId string) (string, error) { @@ -440,7 +441,7 @@ func (d *backendGcp) SetLabel(clusterName string, key string, value string, gcpZ } for _, jj := range j.Clusters { if jj.ClusterName == clusterName { - instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpMetadataFingerprint, jj.GcpMeta} + instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpMetadataFingerprint, jj.GcpMeta, jj.Zone} } } } else { @@ -451,7 +452,7 @@ func (d *backendGcp) SetLabel(clusterName string, key string, value string, gcpZ } for _, jj := range j.Clients { if jj.ClientName == clusterName { - instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpMetadataFingerprint, jj.GcpMeta} + instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpMetadataFingerprint, jj.GcpMeta, jj.Zone} } } } @@ -473,7 +474,7 @@ func (d *backendGcp) SetLabel(clusterName string, key string, value string, gcpZ _, err = instancesClient.SetMetadata(ctx, &computepb.SetMetadataInstanceRequest{ Instance: iName, Project: a.opts.Config.Backend.Project, - Zone: gcpZone, + Zone: iMeta.zone, MetadataResource: &computepb.Metadata{ Fingerprint: proto.String(iMeta.labelFingerprint), Items: items, @@ -497,7 +498,7 @@ func (d *backendGcp) ClusterExpiry(zone string, clusterName string, expiry time. for _, jj := range j.Clusters { nodeNo, _ := strconv.Atoi(jj.NodeNo) if jj.ClusterName == clusterName && (len(nodes) == 0 || inslice.HasInt(nodes, nodeNo)) { - instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpLabelFingerprint, jj.GcpLabels} + instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpLabelFingerprint, jj.GcpLabels, jj.Zone} } } } else { @@ -509,7 +510,7 @@ func (d *backendGcp) ClusterExpiry(zone string, clusterName string, expiry time. for _, jj := range j.Clients { nodeNo, _ := strconv.Atoi(jj.NodeNo) if jj.ClientName == clusterName && (len(nodes) == 0 || inslice.HasInt(nodes, nodeNo)) { - instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpLabelFingerprint, jj.GcpLabels} + instances[jj.InstanceId] = gcpClusterExpiryInstances{jj.GcpLabelFingerprint, jj.GcpLabels, jj.Zone} } } } @@ -532,7 +533,7 @@ func (d *backendGcp) ClusterExpiry(zone string, clusterName string, expiry time. newLabels["aerolab4expires"] = newExpiry _, err = instancesClient.SetLabels(ctx, &computepb.SetLabelsInstanceRequest{ Project: a.opts.Config.Backend.Project, - Zone: zone, + Zone: labelData.zone, Instance: instanceName, InstancesSetLabelsRequestResource: &computepb.InstancesSetLabelsRequest{ LabelFingerprint: proto.String(labelData.labelFingerprint),