Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support k8s on GCE in resource detector #875

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions detectors/gcp/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func TestCloudPlatformGKE(t *testing.T) {
assert.Equal(t, platform, GKE)
}

func TestCloudPlatformK8sNotGKE(t *testing.T) {
d := NewTestDetector(&FakeMetadataProvider{Err: fmt.Errorf("foo")}, &FakeOSProvider{
Vars: map[string]string{
k8sServiceHostEnv: "foo",
},
})
platform := d.CloudPlatform()
assert.Equal(t, platform, UnknownPlatform)
damemi marked this conversation as resolved.
Show resolved Hide resolved
}

func TestCloudPlatformGCE(t *testing.T) {
d := NewTestDetector(&FakeMetadataProvider{}, &FakeOSProvider{
Vars: map[string]string{},
Expand Down
9 changes: 8 additions & 1 deletion detectors/gcp/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ const (
)

func (d *Detector) onGKE() bool {
// Check if we are on k8s first
_, found := d.os.LookupEnv(k8sServiceHostEnv)
return found
if !found {
return false
}
// If we are on k8s, make sure that we are actually on GKE, and not a
// different managed k8s platform.
_, err := d.GKEClusterName()
return err == nil
}

// GKEHostID returns the instance ID of the instance on which this program is running.
Expand Down
Loading