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

[v13] Discovery service panics on GKE clusters without labels #30647

Merged
merged 1 commit into from
Aug 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/services/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,10 @@ func getOrSetDefaultGCPDescription(cluster gcp.GKECluster) string {

// labelsFromGCPKubeCluster creates kube cluster labels.
func labelsFromGCPKubeCluster(cluster gcp.GKECluster) map[string]string {
labels := maps.Clone(cluster.Labels)
labels := make(map[string]string)
maps.Copy(labels, cluster.Labels)
labels[types.OriginLabel] = types.OriginCloud

labels[types.CloudLabel] = types.CloudGCP
labels[types.DiscoveryLabelGCPLocation] = cluster.Location

Expand Down
35 changes: 35 additions & 0 deletions lib/services/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,41 @@ func TestNewKubeClusterFromGCPGKE(t *testing.T) {
require.False(t, actual.IsAWS())
}

func TestNewKubeClusterFromGCPGKEWithoutLabels(t *testing.T) {
expected, err := types.NewKubernetesClusterV3(types.Metadata{
Name: "cluster1",
Description: "desc1",
Labels: map[string]string{
types.DiscoveryLabelGCPLocation: "central-1",
types.DiscoveryLabelGCPProjectID: "p1",
types.CloudLabel: types.CloudGCP,
types.OriginLabel: types.OriginCloud,
},
}, types.KubernetesClusterSpecV3{
GCP: types.KubeGCP{
Name: "cluster1",
ProjectID: "p1",
Location: "central-1",
},
})
require.NoError(t, err)

cluster := gcp.GKECluster{
Name: "cluster1",
Status: containerpb.Cluster_RUNNING,
Labels: nil,
ProjectID: "p1",
Location: "central-1",
Description: "desc1",
}
actual, err := NewKubeClusterFromGCPGKE(cluster)
require.NoError(t, err)
require.Empty(t, cmp.Diff(expected, actual))
require.True(t, actual.IsGCP())
require.False(t, actual.IsAzure())
require.False(t, actual.IsAWS())
}

var kubeServerYAML = `---
kind: kube_server
version: v3
Expand Down