From 8ed7574e061a1e0dde4fbefb6c04c738ae405019 Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Thu, 31 Oct 2024 08:45:18 -0700 Subject: [PATCH] fix onGKE to use the cluster location, as name may be registered (#907) --- detectors/gcp/detector_test.go | 2 +- detectors/gcp/gke.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/detectors/gcp/detector_test.go b/detectors/gcp/detector_test.go index f034b40e3..7c8b04b15 100644 --- a/detectors/gcp/detector_test.go +++ b/detectors/gcp/detector_test.go @@ -44,7 +44,7 @@ func TestCloudPlatformAppEngineStandard(t *testing.T) { func TestCloudPlatformGKE(t *testing.T) { d := NewTestDetector(newFakeMetadataTransport(t, - "instance/attributes/cluster-name", "cluster-name", + "instance/attributes/cluster-location", "us-central-1a", ), &FakeOSProvider{ Vars: map[string]string{ k8sServiceHostEnv: "foo", diff --git a/detectors/gcp/gke.go b/detectors/gcp/gke.go index a016e1c66..734d44cc0 100644 --- a/detectors/gcp/gke.go +++ b/detectors/gcp/gke.go @@ -39,7 +39,7 @@ func (d *Detector) onGKE() bool { } // If we are on k8s, make sure that we are actually on GKE, and not a // different managed k8s platform. - _, err := d.GKEClusterName() + _, err := d.metadata.InstanceAttributeValueWithContext(context.TODO(), clusterLocationMetadataAttr) return err == nil }