Skip to content

Commit

Permalink
fix awsoidc tests (gravitational#29770)
Browse files Browse the repository at this point in the history
* use cmp.Diff for readable test failures
* expect the teleport.dev/cloud label in tests
* remove teleport.dev/origin in aws label conversion func
  • Loading branch information
GavinFrazar authored Aug 4, 2023
1 parent 0bb12aa commit c08c8ef
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 68 deletions.
4 changes: 3 additions & 1 deletion lib/auth/auth_with_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ func TestKubernetesClusterCRUD_DiscoveryService(t *testing.T) {
Status: aws.String(eks.ClusterStatusActive),
})
require.NoError(t, err)
eksCluster.SetOrigin(types.OriginCloud)

// Discovery service must not have access to non-cloud cluster (cluster
// without "cloud" origin label).
Expand All @@ -1939,6 +1940,7 @@ func TestKubernetesClusterCRUD_DiscoveryService(t *testing.T) {
Status: aws.String(eks.ClusterStatusActive),
})
require.NoError(t, err)
clusterWithDynamicLabels.SetOrigin(types.OriginCloud)
clusterWithDynamicLabels.SetDynamicLabels(map[string]types.CommandLabel{
"hostname": &types.CommandLabelV2{
Period: types.Duration(time.Hour),
Expand All @@ -1954,7 +1956,7 @@ func TestKubernetesClusterCRUD_DiscoveryService(t *testing.T) {
t.Run("Read", func(t *testing.T) {
clusters, err := discoveryClt.GetKubernetesClusters(ctx)
require.NoError(t, err)
require.Equal(t, clusters, []types.KubeCluster{eksCluster})
require.Empty(t, cmp.Diff([]types.KubeCluster{eksCluster}, clusters))
})
t.Run("Update", func(t *testing.T) {
require.NoError(t, discoveryClt.UpdateKubernetesCluster(ctx, eksCluster))
Expand Down
45 changes: 21 additions & 24 deletions lib/integrations/awsoidc/listdatabases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ func TestListDatabases(t *testing.T) {
Name: "my-db",
Description: "RDS instance in ",
Labels: map[string]string{
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
"teleport.dev/origin": "cloud",
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
},
},
types.DatabaseSpecV3{
Expand Down Expand Up @@ -253,14 +252,13 @@ func TestListDatabases(t *testing.T) {
Name: "my-db",
Description: "RDS instance in ",
Labels: map[string]string{
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
"teleport.dev/origin": "cloud",
"account-id": "123456789012",
"endpoint-type": "instance",
"engine": "postgres",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
},
},
types.DatabaseSpecV3{
Expand Down Expand Up @@ -305,14 +303,13 @@ func TestListDatabases(t *testing.T) {
Name: "my-dbc",
Description: "Aurora cluster in ",
Labels: map[string]string{
"account-id": "123456789012",
"endpoint-type": "primary",
"engine": "aurora-postgresql",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
"teleport.dev/origin": "cloud",
"account-id": "123456789012",
"endpoint-type": "primary",
"engine": "aurora-postgresql",
"engine-version": "",
"region": "",
"status": "available",
"teleport.dev/cloud": "AWS",
},
},
types.DatabaseSpecV3{
Expand Down
2 changes: 0 additions & 2 deletions lib/services/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,6 @@ func labelsFromAWSMetadata(meta *types.AWS) map[string]string {
labels[types.DiscoveryLabelAccountID] = meta.AccountID
labels[types.DiscoveryLabelRegion] = meta.Region
}
labels[types.OriginLabel] = types.OriginCloud
labels[types.CloudLabel] = types.CloudAWS
return labels
}
Expand All @@ -1561,7 +1560,6 @@ func labelsFromMetaAndEndpointType(meta *types.AWS, endpointType string, extraLa
// azureTagsToLabels converts Azure tags to a labels map.
func azureTagsToLabels(tags map[string]string) map[string]string {
labels := make(map[string]string)
labels[types.OriginLabel] = types.OriginCloud
labels[types.CloudLabel] = types.CloudAzure
return addLabels(labels, tags)
}
Expand Down
39 changes: 4 additions & 35 deletions lib/services/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ func TestDatabaseFromAzureDBServer(t *testing.T) {
types.DiscoveryLabelEngine: "Microsoft.DBforMySQL/servers",
types.DiscoveryLabelEngineVersion: "5.7",
types.DiscoveryLabelAzureResourceGroup: "defaultRG",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAzure,
types.DiscoveryLabelAzureSubscriptionID: "sub1",
"foo": "bar",
Expand Down Expand Up @@ -596,7 +595,6 @@ func TestDatabaseFromAzureRedis(t *testing.T) {
types.DiscoveryLabelEngine: "Microsoft.Cache/Redis",
types.DiscoveryLabelEngineVersion: "6.0",
types.DiscoveryLabelAzureResourceGroup: group,
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAzure,
types.DiscoveryLabelAzureSubscriptionID: subscription,
"foo": "bar",
Expand Down Expand Up @@ -655,7 +653,6 @@ func TestDatabaseFromAzureRedisEnterprise(t *testing.T) {
types.DiscoveryLabelEngine: "Microsoft.Cache/redisEnterprise",
types.DiscoveryLabelEngineVersion: "6.0",
types.DiscoveryLabelAzureResourceGroup: group,
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAzure,
types.DiscoveryLabelAzureSubscriptionID: subscription,
types.DiscoveryLabelEndpointType: "OSSCluster",
Expand Down Expand Up @@ -703,7 +700,6 @@ func TestDatabaseFromRDSInstance(t *testing.T) {
Description: "RDS instance in us-west-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-west-1",
types.DiscoveryLabelEngine: RDSEnginePostgres,
Expand Down Expand Up @@ -764,7 +760,6 @@ func TestDatabaseFromRDSV2Instance(t *testing.T) {
Description: "RDS instance in us-west-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-west-1",
types.DiscoveryLabelEngine: RDSEnginePostgres,
Expand Down Expand Up @@ -842,7 +837,6 @@ func TestDatabaseFromRDSInstanceNameOverride(t *testing.T) {
Description: "RDS instance in us-west-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-west-1",
types.DiscoveryLabelEngine: RDSEnginePostgres,
Expand Down Expand Up @@ -911,7 +905,6 @@ func TestDatabaseFromRDSCluster(t *testing.T) {
Description: "Aurora cluster in us-east-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEngine: RDSEngineAuroraMySQL,
Expand All @@ -936,7 +929,6 @@ func TestDatabaseFromRDSCluster(t *testing.T) {
Description: "Aurora cluster in us-east-1 (reader endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEngine: RDSEngineAuroraMySQL,
Expand All @@ -958,7 +950,6 @@ func TestDatabaseFromRDSCluster(t *testing.T) {
t.Run("custom endpoints", func(t *testing.T) {
expectedLabels := map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEngine: RDSEngineAuroraMySQL,
Expand Down Expand Up @@ -1051,7 +1042,6 @@ func TestDatabaseFromRDSV2Cluster(t *testing.T) {
Description: "Aurora cluster in us-east-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEngine: RDSEngineAuroraMySQL,
Expand Down Expand Up @@ -1129,7 +1119,6 @@ func TestDatabaseFromRDSClusterNameOverride(t *testing.T) {
Description: "Aurora cluster in us-east-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEngine: RDSEngineAuroraMySQL,
Expand All @@ -1155,7 +1144,6 @@ func TestDatabaseFromRDSClusterNameOverride(t *testing.T) {
Description: "Aurora cluster in us-east-1 (reader endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEngine: RDSEngineAuroraMySQL,
Expand All @@ -1178,7 +1166,6 @@ func TestDatabaseFromRDSClusterNameOverride(t *testing.T) {
t.Run("custom endpoints", func(t *testing.T) {
expectedLabels := map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEngine: RDSEngineAuroraMySQL,
Expand Down Expand Up @@ -1263,7 +1250,6 @@ func TestDatabaseFromRDSProxy(t *testing.T) {
Labels: map[string]string{
"key": "val",
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "ca-central-1",
types.DiscoveryLabelEngine: "MYSQL",
Expand Down Expand Up @@ -1295,7 +1281,6 @@ func TestDatabaseFromRDSProxy(t *testing.T) {
Labels: map[string]string{
"key": "val",
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "ca-central-1",
types.DiscoveryLabelEngine: "MYSQL",
Expand Down Expand Up @@ -1458,11 +1443,10 @@ func TestAzureTagsToLabels(t *testing.T) {
}
labels := azureTagsToLabels(azureTags)
wantLabels := map[string]string{
"Name": "test",
"Env": "dev",
"foo:bar": "some-id",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAzure,
"Name": "test",
"Env": "dev",
"foo:bar": "some-id",
types.CloudLabel: types.CloudAzure,
}
require.Equal(t, wantLabels, labels)
}
Expand Down Expand Up @@ -1493,7 +1477,6 @@ func TestDatabaseFromRedshiftCluster(t *testing.T) {
Description: "Redshift cluster in us-east-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
"key": "val",
Expand Down Expand Up @@ -1547,7 +1530,6 @@ func TestDatabaseFromRedshiftCluster(t *testing.T) {
Description: "Redshift cluster in us-east-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
overrideLabel: "mycluster-override-2",
Expand Down Expand Up @@ -1627,7 +1609,6 @@ func TestDatabaseFromElastiCacheConfigurationEndpoint(t *testing.T) {
Description: "ElastiCache cluster in us-east-1 (configuration endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "configuration",
Expand Down Expand Up @@ -1703,7 +1684,6 @@ func TestDatabaseFromElastiCacheConfigurationEndpointNameOverride(t *testing.T)
Description: "ElastiCache cluster in us-east-1 (configuration endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "configuration",
Expand Down Expand Up @@ -1762,7 +1742,6 @@ func TestDatabaseFromElastiCacheNodeGroups(t *testing.T) {
Description: "ElastiCache cluster in us-east-1 (primary endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "primary",
Expand All @@ -1789,7 +1768,6 @@ func TestDatabaseFromElastiCacheNodeGroups(t *testing.T) {
Description: "ElastiCache cluster in us-east-1 (reader endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "reader",
Expand Down Expand Up @@ -1850,7 +1828,6 @@ func TestDatabaseFromElastiCacheNodeGroupsNameOverride(t *testing.T) {
Description: "ElastiCache cluster in us-east-1 (primary endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "primary",
Expand Down Expand Up @@ -1878,7 +1855,6 @@ func TestDatabaseFromElastiCacheNodeGroupsNameOverride(t *testing.T) {
Description: "ElastiCache cluster in us-east-1 (reader endpoint)",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "reader",
Expand Down Expand Up @@ -1927,7 +1903,6 @@ func TestDatabaseFromMemoryDBCluster(t *testing.T) {
Description: "MemoryDB cluster in us-east-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "cluster",
Expand Down Expand Up @@ -1962,7 +1937,6 @@ func TestDatabaseFromRedshiftServerlessWorkgroup(t *testing.T) {
Description: "Redshift Serverless workgroup in eu-west-2",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "eu-west-2",
types.DiscoveryLabelEndpointType: "workgroup",
Expand Down Expand Up @@ -1998,7 +1972,6 @@ func TestDatabaseFromRedshiftServerlessVPCEndpoint(t *testing.T) {
Description: "Redshift Serverless endpoint in eu-west-2",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "eu-west-2",
types.DiscoveryLabelEndpointType: "vpc-endpoint",
Expand Down Expand Up @@ -2054,7 +2027,6 @@ func TestDatabaseFromMemoryDBClusterNameOverride(t *testing.T) {
Description: "MemoryDB cluster in us-east-1",
Labels: map[string]string{
types.DiscoveryLabelAccountID: "123456789012",
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAWS,
types.DiscoveryLabelRegion: "us-east-1",
types.DiscoveryLabelEndpointType: "cluster",
Expand Down Expand Up @@ -2448,7 +2420,6 @@ func TestDatabaseFromAzureMySQLFlexServer(t *testing.T) {
types.DiscoveryLabelEngine: provider,
types.DiscoveryLabelEngineVersion: "8.0.21",
types.DiscoveryLabelAzureResourceGroup: group,
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAzure,
types.DiscoveryLabelAzureSubscriptionID: subID,
"foo": "bar",
Expand Down Expand Up @@ -2525,7 +2496,6 @@ func TestDatabaseFromAzurePostgresFlexServer(t *testing.T) {
types.DiscoveryLabelEngine: provider,
types.DiscoveryLabelEngineVersion: "14",
types.DiscoveryLabelAzureResourceGroup: group,
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAzure,
types.DiscoveryLabelAzureSubscriptionID: subID,
"foo": "bar",
Expand Down Expand Up @@ -2623,7 +2593,6 @@ func TestMakeAzureDatabaseLoginUsername(t *testing.T) {
types.DiscoveryLabelEngine: tt.engine,
types.DiscoveryLabelEngineVersion: "1.2.3",
types.DiscoveryLabelAzureResourceGroup: group,
types.OriginLabel: types.OriginCloud,
types.CloudLabel: types.CloudAzure,
types.DiscoveryLabelAzureSubscriptionID: subID,
"foo": "bar",
Expand Down
3 changes: 0 additions & 3 deletions lib/services/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ func NewKubeClusterFromAzureAKS(cluster *azure.AKSCluster) (types.KubeCluster, e
// labelsFromAzureKubeCluster creates kube cluster labels.
func labelsFromAzureKubeCluster(cluster *azure.AKSCluster) map[string]string {
labels := azureTagsToLabels(cluster.Tags)
labels[types.OriginLabel] = types.OriginCloud
labels[types.CloudLabel] = types.CloudAzure
labels[types.DiscoveryLabelRegion] = cluster.Location

Expand Down Expand Up @@ -258,7 +257,6 @@ 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[types.OriginLabel] = types.OriginCloud
labels[types.CloudLabel] = types.CloudGCP
labels[types.DiscoveryLabelGCPLocation] = cluster.Location

Expand Down Expand Up @@ -293,7 +291,6 @@ func NewKubeClusterFromAWSEKS(cluster *eks.Cluster) (types.KubeCluster, error) {
// labelsFromAWSKubeCluster creates kube cluster labels.
func labelsFromAWSKubeCluster(cluster *eks.Cluster, parsedARN arn.ARN) map[string]string {
labels := awsEKSTagsToLabels(cluster.Tags)
labels[types.OriginLabel] = types.OriginCloud
labels[types.CloudLabel] = types.CloudAWS
labels[types.DiscoveryLabelRegion] = parsedARN.Region

Expand Down
Loading

0 comments on commit c08c8ef

Please sign in to comment.